Created
May 26, 2023 11:46
-
-
Save gadiener/5458a82c4cf037c1d9fd89ec1534a3d3 to your computer and use it in GitHub Desktop.
Delete crds and all resources matching a suffix
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
#!/bin/bash | |
CRD_SUFFIX=${1} | |
if [ -z "${CRD_SUFFIX}" ]; then | |
echo "Missing CRD suffix" | |
exit 1 | |
fi | |
echo "Removing CRDs with suffix ${CRD_SUFFIX}" | |
echo | |
for crd in $(kubectl get crd -o name | grep "${CRD_SUFFIX}"); do | |
resource=$(echo "${crd}" | cut -d'/' -f2) | |
for app in $(kubectl get "${resource}" -o name); do | |
echo | |
echo "-> Removing finalizers from ${app}" | |
kubectl get "${app}" -o json | jq '.metadata.finalizers = null' | kubectl apply -f - | |
echo | |
echo "-> Deleting ${app}" | |
name=$(echo $app | cut -d'/' -f2) | |
kubectl delete "${resource}" "${name}" | |
done | |
echo | |
echo "-> Deleting ${crd}" | |
kubectl delete crd "${resource}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment