Skip to content

Instantly share code, notes, and snippets.

@nastacio
Created May 19, 2021 15:58
Show Gist options
  • Save nastacio/19dd9a980c407dbe35e03f8ca18a34ad to your computer and use it in GitHub Desktop.
Save nastacio/19dd9a980c407dbe35e03f8ca18a34ad to your computer and use it in GitHub Desktop.
Force deletion of k8s namespace
function delete_namespace() {
local namespace=${1}
kubectl get namespace ${namespace} -o jsonpath={.status.conditions} \
| jq '.[] | select(.type=="NamespaceContentRemaining" and .reason=="SomeResourcesRemain") .message' \
| sed "s| |\\n|g" | grep "\." \
| xargs -Iresource oc get resource -n ${namespace} -o name \
| xargs -I r2 oc patch r2 -n ${namespace} --type=merge --patch '{"metadata":{"finalizers":[]}}'
}
delete_namespace ${1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment