Skip to content

Commit

Permalink
bug: inherited defaults not respected in cache BuilderWithOptions
Browse files Browse the repository at this point in the history
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 <akalenyu@redhat.com>
  • Loading branch information
akalenyu committed Sep 11, 2023
1 parent 942d53b commit 2270f10
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ func BuilderWithOptions(options Options) NewCacheFunc {
if err != nil {
return nil, err
}
options, err = defaultToInheritedOpts(options, inherited)
if err != nil {
return nil, err
}
options, err = defaultOpts(config, options)
if err != nil {
return nil, err
Expand Down Expand Up @@ -424,6 +428,21 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
return opts, nil
}

func defaultToInheritedOpts(opts, inherited Options) (Options, error) {
if opts.Scheme == nil {
opts.Scheme = inherited.Scheme
}

if opts.Mapper == nil {
opts.Mapper = inherited.Mapper
}

if opts.Resync == nil {
opts.Resync = inherited.Resync
}
return opts, nil
}

func convertToByGVK[T any](byObject map[client.Object]T, def T, scheme *runtime.Scheme) (map[schema.GroupVersionKind]T, error) {
byGVK := map[schema.GroupVersionKind]T{}
for object, value := range byObject {
Expand Down

0 comments on commit 2270f10

Please sign in to comment.