@@ -46,7 +46,7 @@ type informer struct {
46
46
numWorkers int
47
47
}
48
48
49
- func NewInformer (resourcePluralName , namespace string , resourceClient dynamic.ResourceInterface , resyncPeriod int , c * metrics.Collector , n int ) Informer {
49
+ func NewInformer (resourcePluralName , namespace string , resourceClient dynamic.ResourceInterface , resyncPeriod int , c * metrics.Collector , n int , labelSelector string ) Informer {
50
50
i := & informer {
51
51
resourcePluralName : resourcePluralName ,
52
52
queue : workqueue .NewNamedRateLimitingQueue (workqueue .DefaultControllerRateLimiter (), resourcePluralName ),
@@ -58,7 +58,7 @@ func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.Re
58
58
59
59
resyncDuration := time .Duration (resyncPeriod ) * time .Second
60
60
i .sharedIndexInformer = cache .NewSharedIndexInformer (
61
- newListWatcherFromResourceClient (resourceClient ), & unstructured.Unstructured {}, resyncDuration , cache.Indexers {},
61
+ newListWatcherFromResourceClient (resourceClient , labelSelector ), & unstructured.Unstructured {}, resyncDuration , cache.Indexers {},
62
62
)
63
63
i .sharedIndexInformer .AddEventHandler (cache.ResourceEventHandlerFuncs {
64
64
AddFunc : i .handleAddResourceEvent ,
@@ -68,11 +68,17 @@ func NewInformer(resourcePluralName, namespace string, resourceClient dynamic.Re
68
68
return i
69
69
}
70
70
71
- func newListWatcherFromResourceClient (resourceClient dynamic.ResourceInterface ) * cache.ListWatch {
71
+ func newListWatcherFromResourceClient (resourceClient dynamic.ResourceInterface , labelSelector string ) * cache.ListWatch {
72
72
listFunc := func (options metav1.ListOptions ) (runtime.Object , error ) {
73
+ if labelSelector != "" {
74
+ options .LabelSelector = labelSelector
75
+ }
73
76
return resourceClient .List (options )
74
77
}
75
78
watchFunc := func (options metav1.ListOptions ) (watch.Interface , error ) {
79
+ if labelSelector != "" {
80
+ options .LabelSelector = labelSelector
81
+ }
76
82
return resourceClient .Watch (options )
77
83
}
78
84
return & cache.ListWatch {ListFunc : listFunc , WatchFunc : watchFunc }
0 commit comments