From e1cf7896fd4870f6033c9fffd55416e32134ba45 Mon Sep 17 00:00:00 2001 From: Florian Lemaitre Date: Fri, 27 Dec 2024 09:50:54 +0100 Subject: [PATCH] add script to force delete a namespace --- tools/force-delete-namespace.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 tools/force-delete-namespace.sh diff --git a/tools/force-delete-namespace.sh b/tools/force-delete-namespace.sh new file mode 100755 index 000000000..579d97e55 --- /dev/null +++ b/tools/force-delete-namespace.sh @@ -0,0 +1,32 @@ +#! /bin/sh + +namespace="${1:?Namespace not defined}" + +echo -n "Force deleting a namespace can leave some resources associated to the namespace alive.\nAre you sure you want to delete the namespace \`$namespace\`? [y/N] " >&2 + +read -r answer + +case "$answer" in + y|Y|yes|Yes) + echo "Deleting namespace \`$namespace\`" + ;; + n|N|no|No|"") + echo Abort >&2 + exit 1 + ;; + *) + echo "Unrecognized answer \`$answer\`: it should be either yes or no.\nAbort" >&2 + exit 2 + ;; +esac + +kubectl delete namespaces "$namespace" --force --grace-period=0 --timeout=10s || { + kubectl proxy --port=1337 & pid=$! + sleep 1 + + curl -fsS "http://localhost:1337/api/v1/namespaces/$namespace" | + jq '.spec.finalizers = []' | + curl -fsS -XPUT -H 'Content-Type: application/json' "http://localhost:1337/api/v1/namespaces/$namespace/finalize" -d @- + + kill $pid +}