Skip to content

Commit

Permalink
Scoped cache config for NROP namespace and cluster resources
Browse files Browse the repository at this point in the history
This ensures the informer can successfully watch and list Service objects.
  Without this restriction, the operator will encounter the following failures:
   reflector.go:561] sigs.k8s.io/controller-runtime/pkg/cache/internal/informers.go:106: failed to list *v1.Service: services is forbidden: User "system:serviceaccount:numaresources:numaresources-controller-manager" cannot list resource "services" in API group "" at the cluster scope
   reflector.go:158] "Unhandled Error" err="sigs.k8s.io/controller-runtime/pkg/cache/internal/informers.go:106: Failed to watch *v1.Service: failed to list *v1.Service: services is forbidden: User \"system:serviceaccount:numaresources:numaresources-controller-manager\" cannot list resource \"services\" in API group \"\" at the cluster scope" logger="UnhandledError"

Signed-off-by: Ronny Baturov <[email protected]>
  • Loading branch information
rbaturov committed Jan 7, 2025
1 parent 300ba5d commit 1904cfc
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
securityv1 "github.com/openshift/api/security/v1"
machineconfigv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8sruntime "k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -247,7 +248,12 @@ func main() {
klog.InfoS("metrics server", "enabled", params.enableMetrics, "addr", params.metricsAddr)

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Cache: cache.Options{}, // TODO: restrict namespace here?
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{
namespace: {},
metav1.NamespaceNone: {},
},
},
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: params.metricsAddr,
Expand Down

0 comments on commit 1904cfc

Please sign in to comment.