Skip to content

Instantly share code, notes, and snippets.

@gadiener
Created May 26, 2023 11:46
Show Gist options
  • Save gadiener/5458a82c4cf037c1d9fd89ec1534a3d3 to your computer and use it in GitHub Desktop.
Save gadiener/5458a82c4cf037c1d9fd89ec1534a3d3 to your computer and use it in GitHub Desktop.
Delete crds and all resources matching a suffix
#!/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