ctron / kill-kube-ns

Kill a Kubernetes namespace suffering from being stuck in "Terminating"
146 stars 51 forks source link

Cannot iterate over null #2

Open oxr463 opened 3 years ago

oxr463 commented 3 years ago
./kill-kube-ns cattle-global-data
jq: error (at <stdin>:63): Cannot iterate over null (null)

kubectl get ns                   
NAME                                     STATUS        AGE
cattle-global-data                       Terminating   22d
ctron commented 3 years ago

Can you show the finalizers which are set for this namespace?

oxr463 commented 3 years ago
kubectl get namespace cattle-global-data -o yaml
apiVersion: v1
kind: Namespace
metadata:
  annotations:
    cattle.io/status: '{"Conditions":[{"Type":"ResourceQuotaInit","Status":"True","Message":"","LastUpdateTime":"2021-09-17T20:43:31Z"},{"Type":"InitialRolesPopulated","Status":"True","Message":"","LastUpdateTime":"2021-09-17T20:43:32Z"}]}'
    lifecycle.cattle.io/create.namespace-auth: "true"
  creationTimestamp: "2021-09-17T20:43:25Z"
  deletionTimestamp: "2021-09-20T18:36:45Z"
  finalizers:
  - controller.cattle.io/namespace-auth
  labels:
    cattle.io/creator: norman
  name: cattle-global-data
  resourceVersion: "25719370"
  selfLink: /api/v1/namespaces/cattle-global-data
  uid: 0443db08-abe0-4406-9036-e8bfd6741f28
spec: {}
status:
  phase: Terminating
oxr463 commented 3 years ago

I removed the finalizer manually and the namespace disappeared, but I figured this tool would've done that for me.

ctron commented 3 years ago

The tool does that, but only when the finalizer is the kubernetes finalizer. You can swap out the name of the finalizer in the script.

It would be cool to have this script handle "null", and also to have the ability to put in the correct finalizer to remove.

Then again, I didn't need to use this script for quite a while. I guess the underlying issue was resolved. So, I am not sure what to do here.