Skip to content

Commit f236f03

Browse files
authored
Merge pull request #1743 from alvaroaleman/fix-passing
🐛 Correctly pass cache options on
2 parents 5a24475 + 558ef2e commit f236f03

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

pkg/cache/cache.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,23 @@ func New(config *rest.Config, opts Options) (Cache, error) {
159159
// returned from cache get/list before mutating it.
160160
func BuilderWithOptions(options Options) NewCacheFunc {
161161
return func(config *rest.Config, opts Options) (Cache, error) {
162-
if opts.Scheme == nil {
163-
opts.Scheme = options.Scheme
162+
if options.Scheme == nil {
163+
options.Scheme = opts.Scheme
164164
}
165-
if opts.Mapper == nil {
166-
opts.Mapper = options.Mapper
165+
if options.Mapper == nil {
166+
options.Mapper = opts.Mapper
167+
}
168+
if options.Resync == nil {
169+
options.Resync = opts.Resync
170+
}
171+
if options.Namespace == "" {
172+
options.Namespace = opts.Namespace
167173
}
168174
if opts.Resync == nil {
169175
opts.Resync = options.Resync
170176
}
171-
if opts.Namespace == "" {
172-
opts.Namespace = options.Namespace
173-
}
174-
opts.SelectorsByObject = options.SelectorsByObject
175-
opts.UnsafeDisableDeepCopyByObject = options.UnsafeDisableDeepCopyByObject
176-
return New(config, opts)
177+
178+
return New(config, options)
177179
}
178180
}
179181

pkg/cache/internal/informers_map.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func newSpecificInformersMap(config *rest.Config,
6666
startWait: make(chan struct{}),
6767
createListWatcher: createListWatcher,
6868
namespace: namespace,
69-
selectors: selectors,
69+
selectors: selectors.forGVK,
7070
disableDeepCopy: disableDeepCopy,
7171
}
7272
return ip
@@ -131,7 +131,7 @@ type specificInformersMap struct {
131131

132132
// selectors are the label or field selectors that will be added to the
133133
// ListWatch ListOptions.
134-
selectors SelectorsByGVK
134+
selectors func(gvk schema.GroupVersionKind) Selector
135135

136136
// disableDeepCopy indicates not to deep copy objects during get or list objects.
137137
disableDeepCopy DisableDeepCopyByGVK
@@ -277,19 +277,19 @@ func createStructuredListWatch(gvk schema.GroupVersionKind, ip *specificInformer
277277
// Create a new ListWatch for the obj
278278
return &cache.ListWatch{
279279
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
280-
ip.selectors.forGVK(gvk).ApplyToList(&opts)
280+
ip.selectors(gvk).ApplyToList(&opts)
281281
res := listObj.DeepCopyObject()
282-
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors.forGVK(gvk))
282+
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors(gvk))
283283
isNamespaceScoped := namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameRoot
284284
err := client.Get().NamespaceIfScoped(namespace, isNamespaceScoped).Resource(mapping.Resource.Resource).VersionedParams(&opts, ip.paramCodec).Do(ctx).Into(res)
285285
return res, err
286286
},
287287
// Setup the watch function
288288
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
289-
ip.selectors.forGVK(gvk).ApplyToList(&opts)
289+
ip.selectors(gvk).ApplyToList(&opts)
290290
// Watch needs to be set to true separately
291291
opts.Watch = true
292-
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors.forGVK(gvk))
292+
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors(gvk))
293293
isNamespaceScoped := namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameRoot
294294
return client.Get().NamespaceIfScoped(namespace, isNamespaceScoped).Resource(mapping.Resource.Resource).VersionedParams(&opts, ip.paramCodec).Watch(ctx)
295295
},
@@ -319,19 +319,19 @@ func createUnstructuredListWatch(gvk schema.GroupVersionKind, ip *specificInform
319319
// Create a new ListWatch for the obj
320320
return &cache.ListWatch{
321321
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
322-
ip.selectors[gvk].ApplyToList(&opts)
323-
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors[gvk])
322+
ip.selectors(gvk).ApplyToList(&opts)
323+
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors(gvk))
324324
if namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameRoot {
325325
return dynamicClient.Resource(mapping.Resource).Namespace(namespace).List(ctx, opts)
326326
}
327327
return dynamicClient.Resource(mapping.Resource).List(ctx, opts)
328328
},
329329
// Setup the watch function
330330
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
331-
ip.selectors[gvk].ApplyToList(&opts)
331+
ip.selectors(gvk).ApplyToList(&opts)
332332
// Watch needs to be set to true separately
333333
opts.Watch = true
334-
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors[gvk])
334+
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors(gvk))
335335
if namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameRoot {
336336
return dynamicClient.Resource(mapping.Resource).Namespace(namespace).Watch(ctx, opts)
337337
}
@@ -366,13 +366,13 @@ func createMetadataListWatch(gvk schema.GroupVersionKind, ip *specificInformersM
366366
// create the relevant listwatch
367367
return &cache.ListWatch{
368368
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
369-
ip.selectors[gvk].ApplyToList(&opts)
369+
ip.selectors(gvk).ApplyToList(&opts)
370370

371371
var (
372372
list *metav1.PartialObjectMetadataList
373373
err error
374374
)
375-
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors[gvk])
375+
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors(gvk))
376376
if namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameRoot {
377377
list, err = client.Resource(mapping.Resource).Namespace(namespace).List(ctx, opts)
378378
} else {
@@ -387,15 +387,15 @@ func createMetadataListWatch(gvk schema.GroupVersionKind, ip *specificInformersM
387387
},
388388
// Setup the watch function
389389
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
390-
ip.selectors[gvk].ApplyToList(&opts)
390+
ip.selectors(gvk).ApplyToList(&opts)
391391
// Watch needs to be set to true separately
392392
opts.Watch = true
393393

394394
var (
395395
watcher watch.Interface
396396
err error
397397
)
398-
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors[gvk])
398+
namespace := restrictNamespaceBySelector(ip.namespace, ip.selectors(gvk))
399399
if namespace != "" && mapping.Scope.Name() != meta.RESTScopeNameRoot {
400400
watcher, err = client.Resource(mapping.Resource).Namespace(namespace).Watch(ctx, opts)
401401
} else {

0 commit comments

Comments
 (0)