Skip to content

Commit

Permalink
pass watchErrorHandler through Options struct
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 18, 2023
1 parent 0c894a4 commit 0e607db
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 9 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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,
}),
Expand Down Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions pkg/cache/internal/informers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
}
}

Expand Down

0 comments on commit 0e607db

Please sign in to comment.