@@ -45,37 +45,37 @@ type MultiNamespacedOption func(*MultiNamespacedOptions)
4545// MultiNamespacedOptions is used to configure the functions used to create caches
4646// on a per-namespace basis.
4747type MultiNamespacedOptions struct {
48- NewNamespaceCaches map [string ]NewCacheFunc
48+ NewNamespacedCaches map [string ]NewCacheFunc
4949 NewClusterScopedCache NewCacheFunc
5050 NewDefaultNamespacedCache NewCacheFunc
5151}
5252
53- // WithLegacyNamespaceCaches configures the MultiNamespacedCacheWithOptionsBuilder
53+ // WithLegacyNamespacedCaches configures the MultiNamespacedCacheWithOptionsBuilder
5454// with standard caches in each of the namespaces provided as well as for cluster-scoped
5555// objects. This option enables use of the MultiNamespacedCacheWithOptionsBuilder
5656// to match the behavior of the deprecated MultiNamespacedCacheBuilder.
57- func WithLegacyNamespaceCaches (namespaces []string ) MultiNamespacedOption {
57+ func WithLegacyNamespacedCaches (namespaces []string ) MultiNamespacedOption {
5858 return func (options * MultiNamespacedOptions ) {
59- WithNamespaceCaches (namespaces , New )(options )
59+ WithNamespacedCaches (namespaces , New )(options )
6060 WithClusterScopedCache (New )(options )
6161 }
6262}
6363
64- // WithNamespaceCaches configures MultiNamespacedCacheWithOptionsBuilder
64+ // WithNamespacedCaches configures MultiNamespacedCacheWithOptionsBuilder
6565// 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 {
6767 return func (options * MultiNamespacedOptions ) {
6868 for _ , ns := range namespaces {
69- WithNamespaceCache (ns , f )(options )
69+ WithNamespacedCache (ns , f )(options )
7070 }
7171 }
7272}
7373
74- // WithNamespaceCache configures MultiNamespacedCacheWithOptionsBuilder
74+ // WithNamespacedCache configures MultiNamespacedCacheWithOptionsBuilder
7575// 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 {
7777 return func (options * MultiNamespacedOptions ) {
78- options .NewNamespaceCaches [namespace ] = f
78+ options .NewNamespacedCaches [namespace ] = f
7979 }
8080}
8181
@@ -89,7 +89,7 @@ func WithClusterScopedCache(f NewCacheFunc) MultiNamespacedOption {
8989
9090// WithDefaultNamespacedCache configures MultiNamespacedCacheWithOptionsBuilder
9191// 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.
9393func WithDefaultNamespacedCache (f NewCacheFunc ) MultiNamespacedOption {
9494 return func (options * MultiNamespacedOptions ) {
9595 options .NewDefaultNamespacedCache = f
@@ -112,7 +112,7 @@ func WithDefaultNamespacedCache(f NewCacheFunc) MultiNamespacedOption {
112112// operations, reporting that a cluster-scoped cache is not defined.
113113func MultiNamespacedCacheWithOptionsBuilder (opts ... MultiNamespacedOption ) NewCacheFunc {
114114 multiNamespaceOpts := MultiNamespacedOptions {
115- NewNamespaceCaches : map [string ]NewCacheFunc {},
115+ NewNamespacedCaches : map [string ]NewCacheFunc {},
116116 }
117117 for _ , opt := range opts {
118118 opt (& multiNamespaceOpts )
@@ -134,14 +134,15 @@ func MultiNamespacedCacheWithOptionsBuilder(opts ...MultiNamespacedOption) NewCa
134134
135135 nsToCache := map [string ]Cache {}
136136 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 )
138139 if err != nil {
139140 return nil , err
140141 }
141- nsToCache [corev1 .NamespaceAll ] = defaultNamespaceCache
142+ nsToCache [corev1 .NamespaceAll ] = defaultNamespacedCache
142143 }
143144
144- for ns , newCacheFunc := range multiNamespaceOpts .NewNamespaceCaches {
145+ for ns , newCacheFunc := range multiNamespaceOpts .NewNamespacedCaches {
145146 opts .Namespace = ns
146147 nsToCache [ns ], err = newCacheFunc (config , opts )
147148 if err != nil {
@@ -158,7 +159,7 @@ func MultiNamespacedCacheWithOptionsBuilder(opts ...MultiNamespacedOption) NewCa
158159 }
159160}
160161
161- func ignoreNamespaces (opts Options , newObjectCaches map [string ]NewCacheFunc ) Options {
162+ func setDefaultNamespacedCacheOpts (opts Options , newObjectCaches map [string ]NewCacheFunc ) Options {
162163 fieldSelectors := []fields.Selector {}
163164 if opts .DefaultSelector .Field != nil {
164165 fieldSelectors = append (fieldSelectors , opts .DefaultSelector .Field )
@@ -180,11 +181,11 @@ func ignoreNamespaces(opts Options, newObjectCaches map[string]NewCacheFunc) Opt
180181// Deprecated: Use MultiNamespacedCacheWithOptionsBuilder instead:
181182//
182183// cache.MultiNamespacedCacheWithOptionsBuilder(
183- // WithLegacyNamespaceCaches (namespaces),
184+ // WithLegacyNamespacedCaches (namespaces),
184185// )
185186func MultiNamespacedCacheBuilder (namespaces []string ) NewCacheFunc {
186187 return MultiNamespacedCacheWithOptionsBuilder (
187- WithLegacyNamespaceCaches (namespaces ),
188+ WithLegacyNamespacedCaches (namespaces ),
188189 )
189190}
190191
@@ -345,7 +346,7 @@ func (c *multiNamespaceCache) Get(ctx context.Context, key client.ObjectKey, obj
345346 cache , ok = c .namespaceToCache [corev1 .NamespaceAll ]
346347 }
347348 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 . String () )
349350 }
350351 return cache .Get (ctx , key , obj )
351352}
@@ -375,7 +376,7 @@ func (c *multiNamespaceCache) List(ctx context.Context, list client.ObjectList,
375376 cache , ok = c .namespaceToCache [corev1 .NamespaceAll ]
376377 }
377378 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 )
379380 }
380381 return cache .List (ctx , list , opts ... )
381382 }
0 commit comments