Skip to content

Commit 532e636

Browse files
committed
use context while updating cluster status
Signed-off-by: Chetan Banavikalmutt <[email protected]>
1 parent d35d7b1 commit 532e636

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

pkg/cache/cluster.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ type ClusterCache interface {
135135
// OnEvent register event handler that is executed every time when new K8S event received
136136
OnEvent(handler OnEventHandler) Unsubscribe
137137
// UpdateClusterConnectionStatus checks the watch errors periodically and updates the cluster connection status.
138-
UpdateClusterConnectionStatus()
138+
UpdateClusterConnectionStatus(ctx context.Context)
139139
}
140140

141141
type WeightedSemaphore interface {
@@ -1234,11 +1234,11 @@ func skipAppRequeuing(key kube.ResourceKey) bool {
12341234
// UpdateClusterConnectionStatus starts a goroutine that checks for watch failures.
12351235
// If there are any watch errors, it will periodically ping the remote cluster
12361236
// and update the cluster connection status.
1237-
func (c *clusterCache) UpdateClusterConnectionStatus() {
1238-
go c.clusterConnectionService()
1237+
func (c *clusterCache) UpdateClusterConnectionStatus(ctx context.Context) {
1238+
go c.clusterConnectionService(ctx)
12391239
}
12401240

1241-
func (c *clusterCache) clusterConnectionService() {
1241+
func (c *clusterCache) clusterConnectionService(ctx context.Context) {
12421242
clusterConnectionTimeout := 10 * time.Second
12431243
ticker := time.NewTicker(clusterConnectionTimeout)
12441244
defer ticker.Stop()
@@ -1261,6 +1261,9 @@ func (c *clusterCache) clusterConnectionService() {
12611261
c.updateConnectionStatus(ConnectionStatusSuccessful)
12621262
}
12631263
}
1264+
case <-ctx.Done():
1265+
ticker.Stop()
1266+
return
12641267
}
12651268
}
12661269

pkg/cache/mocks/ClusterCache.go

+6-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)