@@ -194,23 +194,32 @@ func New(config *rest.Config, opts Options) (Cache, error) {
194194// returned from cache get/list before mutating it.
195195func BuilderWithOptions (options Options ) NewCacheFunc {
196196 return func (config * rest.Config , inherited Options ) (Cache , error ) {
197- var err error
198- inherited , err = defaultOpts (config , inherited )
199- if err != nil {
200- return nil , err
201- }
202- options , err = defaultOpts (config , options )
203- if err != nil {
204- return nil , err
205- }
206- combined , err := options .inheritFrom (inherited )
197+ combined , err := options .combinedOpts (config , inherited )
207198 if err != nil {
208199 return nil , err
209200 }
210201 return New (config , * combined )
211202 }
212203}
213204
205+ func (options Options ) combinedOpts (config * rest.Config , inherited Options ) (* Options , error ) {
206+ var err error
207+ inherited , err = defaultOpts (config , inherited )
208+ if err != nil {
209+ return nil , err
210+ }
211+ options = defaultToInheritedOpts (options , inherited )
212+ options , err = defaultOpts (config , options )
213+ if err != nil {
214+ return nil , err
215+ }
216+ combined , err := options .inheritFrom (inherited )
217+ if err != nil {
218+ return nil , err
219+ }
220+ return combined , nil
221+ }
222+
214223func (options Options ) inheritFrom (inherited Options ) (* Options , error ) {
215224 var (
216225 combined Options
@@ -424,6 +433,21 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
424433 return opts , nil
425434}
426435
436+ func defaultToInheritedOpts (opts , inherited Options ) Options {
437+ if opts .Scheme == nil {
438+ opts .Scheme = inherited .Scheme
439+ }
440+
441+ if opts .Mapper == nil {
442+ opts .Mapper = inherited .Mapper
443+ }
444+
445+ if opts .Resync == nil {
446+ opts .Resync = inherited .Resync
447+ }
448+ return opts
449+ }
450+
427451func convertToByGVK [T any ](byObject map [client.Object ]T , def T , scheme * runtime.Scheme ) (map [schema.GroupVersionKind ]T , error ) {
428452 byGVK := map [schema.GroupVersionKind ]T {}
429453 for object , value := range byObject {
0 commit comments