Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ SetErrorWatchHandler on SharedIndexInformer #2494

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
FillZpp marked this conversation as resolved.
Show resolved Hide resolved
}

// 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
troy0820 marked this conversation as resolved.
Show resolved Hide resolved
}

// 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