diff --git a/pkg/cache/internal/informers.go b/pkg/cache/internal/informers.go index 1d2c9ce2b4..16a2eea924 100644 --- a/pkg/cache/internal/informers.go +++ b/pkg/cache/internal/informers.go @@ -49,14 +49,19 @@ type InformersOpts struct { Selector Selector Transform cache.TransformFunc UnsafeDisableDeepCopy bool + WatchErrorHandler cache.WatchErrorHandler } // NewInformers creates a new InformersMap that can create informers under the hood. func NewInformers(config *rest.Config, options *InformersOpts) *Informers { newInformer := cache.NewSharedIndexInformer + watchErrorHandler := cache.DefaultWatchErrorHandler if options.NewInformer != nil { newInformer = *options.NewInformer } + if options.WatchErrorHandler != nil { + watchErrorHandler = options.WatchErrorHandler + } return &Informers{ config: config, httpClient: options.HTTPClient, @@ -76,6 +81,7 @@ func NewInformers(config *rest.Config, options *InformersOpts) *Informers { transform: options.Transform, unsafeDisableDeepCopy: options.UnsafeDisableDeepCopy, newInformer: newInformer, + watchErrorHandler: watchErrorHandler, } } @@ -159,6 +165,8 @@ type Informers struct { // NewInformer allows overriding of the shared index informer constructor for testing. newInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer + + watchErrorHandler cache.WatchErrorHandler } // Start calls Run on each of the informers and sets started to true. Blocks on the context. @@ -323,6 +331,12 @@ func (ip *Informers) addInformerToMap(gvk schema.GroupVersionKind, obj runtime.O cache.NamespaceIndex: cache.MetaNamespaceIndexFunc, }) + // Set WatchErrorHandler on SharedIndexInformer + err = sharedIndexInformer.SetWatchErrorHandler(ip.watchErrorHandler) + if err != nil { + return nil, false, err + } + // Check to see if there is a transformer for this gvk if err := sharedIndexInformer.SetTransform(ip.transform); err != nil { return nil, false, err