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 12, 2023
1 parent 942d53b commit 2b0d261
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func BuilderWithOptions(options Options) NewCacheFunc {
if err != nil {
return nil, err
}
options = defaultToInheritedOpts(options, inherited)
options, err = defaultOpts(config, options)
if err != nil {
return nil, err
Expand Down Expand Up @@ -424,6 +425,21 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
return opts, nil
}

func defaultToInheritedOpts(opts, inherited Options) Options {
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
}

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 2b0d261

Please sign in to comment.