I have:
// +kubebuilder:rbac:groups="apps",resources=deployments,verbs=create;get;list;delete;watch;update;patch
The config/rbac/role.yaml looks OK and I have applied it.
config/rbac/role.yaml
after changing the markers, run make manifests
.
2021-10-13T07:38:51.016Z ERROR controller-runtime.manager.controller.webserver Reconciler error {"reconciler group": "webservers.web.servers.org", "reconciler kind": "WebServer", "name": "tomcatdemo", "namespace": "default", "error": "deployments.apps \"tomcat-demo\" is forbidden: User \"system:serviceaccount:jws-operator-system:jws-operator-controller-manager\" cannot update resource \"deployments\" in API group \"apps\" in the namespace \"default\""}
namespacestringspecifies the scope of the Rule. If not set, the Rule belongs to the generated ClusterRole. If set, the Rule belongs to a Role, whose namespace is specified by this field
--
You received this message because you are subscribed to the Google Groups "Operator Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to operator-framew...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/operator-framework/06362d6a-476d-4ca3-a3fc-693154d00227n%40googlegroups.com.
Hi Jean-Frederic,
Following some comments inline whcih I hope helps you out. Also, could you please provide some additional info to see if we can help you out?
I have:
// +kubebuilder:rbac:groups="apps",resources=deployments,verbs=create;get;list;delete;watch;update;patch
The config/rbac/role.yaml looks OK and I have applied it.
Note that to updateconfig/rbac/role.yaml
after changing the markers, runmake manifests
.More info: https://sdk.operatorframework.io/docs/building-operators/golang/migration/#set-rbac-permissions
You can check the markers used to the Memcached sample in: https://github.com/operator-framework/operator-sdk/blob/master/testdata/go/v3/memcached-operator/controllers/memcached_controller.go#L44-L48
2021-10-13T07:38:51.016Z ERROR controller-runtime.manager.controller.webserver Reconciler error {"reconciler group": "webservers.web.servers.org", "reconciler kind": "WebServer", "name": "tomcatdemo", "namespace": "default", "error": "deployments.apps \"tomcat-demo\" is forbidden: User \"system:serviceaccount:jws-operator-system:jws-operator-controller-manager\" cannot update resource \"deployments\" in API group \"apps\" in the namespace \"default\""}
How are you deploying the project?
Because if you follow up the steps provided you would use e.g.:
make manifests docker-build docker-push IMG=example.com/memcached-operator:v0.0.1
make deploy IMG=example.com/memcached-operator:v0.0.1
Then, your project would be deployed in a namespace created for your Operator where the default configuration scaffold for you should work.If I am not wrong that would be `<your project name>-system` and not default as we can check in the logs provided.
Also, see that you have the namespace option for the markers as well:namespacestringspecifies the scope of the Rule. If not set, the Rule belongs to the generated ClusterRole. If set, the Rule belongs to a Role, whose namespace is specified by this field
> I have noted that old rbac file is creating a role and the new a ClusterRole, I guess I missed something.
- Before 1.0.0 SDK scaffold rule and not cluster rule. See what changed in the migration guide: https://sdk.operatorframework.io/docs/building-operators/golang/migration/#what-was-changed
- Also, please check: https://sdk.operatorframework.io/docs/building-operators/golang/migration/#set-rbac-permissions
If the above information is not enough to solve your problem,
Yes that was enough, the basic features of the operator are working, thanks.
I have 2 remaining questions:
1 - the operator is doing:
err := r.Client.Get(context.TODO(), types.NamespacedName{Name:
resourceName, Namespace: resourceNamespace}, resource)
to check if a resource is existing, should I use the ctx I have in the func (r *WebServerReconciler) Reconcile(ctx context.Context instead?
2 - the SetupWithManager() does have a Owns() but the old code has a bunch of Watch(1) I am not sure how to handle that.
In our example, theWatch
implemented for the Deployment will be replaced withOwns(&appsv1.Deployment{})
. Setting up controllerWatches
is simplified in more recent versions of controller-runtime, which has controller Builder helpers to handle more of the details.