Skip to content

Support dynamically watching objects based on namespaces labels #3178

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

Open
tabarafael opened this issue Mar 24, 2025 · 6 comments
Open

Support dynamically watching objects based on namespaces labels #3178

tabarafael opened this issue Mar 24, 2025 · 6 comments

Comments

@tabarafael
Copy link

Inside "sigs.k8s.io/controller-runtime/pkg/cache".Options The option for DefaultNamespaces should select the namespaces in which the cache watches.

When setting the cache to watch dynamic namespaces that should be identified through a label selector the cache refuses to sync properly, when attempting to get a secret from such namespace, it returns the error:

failed to get secret: /v1, Kind=Secret is not cached.

code example:

	labelRequirements, err := labels.NewRequirement(
		"key", selection.In, []string{"value1", "value2"})
	
        cacheOpts := cache.Options{
		DefaultNamespaces: map[string]cache.Config{
			cache.AllNamespaces: cache.Config{
				LabelSelector: labels.NewSelector().Add(*labelRequirements),
			},
		},
		ReaderFailOnMissingInformer: true,
		SyncPeriod:                  &syncTimer,
	}
....

When replacing the cache.AllNamespaces string with the name of the namespaces and removing the label selector it works properly.

@alvaroaleman
Copy link
Member

The labelselector is not a labelselector for namespaces, it is a labelselector for objects inside the namespace

@tabarafael
Copy link
Author

So selecting a namespace by the label instead of the name is just not a supported feature? instead of a bug.

You see, I need to cache the objects inside these dynamic namespaces with random (uuid) names, the objects don't have any label that I can go off of to select them. I think I have exhausted my options already.

@alvaroaleman
Copy link
Member

So selecting a namespace by the label instead of the name is just not a supported feature

It is not supported, no.

@sbueringer
Copy link
Member

sbueringer commented Mar 25, 2025

You can potentially just watch cluster-wide and then filter out ConfigMaps in namespaces you don't care about via predicate or within Reconcile

@tabarafael
Copy link
Author

That just has the problem in that it requires cluster-wide permission for get/list, instead of only namespaced permission.

@alvaroaleman
Copy link
Member

/rename Support dynamically watching objects based on namespaces labels

Renaming the issue to clarify the problem.

What you are asking for isn't supported well by either the server side nor the client libs, you would need some sort of controller that dynamically starts and stops informers based on the labeling of namespaces

@alvaroaleman alvaroaleman changed the title Label Selector does not work properly for cache 'DefaultNamespaces' with 'LabelSelector' Support dynamically watching objects based on namespaces labels Mar 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants