Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Operators Scope documentation requires update #6682

Closed
blez opened this issue Feb 16, 2024 · 4 comments · Fixed by #6719
Closed

Operators Scope documentation requires update #6682

blez opened this issue Feb 16, 2024 · 4 comments · Fixed by #6719
Assignees
Labels
triage/support Indicates an issue that is a support question.
Milestone

Comments

@blez
Copy link

blez commented Feb 16, 2024

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

@OchiengEd OchiengEd self-assigned this Feb 26, 2024
@OchiengEd
Copy link
Contributor

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 OchiengEd added the triage/support Indicates an issue that is a support question. label Feb 26, 2024
@OchiengEd
Copy link
Contributor

OchiengEd commented Feb 26, 2024

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
Copy link
Author

blez commented Feb 26, 2024

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

@OchiengEd
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/support Indicates an issue that is a support question.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants