Skip to content

Commit

Permalink
🐛 filter global namespace while looking for cluster scoped resources
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
varshaprasad96 committed May 13, 2021
1 parent ce2f0c9 commit 49b9d0a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/cache/multi_namespace_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 49b9d0a

Please sign in to comment.