<p>I am working on a custom kubernetes controller, which creates kubernetes secrets based off some inputs. As part of this controller it is required to copy these secrets to multiple namespaces. Which it successfully does. </p>

<p>For e.g. </p>

<pre><code>CustomSecretGenerator 

metadata:
 names : mypersonalsecret
spec:
 secret:
  name: mysecret
  namespace: default
 target:
  namespaces:
   - dev
   - personal
</code></pre>

<p>Above is a rough CRD of the controller input. I am able to copy secrets from one namespace to another with owner reference set to my Controller name. </p>

<p>My PROBLEM:</p>

<ol>
<li>If I delete the default/mysecret secret it will auto-generate (with a autogenerating logic). But if I delete secret in other namespaces i.e. dev/mysecret or personal/mysecret the controller doesnt auto-generate (with the autogenerating logic). I tried to catch all the events, but I suspect that Controller is not able to watch the secret generated in the target namespace.</li>
</ol>

<p>Here is watch code block </p>

<pre><code>err = c.Watch(&amp;source.Kind{Type: &amp;corev1.Secret{}}, &amp;handler.EnqueueRequestForOwner{
        IsController: true,
        OwnerType:    &amp;appv1alpha1.MyCustomController{},
    })
</code></pre>

<p>and this is the metadata section for all the secrets that get generated with the controller</p>

<pre><code>name: mysecret
  namespace: dev
  ownerReferences:
  - apiVersion: com.company.app/v1alpha1
    blockOwnerDeletion: true
    controller: true
    kind: MyCustomController
    name: example-customer-controller
    uid: ed2fa8c5-6855-11e9-94c6-0050569d445e
</code></pre>

<p>Also my controller is running in a default namespace and has role with all access to secrets.</p>

<p><strong>EDIT:</strong></p>

<p>This is the section of the code which creates the Secret.</p>

<pre><code>mySecret := &amp;corev1.Secret{
        TypeMeta: meta_v1.TypeMeta{
            APIVersion: "v1",
            Kind:       "Secret",
        },
        ObjectMeta: meta_v1.ObjectMeta{
            Name:      secretName,
            Namespace: secretNamespace,
            Labels:    labelsforRegistryToken(crt.Name),
        },
        Data: map[string][]byte{
            v1.DockerConfigJsonKey: jsonValue,
        },
        Type: corev1.SecretTypeDockerConfigJson,
    }
    controllerutil.SetControllerReference(crt, mySecret, r.scheme)
</code></pre>

<p>NOTE: <code>crt</code> is the custom controller object which controls the creation of the object.</p>

<p>I tried copying the ownerrefence from the default/mysecret to dev/mysecret, the controller is still not able to detect the deletion of the dev/mysecret.</p>

subodev
<p>Since the controller wasn't able to detect the changes from the object in other namespace, I tried to scan all the namespaces in the cluster and had the reconcile loop end with </p>

<p><code>return reconcile.Result{RequeueAfter: time.Duration(15) * time.Minute}, nil</code> </p>

<p>to allow reconciliation every 15 minutes. The controller does respond to the events to the secrets created in the same namespace as the controller is running. </p>
