Created
January 9, 2020 04:08
-
-
Save jonstacks/876ab7935a43260f677f6d7be4aa8fba to your computer and use it in GitHub Desktop.
Purge a kubernetes namespace but only if it is empty
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
#!/bin/bash | |
set -e | |
NAMESPACE="$1" | |
echo "Checking if we can purge namespace $NAMESPACE" | |
OUTPUT=$(kubectl -n "$NAMESPACE" get all 2>&1) | |
echo "$OUTPUT" | |
case "$OUTPUT" in | |
"No resources found.") | |
kubectl delete namespace "$NAMESPACE" | |
exit 0 | |
;; | |
*) | |
echo "" | |
echo "Can't delete namespace $NAMESPACE as it is not empty" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment