Skip to content

Commit 92f3e22

Browse files
committed
initial SetErrorWatchHandler implementation
Signed-off-by: Troy Connor <troy0820@users.noreply.github.com>
1 parent 8117577 commit 92f3e22

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/cache/internal/informers.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,19 @@ type InformersOpts struct {
4949
Selector Selector
5050
Transform cache.TransformFunc
5151
UnsafeDisableDeepCopy bool
52+
WatchErrorHandler cache.WatchErrorHandler
5253
}
5354

5455
// NewInformers creates a new InformersMap that can create informers under the hood.
5556
func NewInformers(config *rest.Config, options *InformersOpts) *Informers {
5657
newInformer := cache.NewSharedIndexInformer
58+
watchErrorHandler := cache.DefaultWatchErrorHandler
5759
if options.NewInformer != nil {
5860
newInformer = *options.NewInformer
5961
}
62+
if options.WatchErrorHandler != nil {
63+
watchErrorHandler = options.WatchErrorHandler
64+
}
6065
return &Informers{
6166
config: config,
6267
httpClient: options.HTTPClient,
@@ -76,6 +81,7 @@ func NewInformers(config *rest.Config, options *InformersOpts) *Informers {
7681
transform: options.Transform,
7782
unsafeDisableDeepCopy: options.UnsafeDisableDeepCopy,
7883
newInformer: newInformer,
84+
watchErrorHandler: watchErrorHandler,
7985
}
8086
}
8187

@@ -159,6 +165,8 @@ type Informers struct {
159165

160166
// NewInformer allows overriding of the shared index informer constructor for testing.
161167
newInformer func(cache.ListerWatcher, runtime.Object, time.Duration, cache.Indexers) cache.SharedIndexInformer
168+
169+
watchErrorHandler cache.WatchErrorHandler
162170
}
163171

164172
// 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
323331
cache.NamespaceIndex: cache.MetaNamespaceIndexFunc,
324332
})
325333

334+
// Set WatchErrorHandler on SharedIndexInformer
335+
err = sharedIndexInformer.SetWatchErrorHandler(ip.watchErrorHandler)
336+
if err != nil {
337+
return nil, false, err
338+
}
339+
326340
// Check to see if there is a transformer for this gvk
327341
if err := sharedIndexInformer.SetTransform(ip.transform); err != nil {
328342
return nil, false, err

0 commit comments

Comments
 (0)