Skip to content

Support dynamically watching objects based on namespaces labels #3178

Open
@tabarafael

Description

@tabarafael

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions