<p>I have a controller which Reconciles MyKind Custom Resource in 'foo' namespace. Within the reconcile loop, it creates a deployment MyDeployment in 'bar' namespace. I am wondering how can I setup a watch on the MyDeployment created in 'bar' namespace which is different than namespace ('foo') where the custom resource live.</p>
<p>I tried setting up my manager with the following, but it doesnt seem to work since the deployment I am trying to watch are in different namespace hence the controller is not able to receive any events for the CRUD operation on the deployment.</p>
<pre><code>    return controllerruntime.NewControllerManagedBy(mgr).
        For(&amp;v1alpha1.MyKind{}).
        Owns(&amp;appsv1.Deployment{}).
        Complete(r)
}
</code></pre>
<p>Is there any custom watch that I can configure my controller with in order to receive events for the deployment in a different namespace.</p>
<p>Note: I tried handler.EnqueueRequestsFromMapFunc, IIUC it also reconciles for Kinds in the same namespace.</p>

Kapoor Akul
<p>You can use <a href="https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/cache#MultiNamespacedCacheBuilder" rel="nofollow noreferrer">MultiNamespacedCacheBuilder</a> as the <code>NewCache</code> function when creating manager. This can be set in <a href="https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.13.0/pkg/manager#Options" rel="nofollow noreferrer">manager.Options</a>.</p>
<p>For example:</p>
<pre><code>namespace := &quot;ns1,ns1&quot;
options := ctrl.Options{
    .
    .
    .
    NewCache: cache.MultiNamespacedCacheBuilder(strings.Split(namespace, &quot;,&quot;))
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
</code></pre>
