-
Notifications
You must be signed in to change notification settings - Fork 1.3k
DefaultNamespaces Cache Option doesn't allow All Namespaces for List #2628
Description
I'm trying to limit the controller to watch config maps only in one namespace, while watching other resources in all namespaces. Mainly for performance reasons, I don't want the controller to trigger for any config map event in the cluster.
The cache design document describes the config as DefaultNamespaces map[string]*Config, while the code implements DefaultNamespaces map[string]Config. Since all options are nil-able I guess that's not an issue.
From the cache tests I'd expect this to allow list and get in all namespaces:
Cache: cache.Options{
DefaultNamespaces: map[string]cache.Config{cache.AllNamespaces: {}},
},
However, it results in unable to list: test-7af124d because of unknown namespace for the cache.
I think that's because theList func in multi cache is missing the special handling, that was added to Get func:
diff --git a/pkg/cache/multi_namespace_cache.go b/pkg/cache/multi_namespace_cache.go
index 87c31a7c..8e58b0c0 100644
--- a/pkg/cache/multi_namespace_cache.go
+++ b/pkg/cache/multi_namespace_cache.go
@@ -237,6 +237,9 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
if listOpts.Namespace != corev1.NamespaceAll {
cache, ok := c.namespaceToCache[listOpts.Namespace]
if !ok {
+ if global, hasGlobal := c.namespaceToCache[metav1.NamespaceAll]; hasGlobal {
+ return global.List(ctx, list, opts...)
+ }
return fmt.Errorf("unable to list: %v because of unknown namespace for the cache", listOpts.Namespace)
}
return cache.List(ctx, list, opts...)
If I understand the consequences of cache options correctly, they do limit Watch, but also affect the cached client. I need another client, e.g. APIReader, to retrieve configmaps in other namespaces.