Closed blez closed 5 months ago
In the past, the manager.Options
struct had a Namespace
field which could be used to restrict the scope of the operator. However, this field was deprecated but the same effect could be achieved by customizing the cache options as shown in the example below:
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionID: "852d23b0.example.com",
Cache: cache.Options{
Namespaces: []string{"namespace1", "namespace2"},
},
})
Below is a link to an out of date operator code that uses the old approach to scope the operator to a single namespace. Hopefully it will be a satisfactory reference / guide in your endeavor.
Well, the most recent controller-runtime code show the cache.Options
struct has changed further. As a result, the Namespaces field no longer exists has has been replaced by the DefaultNamespaces
field.
So, ideally, depending on the version of operator-sdk you are using and the version of dependencies and more specifically controller-runtime is in use, the solution could look different.
With that being said, what version of operator-sdk and controller-runtime are used in your operator?
Thanks!
The purpose of this issue was to say that documentation is wrong and should be fixed.
I use the DefaultNamespaces
field.
Thank you for pointing that out. It was not clear in your initial post. If you would like to add a PR to update the documentation, that would be greatly appreciated.
https://sdk.operatorframework.io/docs/building-operators/golang/operator-scope/#watching-resources-in-a-single-namespace
Namespace
filed is not a part ofmanager.Options
struct