0

I am trying to get a helm release name via executing below code in nodejs

and then wanted to delete that release

var sys = require('sys')
var spawn = require('child_process').spawn;

output = spawn('helm',['list', '-q', '--namespace', 'd35nb8']);

release = output.stdout.on('data', (data) => {
                var test = process.stdout.write(data.toString());
                process.stdout.write(data.toString()) 
                spawn('helm',['delete', test]);

});

code here is able to get the helm release name but could not delete the release

code outputs as

oot@5a857d30a4c1:/opt/api# nodejs test2.js
inside moving further
(node:2272) [DEP0025] DeprecationWarning: sys is deprecated. Use util instead.
kilted-markhor
kilted-markhor

how could I achieve this logic here in nodejs

2
  • Have you tried spawn('helm',['delete', data.toString()]);? Commented May 10, 2019 at 12:21
  • That did not helped Commented May 10, 2019 at 14:03

1 Answer 1

1

Usually, spawn is needed for more sophisticated child process management. For the described use case I would suggest using simple exec:

const exec = require('child_process').exec;

exec('helm list -q --namespace d35nb8'], (err, stdout, stderr) => {
    if (err) {
        console.log('helm list failed', err);
    } else {
        const releases = stdout.split('\n');  // or whatever is the separator
        for (const r of releases) {
            console.log('deleting release', r);
            exec('helm delete ' + r, (err2) => {
                if (err2) {
                    console.log('helm delete failed', err2);
                }
            });
        }
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.