Last active
March 19, 2024 23:28
-
-
Save timscottbell/9ddfecdc2240dbf06dac2191b6c79157 to your computer and use it in GitHub Desktop.
Remove resource requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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