<p>In Kubernetes and Operator-sdk, we can define CRD (Custom Resource Definition) and CR (Custom Resource). In my operator controller, when a CR is initialized, then I create a new Deployment and service.</p>
<p>When we delete a CR object, then the correlated resources (such as Deployment or service) will be deleted as well at the same time. I understand it should be done by <code>CR</code> or <code>CRD</code> finalizer, this is just my guess.</p>
<p>Now I hit an issue, during Operator testing, under <code>envTest</code> environment, when I delete a <code>CR</code>, its correlated resources (Deployment or service) have not been deleted.</p>
<p>I am confused. In <code>real k8s cluster</code>, the correlated resources (Deployment or service) can be deleted automatically when I delete a <code>CR</code>, under <code>envTest environment</code>, why it doesn't delete correlated resources?</p>
<p>Could anybody point out the reason.</p>

Joe
<p>Deletion of orphaned resources is done by Kubernetes's <a href="https://kubernetes.io/docs/concepts/workloads/controllers/garbage-collection/" rel="nofollow noreferrer">garbage collector</a>, which is implemented in <a href="https://v1-16.docs.kubernetes.io/docs/concepts/cluster-administration/kubelet-garbage-collection/" rel="nofollow noreferrer">kubelet</a>. When you test operator in <code>envTest</code> environment, garbage collection doesn't work because <code>kubelet</code> is missing in that environment(it only deploys API server and etcd).</p>
