title: How to add RBAC roles to a Controller for a different kind of resource in Kubebuilder
body: <p>I am creating a new Operator with Kubebuilder to deploy a Kubernetes controller to manage a new CRD Custom Resource Definition.</p>
  <p>This new CRD (let's say is called <code>MyNewResource</code>), needs to list/create/delete CronJobs.</p>
  <p>So in the Controller Go code where the <code>Reconcile(...)</code> method is defined I added a new RBAC comment to allow the reconciliation to work on CronJobs (see <a href="https://book.kubebuilder.io/reference/markers/rbac.html" rel="nofollow noreferrer">here</a>):</p>
  <pre class="lang-golang prettyprint-override"><code>//+kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;watch;create;update;patch;delete
  </code></pre>
  <p>However after building pushing and deploying the Docker/Kubernetes controller (repo <code>myrepo</code>, <code>make manifests</code>, then <code>make install</code>, then <code>make docker-build docker-push</code>, then <code>make deploy</code>), then in the logs I still see:</p>
  <pre><code>E0111 09:35:18.785523       1 reflector.go:138] pkg/mod/k8s.io/client-go@v0.22.1/tools/cache/reflector.go:167: Failed to watch *v1beta1.CronJob: failed to list *v1beta1.CronJob: cronjobs.batch is forbidden: User &quot;system:serviceaccount:myrepo-system:myrepo-controller-manager&quot; cannot list resource &quot;cronjobs&quot; in API group &quot;batch&quot; at the cluster scope
  </code></pre>
  <p>I also see issues about the cache, but they might not be related (not sure):</p>
  <pre><code>2022-01-11T09:35:57.857Z        ERROR   controller.mynewresource        Could not wait for Cache to sync        {&quot;reconciler group&quot;: &quot;mygroup.mydomain.com&quot;, &quot;reconciler kind&quot;: &quot;MyNewResource&quot;, &quot;error&quot;: &quot;failed to wait for mynewresource caches to sync: timed out waiting for cache to be synced&quot;}
  sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start
          /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.10.0/pkg/internal/controller/controller.go:234
  sigs.k8s.io/controller-runtime/pkg/manager.(*controllerManager).startRunnable.func1
          /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.10.0/pkg/manager/internal.go:696
  2022-01-11T09:35:57.858Z        ERROR   error received after stop sequence was engaged  {&quot;error&quot;: &quot;leader election lost&quot;}
  2022-01-11T09:35:57.858Z        ERROR   setup   problem running manager {&quot;error&quot;: &quot;failed to wait for mynewresource caches to sync: timed out waiting for cache to be synced&quot;}
  </code></pre>
  <p>How can I allow my new Operator to deal with CronJobs resources?</p>
  <p>At the moment basically I am not able to create new CronJobs programmatically (Go code) when I provide some YAML for a new instance of my CRD, by invoking:</p>
  <pre><code>kubectl create -f mynewresource-project/config/samples/
  </code></pre>