-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstuck-namespace-remover.sh
More file actions
21 lines (19 loc) · 1.02 KB
/
stuck-namespace-remover.sh
File metadata and controls
21 lines (19 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
###########
#
# Author: J-dar Siegfred Rodriguez
# Create: August 21, 2021
#
# Used for removing stuck namespaces
# NOTE: Stuck for a long time, probably due to delete finalizers
#
# Symptoms:
# executing "kubectl api-resources --verbs=list --namespaced -o name | xargs -n 1 kubectl get -n <NAMESPACE>" results in
# "error: unable to retrieve the complete list of server APIs: something something: the server is currently unable to handle the request"
#
# Dependency:
# JQ JSON processor.
#
#########################
#!/bin/bash
for ns in $(kubectl get ns --field-selector status.phase=Terminating -o jsonpath='{.items[*].metadata.name}'); do kubectl get ns $ns -ojson | jq '.spec.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/$ns/finalize" -f -; done
for ns in $(kubectl get ns --field-selector status.phase=Terminating -o jsonpath='{.items[*].metadata.name}'); do kubectl get ns $ns -ojson | jq '.metadata.finalizers = []' | kubectl replace --raw "/api/v1/namespaces/$ns/finalize" -f -; done