1

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
  • 53
  • 1
  • 7

1 Answers1

1

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.

Ottovsky
  • 2,068
  • 15
  • 22
  • Thanks for your reply Adam. I am using ownerReference for resources my controller is creating. but here we are talking about the input custom resources, not the output. can I do it on the input, without causing a potential deadlock? – igorT Jun 02 '19 at 20:00
  • I am assuming you must be using one of the operators framework, so in that case the ownerReference is established between input-output resources. So what I would suggest is to implement an ownerReference between controller -> input resources, so in that case if controller is removed it will remove all input resources, what will cause removal of all output resources as well. I don't think this approach can cause a deadlock. – Ottovsky Jun 02 '19 at 20:12
  • thanks again. yes I am using https://github.com/operator-framework/operator-sdk ownerReference of Operator owning all instances of myCustom? – igorT Jun 03 '19 at 11:42