operator-sdk icon indicating copy to clipboard operation
operator-sdk copied to clipboard

Operators Scope documentation requires update

Open blez opened this issue 1 year ago • 3 comments

https://sdk.operatorframework.io/docs/building-operators/golang/operator-scope/#watching-resources-in-a-single-namespace

Namespace filed is not a part of manager.Options struct

blez avatar Feb 16 '24 19:02 blez

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.

OchiengEd avatar Feb 26 '24 18:02 OchiengEd

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?

OchiengEd avatar Feb 26 '24 18:02 OchiengEd

Thanks! The purpose of this issue was to say that documentation is wrong and should be fixed. I use the DefaultNamespaces field.

blez avatar Feb 26 '24 19:02 blez

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.

OchiengEd avatar Mar 12 '24 18:03 OchiengEd