Skip to content

Instantly share code, notes, and snippets.

@timscottbell
Last active March 19, 2024 23:28
Show Gist options
  • Save timscottbell/9ddfecdc2240dbf06dac2191b6c79157 to your computer and use it in GitHub Desktop.
Save timscottbell/9ddfecdc2240dbf06dac2191b6c79157 to your computer and use it in GitHub Desktop.
Remove resource requests
import {execSync} from 'child_process';
function main() {
const stdout = execSync(
"kubectl get deployment --all-namespaces --selector=projectCustomer=yes | awk '{print $1,$2}' | tail -n +2",
);
const results = stdout
.toString()
.split(/\n/)
.filter(line => line)
.map(line => {
const [namespace, workloadName] = line.split(/\s/);
return {
namespace,
workloadName,
};
});
for (const result of results) {
const patchObj = {
spec: {
template: {
spec: {
containers: [
{
name: result.workloadName,
resources: {
requests: {
memory: 0,
cpu: 0,
},
},
},
],
},
},
},
};
try {
execSync(
`kubectl patch deployment ${
result.workloadName
} --patch '${JSON.stringify(patchObj)}' --namespace ${result.namespace}`,
);
} catch (error) {
console.warn(error);
}
console.log(result.namespace, result.workloadName);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment