From 49b9d0aa0bd87f7a70ba89d27fd9a20f14ff18c3 Mon Sep 17 00:00:00 2001 From: varshaprasad96 Date: Sat, 8 May 2021 11:04:13 -0700 Subject: [PATCH] :bug: filter global namespace while looking for cluster scoped resources In the current implementation of multinamespaced cache, we look at global namespace while listing objects from all namespaced. Global namespace should not be looked at while fetching namespaced resources. --- pkg/cache/multi_namespace_cache.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/cache/multi_namespace_cache.go b/pkg/cache/multi_namespace_cache.go index 7e3f67d8d4..ed37b6dd7f 100644 --- a/pkg/cache/multi_namespace_cache.go +++ b/pkg/cache/multi_namespace_cache.go @@ -50,9 +50,18 @@ func MultiNamespacedCacheBuilder(namespaces []string) NewCacheFunc { if err != nil { return nil, err } - // create a cache for cluster scoped resources - namespaces = append(namespaces, globalCache) + caches := map[string]Cache{} + + // create a cache for cluster scoped resources + gCache, err := New(config, opts) + if err != nil { + return nil, fmt.Errorf("error creating global cache %v", err) + } + + // add global cache to the cacheMap + caches[globalCache] = gCache + for _, ns := range namespaces { opts.Namespace = ns c, err := New(config, opts) @@ -190,7 +199,10 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList, limitSet := listOpts.Limit > 0 var resourceVersion string - for _, cache := range c.namespaceToCache { + for ns, cache := range c.namespaceToCache { + if ns == globalCache { + continue + } listObj := list.DeepCopyObject().(client.ObjectList) err = cache.List(ctx, listObj, &listOpts) if err != nil {