Skip to content

Commit

Permalink
add SetErrorWatchHandler to informers
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
  • Loading branch information
troy0820 committed Sep 15, 2023
1 parent 8117577 commit 0c894a4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/cache/internal/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -76,6 +81,7 @@ func NewInformers(config *rest.Config, options *InformersOpts) *Informers {
transform: options.Transform,
unsafeDisableDeepCopy: options.UnsafeDisableDeepCopy,
newInformer: newInformer,
watchErrorHandler: watchErrorHandler,
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -323,6 +331,11 @@ func (ip *Informers) addInformerToMap(gvk schema.GroupVersionKind, obj runtime.O
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
})

// Set WatchErrorHandler on SharedIndexInformer
if err := sharedIndexInformer.SetWatchErrorHandler(ip.watchErrorHandler); 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
Expand Down

0 comments on commit 0c894a4

Please sign in to comment.