@@ -181,7 +181,6 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
181181 dgCache := cache .New (5 * time .Minute , 30 * time .Second )
182182
183183 newDataGatherer := & DataGathererDynamic {
184- ctx : ctx ,
185184 groupVersionResource : c .GroupVersionResource ,
186185 fieldSelector : fieldSelector .String (),
187186 namespaces : c .IncludeNamespaces ,
@@ -217,7 +216,7 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
217216 newDataGatherer .informer = factory .ForResource (c .GroupVersionResource ).Informer ()
218217 }
219218
220- registration , err := newDataGatherer .informer .AddEventHandler (k8scache.ResourceEventHandlerFuncs {
219+ registration , err := newDataGatherer .informer .AddEventHandlerWithOptions (k8scache.ResourceEventHandlerFuncs {
221220 AddFunc : func (obj interface {}) {
222221 onAdd (log , obj , dgCache )
223222 },
@@ -227,6 +226,8 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
227226 DeleteFunc : func (obj interface {}) {
228227 onDelete (log , obj , dgCache )
229228 },
229+ }, k8scache.HandlerOptions {
230+ Logger : & log ,
230231 })
231232 if err != nil {
232233 return nil , err
@@ -243,7 +244,6 @@ func (c *ConfigDynamic) newDataGathererWithClient(ctx context.Context, cl dynami
243244// This is to allow us to support arbitrary CRDs and resources that Preflight
244245// does not have registered as part of its `runtime.Scheme`.
245246type DataGathererDynamic struct {
246- ctx context.Context
247247 // groupVersionResource is the name of the API group, version and resource
248248 // that should be fetched by this data gatherer.
249249 groupVersionResource schema.GroupVersionResource
@@ -269,8 +269,8 @@ type DataGathererDynamic struct {
269269// Run starts the dynamic data gatherer's informers for resource collection.
270270// Returns error if the data gatherer informer wasn't initialized, Run blocks
271271// 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 )
274274 if g .informer == nil {
275275 return fmt .Errorf ("informer was not initialized, impossible to start" )
276276 }
@@ -288,7 +288,7 @@ func (g *DataGathererDynamic) Run(stopCh <-chan struct{}) error {
288288 }
289289
290290 // start shared informer
291- g .informer .Run ( stopCh )
291+ g .informer .RunWithContext ( ctx )
292292
293293 return nil
294294}
@@ -298,8 +298,9 @@ var ErrCacheSyncTimeout = fmt.Errorf("timed out waiting for Kubernetes cache to
298298// WaitForCacheSync waits for the data gatherer's informers cache to sync before
299299// collecting the resources. Use errors.Is(err, ErrCacheSyncTimeout) to check if
300300// 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 ) {
303304 return ErrCacheSyncTimeout
304305 }
305306
0 commit comments