Skip to content

Commit 2b0d261

Browse files
committed
bug: inherited defaults not respected in cache BuilderWithOptions
When using BuilderWithOptions the inherited (manager/cluster) options are lost. If they were provided, they are stronger than the cache package defaults. (Overrides default dynamic mapper in my case) Signed-off-by: Alex Kalenyuk <[email protected]>
1 parent 942d53b commit 2b0d261

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/cache/cache.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func BuilderWithOptions(options Options) NewCacheFunc {
199199
if err != nil {
200200
return nil, err
201201
}
202+
options = defaultToInheritedOpts(options, inherited)
202203
options, err = defaultOpts(config, options)
203204
if err != nil {
204205
return nil, err
@@ -424,6 +425,21 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
424425
return opts, nil
425426
}
426427

428+
func defaultToInheritedOpts(opts, inherited Options) Options {
429+
if opts.Scheme == nil {
430+
opts.Scheme = inherited.Scheme
431+
}
432+
433+
if opts.Mapper == nil {
434+
opts.Mapper = inherited.Mapper
435+
}
436+
437+
if opts.Resync == nil {
438+
opts.Resync = inherited.Resync
439+
}
440+
return opts
441+
}
442+
427443
func convertToByGVK[T any](byObject map[client.Object]T, def T, scheme *runtime.Scheme) (map[schema.GroupVersionKind]T, error) {
428444
byGVK := map[schema.GroupVersionKind]T{}
429445
for object, value := range byObject {

0 commit comments

Comments
 (0)