Skip to content

Commit eccc58d

Browse files
committed
Update the cluster connection interval as configurable
Signed-off-by: Chetan Banavikalmutt <[email protected]>
1 parent cdf4bda commit eccc58d

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

pkg/cache/cluster.go

+18-12
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const (
5757
// Limit is required to avoid memory spikes during cache initialization.
5858
// The default limit of 50 is chosen based on experiments.
5959
defaultListSemaphoreWeight = 50
60+
61+
// The default interval for monitoring the cluster connection status.
62+
defaultClusterConnectionInterval = 10 * time.Second
6063
)
6164

6265
const (
@@ -166,16 +169,17 @@ func NewClusterCache(config *rest.Config, opts ...UpdateSettingsFunc) *clusterCa
166169
resyncTimeout: defaultClusterResyncTimeout,
167170
syncTime: nil,
168171
},
169-
watchResyncTimeout: defaultWatchResyncTimeout,
170-
clusterSyncRetryTimeout: ClusterRetryTimeout,
171-
resourceUpdatedHandlers: map[uint64]OnResourceUpdatedHandler{},
172-
eventHandlers: map[uint64]OnEventHandler{},
173-
log: log,
174-
listRetryLimit: 1,
175-
listRetryUseBackoff: false,
176-
listRetryFunc: ListRetryFuncNever,
177-
connectionStatus: ConnectionStatusUnknown,
178-
watchFails: newWatchFailures(),
172+
watchResyncTimeout: defaultWatchResyncTimeout,
173+
clusterSyncRetryTimeout: ClusterRetryTimeout,
174+
resourceUpdatedHandlers: map[uint64]OnResourceUpdatedHandler{},
175+
eventHandlers: map[uint64]OnEventHandler{},
176+
log: log,
177+
listRetryLimit: 1,
178+
listRetryUseBackoff: false,
179+
listRetryFunc: ListRetryFuncNever,
180+
connectionStatus: ConnectionStatusUnknown,
181+
watchFails: newWatchFailures(),
182+
clusterConnectionInterval: defaultClusterConnectionInterval,
179183
}
180184
for i := range opts {
181185
opts[i](cache)
@@ -198,6 +202,9 @@ type clusterCache struct {
198202
// connectionStatus indicates the status of the connection with the cluster.
199203
connectionStatus ConnectionStatus
200204

205+
// clusterConnectionInterval is the interval used to monitor the cluster connection status.
206+
clusterConnectionInterval time.Duration
207+
201208
// watchFails is used to keep track of the failures while watching resources.
202209
watchFails *watchFailures
203210

@@ -1240,8 +1247,7 @@ func (c *clusterCache) StartClusterConnectionStatusMonitoring(ctx context.Contex
12401247
}
12411248

12421249
func (c *clusterCache) clusterConnectionService(ctx context.Context) {
1243-
clusterConnectionTimeout := 10 * time.Second
1244-
ticker := time.NewTicker(clusterConnectionTimeout)
1250+
ticker := time.NewTicker(c.clusterConnectionInterval)
12451251
defer ticker.Stop()
12461252

12471253
for {

pkg/cache/settings.go

+7
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,10 @@ func SetRespectRBAC(respectRBAC int) UpdateSettingsFunc {
170170
}
171171
}
172172
}
173+
174+
// SetClusterConnectionInterval sets the interval for monitoring the cluster connection status.
175+
func SetClusterConnectionInterval(interval time.Duration) UpdateSettingsFunc {
176+
return func(cache *clusterCache) {
177+
cache.clusterConnectionInterval = interval
178+
}
179+
}

0 commit comments

Comments
 (0)