Skip to content

Commit

Permalink
Update the cluster connection interval as configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <[email protected]>
  • Loading branch information
chetan-rns committed Apr 4, 2024
1 parent cdf4bda commit eccc58d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
30 changes: 18 additions & 12 deletions pkg/cache/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -1240,8 +1247,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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/cache/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit eccc58d

Please sign in to comment.