We're building a simple app that scans a user's K8s cluster via <kubectl get all -o json> then compares that data against a json file detailing all K8s API deprecations and replacements from KubePug.
What We Have:
- A ‘test’ user react app spun up into a K8s cluster
- A JS file that (shown below):
- Uses Node’s ‘child_process’ to run the <kubectl get all -o json> in the terminal
- Parse the response JSON and grab the necessary object data from the cluster (apiVersion, kind, name, namespace, etc.)
Desired User Experience:
- Navigate to workdir
- Open our app just like you would vsCode <code .>
- GUI automatically opens that indicates the version/deprecation status of all active APIs in your cluster + other information, links, dependency trees, etc.
Technical Flow:
- User navigates to application workdir
- User executes <kdt .> in their workdir (kdt being our app name)
- Our app starts running
- Our app grabs the users workdir where they executed <kdt .>
- Our app uses the code we already have to execute the <kubectl get all -o json> command inside of the user’s workdir
- Our app performs business logic on the data
- Our app renders data either in a localhost or desktop app GUI
Current Roadblock: It’s apparent that this needs to be either an Electron app or an NPM package that a client runs locally. The NPM package approach seems light-weight and more developer-friendly. The Electron approach seems more feasible given our existing skill set but less developer-friendly.
Any ideas or advice would be greatly appreciated, thank you.
P.S. Our React app is spun up into a K8s cluster running 3 client pods, 3 server pods, 1 worker pod, 1 postgres pod, and 1 redis pod through ingress-nginx.
Our JS file works, we just need to be able to run this in a client's terminal now.
const childProcess = require('child_process');
async function sh(cmd_to_execute) {
return new Promise(function (resolve, reject) {
childProcess.exec(cmd_to_execute, (err, stdout, stderr) => {
if (err) {
reject(err);
} else {
const data = JSON.parse(stdout);
const objects = data.items;
objects.forEach((object) => {
console.log('****************************************')
console.log("Name: ", object.metadata.name);
console.log("Kind: ", object.kind);
console.log("apiVersion: ", object.apiVersion);
})
resolve({ stdout, stderr });
}
});
});
}