diff --git a/pkg/cache/cluster.go b/pkg/cache/cluster.go index 1ca6fc717..cf6942585 100644 --- a/pkg/cache/cluster.go +++ b/pkg/cache/cluster.go @@ -57,6 +57,9 @@ const ( // Limit is required to avoid memory spikes during cache initialization. // The default limit of 50 is chosen based on experiments. defaultListSemaphoreWeight = 50 + + // The default interval for monitoring the cluster connection status. + defaultClusterConnectionInterval = 10 * time.Second ) const ( @@ -166,16 +169,17 @@ func NewClusterCache(config *rest.Config, opts ...UpdateSettingsFunc) *clusterCa resyncTimeout: defaultClusterResyncTimeout, syncTime: nil, }, - watchResyncTimeout: defaultWatchResyncTimeout, - clusterSyncRetryTimeout: ClusterRetryTimeout, - resourceUpdatedHandlers: map[uint64]OnResourceUpdatedHandler{}, - eventHandlers: map[uint64]OnEventHandler{}, - log: log, - listRetryLimit: 1, - listRetryUseBackoff: false, - listRetryFunc: ListRetryFuncNever, - connectionStatus: ConnectionStatusUnknown, - watchFails: newWatchFailures(), + watchResyncTimeout: defaultWatchResyncTimeout, + clusterSyncRetryTimeout: ClusterRetryTimeout, + resourceUpdatedHandlers: map[uint64]OnResourceUpdatedHandler{}, + eventHandlers: map[uint64]OnEventHandler{}, + log: log, + listRetryLimit: 1, + listRetryUseBackoff: false, + listRetryFunc: ListRetryFuncNever, + connectionStatus: ConnectionStatusUnknown, + watchFails: newWatchFailures(), + clusterConnectionInterval: defaultClusterConnectionInterval, } for i := range opts { opts[i](cache) @@ -198,6 +202,9 @@ type clusterCache struct { // connectionStatus indicates the status of the connection with the cluster. connectionStatus ConnectionStatus + // clusterConnectionInterval is the interval used to monitor the cluster connection status. + clusterConnectionInterval time.Duration + // watchFails is used to keep track of the failures while watching resources. watchFails *watchFailures @@ -1239,8 +1246,7 @@ func (c *clusterCache) StartClusterConnectionStatusMonitoring(ctx context.Contex } func (c *clusterCache) clusterConnectionService(ctx context.Context) { - clusterConnectionTimeout := 10 * time.Second - ticker := time.NewTicker(clusterConnectionTimeout) + ticker := time.NewTicker(c.clusterConnectionInterval) defer ticker.Stop() for { diff --git a/pkg/cache/settings.go b/pkg/cache/settings.go index a7194d0ca..f3546a535 100644 --- a/pkg/cache/settings.go +++ b/pkg/cache/settings.go @@ -170,3 +170,10 @@ func SetRespectRBAC(respectRBAC int) UpdateSettingsFunc { } } } + +// SetClusterConnectionInterval sets the interval for monitoring the cluster connection status. +func SetClusterConnectionInterval(interval time.Duration) UpdateSettingsFunc { + return func(cache *clusterCache) { + cache.clusterConnectionInterval = interval + } +}