<p>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:</p>

<p>e.g.</p>

<pre><code>kind: MyCustom
metadata:
 finalizers:
    - MyCustom.finalizers.com
 name: mycustomResourceInstance
</code></pre>

<p>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.</p>

<p>work around is to edit mycustomResourceInstance and remove the finalizer.</p>

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

igorT
<p>You have to look into owner references and foreground cascading deletion <a href="https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/</a> and implement it into your controller, so garbage collector delete your objects in order.</p>
