Skip to content

Commit 49b9d0a

Browse files
🐛 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.
1 parent ce2f0c9 commit 49b9d0a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

pkg/cache/multi_namespace_cache.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ func MultiNamespacedCacheBuilder(namespaces []string) NewCacheFunc {
5050
if err != nil {
5151
return nil, err
5252
}
53-
// create a cache for cluster scoped resources
54-
namespaces = append(namespaces, globalCache)
53+
5554
caches := map[string]Cache{}
55+
56+
// create a cache for cluster scoped resources
57+
gCache, err := New(config, opts)
58+
if err != nil {
59+
return nil, fmt.Errorf("error creating global cache %v", err)
60+
}
61+
62+
// add global cache to the cacheMap
63+
caches[globalCache] = gCache
64+
5665
for _, ns := range namespaces {
5766
opts.Namespace = ns
5867
c, err := New(config, opts)
@@ -190,7 +199,10 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
190199
limitSet := listOpts.Limit > 0
191200

192201
var resourceVersion string
193-
for _, cache := range c.namespaceToCache {
202+
for ns, cache := range c.namespaceToCache {
203+
if ns == globalCache {
204+
continue
205+
}
194206
listObj := list.DeepCopyObject().(client.ObjectList)
195207
err = cache.List(ctx, listObj, &listOpts)
196208
if err != nil {

0 commit comments

Comments
 (0)