Skip to content

Commit 8f3b1a0

Browse files
chore: add script to force delete a namespace (#1345)
2 parents ba71da4 + e1cf789 commit 8f3b1a0

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tools/force-delete-namespace.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#! /bin/sh
2+
3+
namespace="${1:?Namespace not defined}"
4+
5+
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
6+
7+
read -r answer
8+
9+
case "$answer" in
10+
y|Y|yes|Yes)
11+
echo "Deleting namespace \`$namespace\`"
12+
;;
13+
n|N|no|No|"")
14+
echo Abort >&2
15+
exit 1
16+
;;
17+
*)
18+
echo "Unrecognized answer \`$answer\`: it should be either yes or no.\nAbort" >&2
19+
exit 2
20+
;;
21+
esac
22+
23+
kubectl delete namespaces "$namespace" --force --grace-period=0 --timeout=10s || {
24+
kubectl proxy --port=1337 & pid=$!
25+
sleep 1
26+
27+
curl -fsS "http://localhost:1337/api/v1/namespaces/$namespace" |
28+
jq '.spec.finalizers = []' |
29+
curl -fsS -XPUT -H 'Content-Type: application/json' "http://localhost:1337/api/v1/namespaces/$namespace/finalize" -d @-
30+
31+
kill $pid
32+
}

0 commit comments

Comments
 (0)