operator-framework/operator-sdk

Operators Scope documentation requires update

blez opened this issue · 4 comments

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.

See https://github.com/kubernetes-sigs/controller-runtime/blob/5f8d96b043ef8ccadc544535415395be336630e8/pkg/cache/cache.go#L188

With that being said, what version of operator-sdk and controller-runtime are used in your operator?

blez commented

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.