Skip to content

Instantly share code, notes, and snippets.

@mrhillsman
Created January 15, 2024 19:52
Show Gist options
  • Save mrhillsman/78158dff217a259fa5f263696084e987 to your computer and use it in GitHub Desktop.
Save mrhillsman/78158dff217a259fa5f263696084e987 to your computer and use it in GitHub Desktop.
Get all namespaces, filter by status Terminating, output the json, replace the finalizers with an empty set, then finally push the updated namespace's json representation back to the cluster.
for ns in `kubectl get namespaces | awk '/Terminating/ NR>1 {print $1}'`; \
do kubectl get namespace ${ns} -o json | tr -d "\n" | \
sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" | \
kubectl replace --raw /api/v1/namespaces/${ns}/finalize -f -; done;
@mrhillsman
Copy link
Author

mrhillsman commented Feb 12, 2024

for ns in `oc get projects|awk '/Terminating/ NR>1 {print $1}'`; do kubectl get namespace ${ns} -o json | tr -d "\n" | sed "s/\"finalizers\": \[[^]]\+\]/\"finalizers\": []/" | kubectl replace --raw /api/v1/namespaces/${ns}/finalize -f -; done;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment