Created
May 19, 2021 15:58
-
-
Save nastacio/19dd9a980c407dbe35e03f8ca18a34ad to your computer and use it in GitHub Desktop.
Force deletion of k8s namespace
This file contains 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
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