Skip to content

Instantly share code, notes, and snippets.

@sampaiodiego
Created May 3, 2018 04:27
Show Gist options
  • Save sampaiodiego/4c8aad8c68f9b036c2d6df20296474c3 to your computer and use it in GitHub Desktop.
Save sampaiodiego/4c8aad8c68f9b036c2d6df20296474c3 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const { exec } = require('child_process');
const file = fs.readFileSync('replicasets4.txt').toString();
// const file = fs.readFileSync('pods.txt').toString();
(async () => {
const lines = file.split('\n');
const total = lines.length;
console.log('total ->', total);
let count = 0;
let queue = [];
// for (let i = 0; i < total; i++) {
while (true) {
if (count++ > total) break;
if (queue.length === 500) {
console.log('wait', count);
await Promise.all(queue);
queue = [];
}
const line = lines[count];
if (!line || (line === '' && line.indexOf('traefik') !== -1)) continue;
const rs = line.replace(/^([a-z0-9-]+).*/g, '$1');
queue.push(new Promise((resolve, reject) => {
// setTimeout(() => { resolve(rs) }, 300);
// resolve(rs);
// console.log('rs ->', rs);
exec(`kubectl delete rs ${rs} -n rocket-cloud \\`, (error, result) => {
if (error) {
console.error(rs, error);
return resolve();
}
console.log('rs ->', rs);
resolve(result);
});
}));
}
await Promise.all(queue);
console.log('finish ', count);
// .map(async line => {
// // const pod = line.replace(/^([a-z0-9-]+).*/g, '$1');
// // const rs = pod.substr(0, pod.lastIndexOf('-'));
// return new Promise((resolve, reject) => {
// console.log('rs ->', rs);
// // exec(`kubectl delete rs ${rs} -n rocket-cloud \\`, (error, result) => {
// // if (error) return reject(error);
// // console.log('rs ->', rs);
// // resolve(result);
// // });
// });
// })
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment