Tweaked kube-force-delete

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2022-04-06 05:54:27 +01:00
parent c5233d41e7
commit b25a5c4c8d
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78

View File

@ -54,7 +54,7 @@ fi
function deleteResource() {
echo "Deleting ${1}"
kubectl patch -p '{"metadata":{"finalizers":null}}' --type=merge -n ${NAMESPACE} ${1} 1>/dev/null
kubectl patch -p '{"metadata":{"finalizers":null}}' --type=merge -n ${NAMESPACE} ${1} 1>/dev/null|| printf ""
kubectl delete -n ${NAMESPACE} ${1} 2>/dev/null || printf ""
}
@ -69,7 +69,7 @@ else
printf "Are you sure you want to delete all matching '${SELECTOR}'? (y/n): "
SELECTOR="-l ${SELECTOR}"
NAMES="$(kubectl api-resources --namespaced --verbs list -o name 2>/dev/null | tr '\n' ,)"
RESOURCES=$(kubectl get "${NAMES::${#NAMES}-1}" --ignore-not-found ${SELECTOR} -n ${NAMESPACE} -o go-template='{{range.items}}{{.kind}}.{{.apiVersion}}/{{.metadata.name}}{{"\n"}}{{end}}' | tr '[:upper:]' '[:lower:]' | sed -r "s|/(v.+)/|/|g" 2>/dev/null)
RESOURCES=$(kubectl get "${NAMES::${#NAMES}-1}" --ignore-not-found ${SELECTOR} -n ${NAMESPACE} -o go-template='{{range.items}}{{.kind}}.{{.apiVersion}}/{{.metadata.name}}{{"\n"}}{{end}}' 2>/dev/null | tr '[:upper:]' '[:lower:]' | sed -r "s|/(v.+)/|/|g")
fi
read CONFIRM