Deleting namespace hangs on custom resource finalizer

6/2/2019

I have defined a controller (Operator) for handling some Custom Resources in my K8S namespace. each custom resource has a Finalizer so the controller can handle it before it is being deleted:

e.g.

kind: MyCustom
metadata:
 finalizers:
    - MyCustom.finalizers.com
 name: mycustomResourceInstance

this works well, until I delete the namespace ("kubectl delete ns"). if k8s garbage collects the controller pod first - "mycustomResourceInstance" remains stuck in a deleting state, and prevents successful namespace removal.

work around is to edit mycustomResourceInstance and remove the finalizer.

is there any way to make sure the controller does not get deleted, while any instances of the custom resource exist in the namespace?

-- igorT
kubernetes
kubernetes-custom-resources

1 Answer

6/2/2019

You have to look into owner references and foreground cascading deletion https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/ and implement it into your controller, so garbage collector delete your objects in order.

-- Adam Otto
Source: StackOverflow