@@ -45,37 +45,37 @@ type MultiNamespacedOption func(*MultiNamespacedOptions)
45
45
// MultiNamespacedOptions is used to configure the functions used to create caches
46
46
// on a per-namespace basis.
47
47
type MultiNamespacedOptions struct {
48
- NewNamespaceCaches map [string ]NewCacheFunc
48
+ NewNamespacedCaches map [string ]NewCacheFunc
49
49
NewClusterScopedCache NewCacheFunc
50
50
NewDefaultNamespacedCache NewCacheFunc
51
51
}
52
52
53
- // WithLegacyNamespaceCaches configures the MultiNamespacedCacheWithOptionsBuilder
53
+ // WithLegacyNamespacedCaches configures the MultiNamespacedCacheWithOptionsBuilder
54
54
// with standard caches in each of the namespaces provided as well as for cluster-scoped
55
55
// objects. This option enables use of the MultiNamespacedCacheWithOptionsBuilder
56
56
// to match the behavior of the deprecated MultiNamespacedCacheBuilder.
57
- func WithLegacyNamespaceCaches (namespaces []string ) MultiNamespacedOption {
57
+ func WithLegacyNamespacedCaches (namespaces []string ) MultiNamespacedOption {
58
58
return func (options * MultiNamespacedOptions ) {
59
- WithNamespaceCaches (namespaces , New )(options )
59
+ WithNamespacedCaches (namespaces , New )(options )
60
60
WithClusterScopedCache (New )(options )
61
61
}
62
62
}
63
63
64
- // WithNamespaceCaches configures MultiNamespacedCacheWithOptionsBuilder
64
+ // WithNamespacedCaches configures MultiNamespacedCacheWithOptionsBuilder
65
65
// with namespace-specific caches that are created using the provided NewCacheFunc.
66
- func WithNamespaceCaches (namespaces []string , f NewCacheFunc ) MultiNamespacedOption {
66
+ func WithNamespacedCaches (namespaces []string , f NewCacheFunc ) MultiNamespacedOption {
67
67
return func (options * MultiNamespacedOptions ) {
68
68
for _ , ns := range namespaces {
69
- WithNamespaceCache (ns , f )(options )
69
+ WithNamespacedCache (ns , f )(options )
70
70
}
71
71
}
72
72
}
73
73
74
- // WithNamespaceCache configures MultiNamespacedCacheWithOptionsBuilder
74
+ // WithNamespacedCache configures MultiNamespacedCacheWithOptionsBuilder
75
75
// with a namespace cache that uses the provided NewCacheFunc.
76
- func WithNamespaceCache (namespace string , f NewCacheFunc ) MultiNamespacedOption {
76
+ func WithNamespacedCache (namespace string , f NewCacheFunc ) MultiNamespacedOption {
77
77
return func (options * MultiNamespacedOptions ) {
78
- options .NewNamespaceCaches [namespace ] = f
78
+ options .NewNamespacedCaches [namespace ] = f
79
79
}
80
80
}
81
81
@@ -89,7 +89,7 @@ func WithClusterScopedCache(f NewCacheFunc) MultiNamespacedOption {
89
89
90
90
// WithDefaultNamespacedCache configures MultiNamespacedCacheWithOptionsBuilder
91
91
// with a "catch-all" cache for namespace-scoped objects that are in namespaces
92
- // explicitly configured on the cache builder.
92
+ // not explicitly configured on the cache builder.
93
93
func WithDefaultNamespacedCache (f NewCacheFunc ) MultiNamespacedOption {
94
94
return func (options * MultiNamespacedOptions ) {
95
95
options .NewDefaultNamespacedCache = f
@@ -112,7 +112,7 @@ func WithDefaultNamespacedCache(f NewCacheFunc) MultiNamespacedOption {
112
112
// operations, reporting that a cluster-scoped cache is not defined.
113
113
func MultiNamespacedCacheWithOptionsBuilder (opts ... MultiNamespacedOption ) NewCacheFunc {
114
114
multiNamespaceOpts := MultiNamespacedOptions {
115
- NewNamespaceCaches : map [string ]NewCacheFunc {},
115
+ NewNamespacedCaches : map [string ]NewCacheFunc {},
116
116
}
117
117
for _ , opt := range opts {
118
118
opt (& multiNamespaceOpts )
@@ -134,14 +134,15 @@ func MultiNamespacedCacheWithOptionsBuilder(opts ...MultiNamespacedOption) NewCa
134
134
135
135
nsToCache := map [string ]Cache {}
136
136
if multiNamespaceOpts .NewDefaultNamespacedCache != nil {
137
- defaultNamespaceCache , err := multiNamespaceOpts .NewDefaultNamespacedCache (config , ignoreNamespaces (opts , multiNamespaceOpts .NewNamespaceCaches ))
137
+ defaultNamespacedOpts := setDefaultNamespacedCacheOpts (opts , multiNamespaceOpts .NewNamespacedCaches )
138
+ defaultNamespacedCache , err := multiNamespaceOpts .NewDefaultNamespacedCache (config , defaultNamespacedOpts )
138
139
if err != nil {
139
140
return nil , err
140
141
}
141
- nsToCache [corev1 .NamespaceAll ] = defaultNamespaceCache
142
+ nsToCache [corev1 .NamespaceAll ] = defaultNamespacedCache
142
143
}
143
144
144
- for ns , newCacheFunc := range multiNamespaceOpts .NewNamespaceCaches {
145
+ for ns , newCacheFunc := range multiNamespaceOpts .NewNamespacedCaches {
145
146
opts .Namespace = ns
146
147
nsToCache [ns ], err = newCacheFunc (config , opts )
147
148
if err != nil {
@@ -158,7 +159,7 @@ func MultiNamespacedCacheWithOptionsBuilder(opts ...MultiNamespacedOption) NewCa
158
159
}
159
160
}
160
161
161
- func ignoreNamespaces (opts Options , newObjectCaches map [string ]NewCacheFunc ) Options {
162
+ func setDefaultNamespacedCacheOpts (opts Options , newObjectCaches map [string ]NewCacheFunc ) Options {
162
163
fieldSelectors := []fields.Selector {}
163
164
if opts .DefaultSelector .Field != nil {
164
165
fieldSelectors = append (fieldSelectors , opts .DefaultSelector .Field )
@@ -180,11 +181,11 @@ func ignoreNamespaces(opts Options, newObjectCaches map[string]NewCacheFunc) Opt
180
181
// Deprecated: Use MultiNamespacedCacheWithOptionsBuilder instead:
181
182
//
182
183
// cache.MultiNamespacedCacheWithOptionsBuilder(
183
- // WithLegacyNamespaceCaches (namespaces),
184
+ // WithLegacyNamespacedCaches (namespaces),
184
185
// )
185
186
func MultiNamespacedCacheBuilder (namespaces []string ) NewCacheFunc {
186
187
return MultiNamespacedCacheWithOptionsBuilder (
187
- WithLegacyNamespaceCaches (namespaces ),
188
+ WithLegacyNamespacedCaches (namespaces ),
188
189
)
189
190
}
190
191
@@ -345,7 +346,7 @@ func (c *multiNamespaceCache) Get(ctx context.Context, key client.ObjectKey, obj
345
346
cache , ok = c .namespaceToCache [corev1 .NamespaceAll ]
346
347
}
347
348
if ! ok {
348
- return fmt .Errorf ("unable to get: %v because of unknown namespace for the cache" , key )
349
+ return fmt .Errorf ("unable to get %q: neither a per- namespace nor a default namespaced cache exists " , key )
349
350
}
350
351
return cache .Get (ctx , key , obj )
351
352
}
@@ -375,7 +376,7 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
375
376
cache , ok = c .namespaceToCache [corev1 .NamespaceAll ]
376
377
}
377
378
if ! ok {
378
- return fmt .Errorf ("unable to get: %v because of unknown namespace for the cache" , listOpts .Namespace )
379
+ return fmt .Errorf ("unable to list in namespace %q: neither a per- namespace nor a default namespaced cache exists " , listOpts .Namespace )
379
380
}
380
381
return cache .List (ctx , list , opts ... )
381
382
}
0 commit comments