Skip to content

Commit 22815fc

Browse files
authoredFeb 20, 2025
Merge pull request #3127 from k8s-infra-cherrypick-robot/cherry-pick-3126-to-release-0.20
[release-0.20] 🐛 fix: cache should list out of global cache when present and necessary
2 parents 52b1791 + b015843 commit 22815fc

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
 

‎pkg/cache/cache_test.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ var _ = Describe("Informer Cache with ReaderFailOnMissingInformer", func() {
130130
var _ = Describe("Multi-Namespace Informer Cache", func() {
131131
CacheTest(cache.New, cache.Options{
132132
DefaultNamespaces: map[string]cache.Config{
133-
testNamespaceOne: {},
134-
testNamespaceTwo: {},
135-
"default": {},
133+
cache.AllNamespaces: {FieldSelector: fields.OneTermEqualSelector("metadata.namespace", testNamespaceOne)},
134+
testNamespaceTwo: {},
135+
"default": {},
136136
},
137137
})
138138
NonBlockingGetTest(cache.New, cache.Options{
139139
DefaultNamespaces: map[string]cache.Config{
140-
testNamespaceOne: {},
141-
testNamespaceTwo: {},
142-
"default": {},
140+
cache.AllNamespaces: {FieldSelector: fields.OneTermEqualSelector("metadata.namespace", testNamespaceOne)},
141+
testNamespaceTwo: {},
142+
"default": {},
143143
},
144144
})
145145
})

‎pkg/cache/multi_namespace_cache.go

+3
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
262262
if listOpts.Namespace != corev1.NamespaceAll {
263263
cache, ok := c.namespaceToCache[listOpts.Namespace]
264264
if !ok {
265+
if global, hasGlobal := c.namespaceToCache[AllNamespaces]; hasGlobal {
266+
return global.List(ctx, list, opts...)
267+
}
265268
return fmt.Errorf("unable to list: %v because of unknown namespace for the cache", listOpts.Namespace)
266269
}
267270
return cache.List(ctx, list, opts...)

0 commit comments

Comments
 (0)