3

This question is a follow up of: How to list really all objects of a nonexistant namespace?

Long story short:

$ kubectl get namespaces
NAME              STATUS   AGE
argo              Active   27d
default           Active   27d
kube-node-lease   Active   27d
kube-public       Active   27d
kube-system       Active   27d

$ kubectl get eventbus -n argo-events
NAME      AGE
default   17h

$ kubectl get eventsource -n argo-events
NAME                  AGE
pubsub-event-source   14h

There are two resources in namespace argo-events which actually no longer exits because I deleted it and expected it to be gone with all resources in it. Obviously something didn't work as expected.

Now (after listing potentially more objects - first question) I want to really get rid of those resources because they seem to block a redeployment.

But this ...

$ kubectl delete eventbus default -n argo-events
eventbus.argoproj.io "default" deleted
^C
$ kubectl delete eventsource pubsub-event-source -n argo-events
eventsource.argoproj.io "pubsub-event-source" deleted
^C

... doesn't work.

So, how do I force their deletion?


UPDATE:

$ kubectl describe eventbus default -n argo-events | grep -A 3 final
        f:finalizers:
          .:
          v:"eventbus-controller":
      f:status:
$ kubectl describe eventsource pubsub-event-source -n argo-events | grep -A 3 final
        f:finalizers:
          .:
          v:"eventsource-controller":
      f:spec:
Raffael
  • 19,547
  • 15
  • 82
  • 160
  • 2
    check if they have any finalizers that is blocking the deletion. also, could you try to create the `argo-events` namespace manually and then delete the resources, not sure if it would work though. – Krishna Chaurasia Mar 03 '21 at 09:14
  • I updated my question - yes, there are finalizers (I do not understand, though, what this actually means) – Raffael Mar 03 '21 at 09:21
  • 2
    finalizers are resources on kubernetes objects that prevent the resources from getting deleted unless all the finalizers are deleted. they could be added manually/dynamically by controllers. they are mostly used to add dependency between the resources to make sure the deletion happens in order. you can read about them [here](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#advanced-topics). – Krishna Chaurasia Mar 03 '21 at 09:35
  • 2
    as a side note, `kubectl delete namespace` is not the right way to uninstall resources of a namespace and could lead to unexpected results as is visible here. – Krishna Chaurasia Mar 03 '21 at 09:37
  • @KrishnaChaurasia what is the right way? – Raffael Mar 03 '21 at 09:43
  • 2
    unfortunately, I don't have the right answer. Generally all resource should be deleted before deleting the namespace. I see `kubectl delete all -n namespace` is one way but any finalizer will still block the deletion of the resource and must be removed first. May be someone else more experienced can provide a better/accurate answer. – Krishna Chaurasia Mar 03 '21 at 09:47
  • 1
    @KrishnaChaurasia Nonetheless your remark got me thinking. And especially in this specific use case - I just realized - it is actually not a good idea to just delete the namespace. – Raffael Mar 03 '21 at 10:08
  • Meh, it depends I think. I have a dev cluster that I just want to take the hammer to the mole hill approach. I want to save the cluster but just destroy certain resources which are failing to complete deletion. This is a time where deleting finalizers would be OK imo. – Jim Feb 28 '22 at 01:07

2 Answers2

6

This worked:

$ kubectl create namespace argo-events
namespace/argo-events created

$ kubectl patch eventsource/pubsub-event-source -p '{"metadata":{"finalizers":[]}}' --type=merge -n argo-events
eventsource.argoproj.io/pubsub-event-source patched

$ kubectl patch eventbus/default -p '{"metadata":{"finalizers":[]}}' --type=merge -n argo-events
eventbus.argoproj.io/default patched

$ kubectl delete namespace argo-events
namespace "argo-events" deleted

If somebody stumbles upon this answer and knows why this works - please add an explanation in a comment. That would be cool, thanks.

Raffael
  • 19,547
  • 15
  • 82
  • 160
  • 1
    Hello, I'm glad that you've managed to solve your issue and also need to agree with comments posted by Krishna Chaurasia. As for why, I'd reckon the finalizers weren't completely finished (or just stuck) when you were in process of deleting resources that's why when you patched the resources to not include the finalizers they could be deleted without any issues. Similar case can be found (not with argo): [here](https://stackoverflow.com/questions/65186930/istio-delete-istio-control-plane-process-is-frozen) – Dawid Kruk Mar 03 '21 at 16:11
0

What about:

kubectl delete eventsource pubsub-event-source -n argo-events --grace-period=0 --force

?