@@ -181,7 +181,6 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
181
181
dgCache := cache .New (5 * time .Minute , 30 * time .Second )
182
182
183
183
newDataGatherer := & DataGathererDynamic {
184
- ctx : ctx ,
185
184
groupVersionResource : c .GroupVersionResource ,
186
185
fieldSelector : fieldSelector .String (),
187
186
namespaces : c .IncludeNamespaces ,
@@ -217,7 +216,7 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
217
216
newDataGatherer .informer = factory .ForResource (c .GroupVersionResource ).Informer ()
218
217
}
219
218
220
- registration , err := newDataGatherer .informer .AddEventHandler (k8scache.ResourceEventHandlerFuncs {
219
+ registration , err := newDataGatherer .informer .AddEventHandlerWithOptions (k8scache.ResourceEventHandlerFuncs {
221
220
AddFunc : func (obj interface {}) {
222
221
onAdd (log , obj , dgCache )
223
222
},
@@ -227,6 +226,8 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
227
226
DeleteFunc : func (obj interface {}) {
228
227
onDelete (log , obj , dgCache )
229
228
},
229
+ }, k8scache.HandlerOptions {
230
+ Logger : & log ,
230
231
})
231
232
if err != nil {
232
233
return nil , err
@@ -243,7 +244,6 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
243
244
// This is to allow us to support arbitrary CRDs and resources that Preflight
244
245
// does not have registered as part of its `runtime.Scheme`.
245
246
type DataGathererDynamic struct {
246
- ctx context.Context
247
247
// groupVersionResource is the name of the API group, version and resource
248
248
// that should be fetched by this data gatherer.
249
249
groupVersionResource schema.GroupVersionResource
@@ -269,8 +269,8 @@ type DataGathererDynamic struct {
269
269
// Run starts the dynamic data gatherer's informers for resource collection.
270
270
// Returns error if the data gatherer informer wasn't initialized, Run blocks
271
271
// until the stopCh is closed.
272
- func (g * DataGathererDynamic ) Run (stopCh <- chan struct {} ) error {
273
- log := klog .FromContext (g . ctx )
272
+ func (g * DataGathererDynamic ) Run (ctx context. Context ) error {
273
+ log := klog .FromContext (ctx )
274
274
if g .informer == nil {
275
275
return fmt .Errorf ("informer was not initialized, impossible to start" )
276
276
}
@@ -288,7 +288,7 @@ func (g *DataGathererDynamic) Run(stopCh <-chan struct{}) error {
288
288
}
289
289
290
290
// start shared informer
291
- g .informer .Run ( stopCh )
291
+ g .informer .RunWithContext ( ctx )
292
292
293
293
return nil
294
294
}
@@ -298,8 +298,9 @@ var ErrCacheSyncTimeout = fmt.Errorf("timed out waiting for Kubernetes cache to
298
298
// WaitForCacheSync waits for the data gatherer's informers cache to sync before
299
299
// collecting the resources. Use errors.Is(err, ErrCacheSyncTimeout) to check if
300
300
// the cache sync failed.
301
- func (g * DataGathererDynamic ) WaitForCacheSync (stopCh <- chan struct {}) error {
302
- if ! k8scache .WaitForCacheSync (stopCh , g .registration .HasSynced ) {
301
+ func (g * DataGathererDynamic ) WaitForCacheSync (ctx context.Context ) error {
302
+ // Don't use WaitForNamedCacheSync, since we don't want to log extra messages.
303
+ if ! k8scache .WaitForCacheSync (ctx .Done (), g .registration .HasSynced ) {
303
304
return ErrCacheSyncTimeout
304
305
}
305
306
0 commit comments