Skip to content

Commit

Permalink
chore: add script to force delete a namespace (#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
lemaitre-aneo authored Dec 27, 2024
2 parents ba71da4 + e1cf789 commit 8f3b1a0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tools/force-delete-namespace.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 8f3b1a0

Please sign in to comment.