Skip to content

Commit

Permalink
initial SetErrorWatchHandler implementation
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 14, 2023
1 parent 8117577 commit 92f3e22
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/cache/internal/informers.go
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,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
Expand Down

0 comments on commit 92f3e22

Please sign in to comment.