From 0e607db973c8815d254919cd3dbe84e2bf20b92f Mon Sep 17 00:00:00 2001 From: Troy Connor Date: Mon, 18 Sep 2023 10:02:29 -0400 Subject: [PATCH] pass watchErrorHandler through Options struct Signed-off-by: Troy Connor --- pkg/cache/cache.go | 9 +++++++++ pkg/cache/internal/informers.go | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index d8446e85b3..e91444bce9 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -188,6 +188,11 @@ type Options struct { // unless there is already one set in ByObject or DefaultNamespaces. DefaultTransform toolscache.TransformFunc + // DefaultWatchErrorHandler will be used to the WatchErrorHandler which is called + // whenever ListAndWatch drops the connection with an error. After calling this handler, + // the informer will backoff and retry. + DefaultWatchErrorHandler toolscache.WatchErrorHandler + // DefaultUnsafeDisableDeepCopy is the default for UnsafeDisableDeepCopy // for everything that doesn't specify this. // @@ -353,6 +358,7 @@ func newCache(restConfig *rest.Config, opts Options) newCacheFunc { Field: config.FieldSelector, }, Transform: config.Transform, + WatchErrorHandler: opts.DefaultWatchErrorHandler, UnsafeDisableDeepCopy: pointer.BoolDeref(config.UnsafeDisableDeepCopy, false), NewInformer: opts.newInformer, }), @@ -381,6 +387,9 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) { opts.Scheme = scheme.Scheme } + if opts.DefaultWatchErrorHandler == nil { + opts.DefaultWatchErrorHandler = toolscache.DefaultWatchErrorHandler + } // Construct a new Mapper if unset if opts.Mapper == nil { var err error diff --git a/pkg/cache/internal/informers.go b/pkg/cache/internal/informers.go index ac9ee3f36e..eeba40ad85 100644 --- a/pkg/cache/internal/informers.go +++ b/pkg/cache/internal/informers.go @@ -55,13 +55,9 @@ type InformersOpts struct { // 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, @@ -81,7 +77,7 @@ func NewInformers(config *rest.Config, options *InformersOpts) *Informers { transform: options.Transform, unsafeDisableDeepCopy: options.UnsafeDisableDeepCopy, newInformer: newInformer, - watchErrorHandler: watchErrorHandler, + watchErrorHandler: options.WatchErrorHandler, } }