@@ -194,23 +194,32 @@ func New(config *rest.Config, opts Options) (Cache, error) {
194
194
// returned from cache get/list before mutating it.
195
195
func BuilderWithOptions (options Options ) NewCacheFunc {
196
196
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 )
207
198
if err != nil {
208
199
return nil , err
209
200
}
210
201
return New (config , * combined )
211
202
}
212
203
}
213
204
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
+
214
223
func (options Options ) inheritFrom (inherited Options ) (* Options , error ) {
215
224
var (
216
225
combined Options
@@ -424,6 +433,21 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
424
433
return opts , nil
425
434
}
426
435
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
+
427
451
func convertToByGVK [T any ](byObject map [client.Object ]T , def T , scheme * runtime.Scheme ) (map [schema.GroupVersionKind ]T , error ) {
428
452
byGVK := map [schema.GroupVersionKind ]T {}
429
453
for object , value := range byObject {
0 commit comments