Skip to content

Commit 6edd6e8

Browse files
committed
use until to update cache
1 parent 6fb5e32 commit 6edd6e8

File tree

1 file changed

+7
-10
lines changed
  • pkg/controller/clusterstate/cache

1 file changed

+7
-10
lines changed

pkg/controller/clusterstate/cache/cache.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ import (
4848
"k8s.io/klog/v2"
4949

5050
"github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/controller/clusterstate/api"
51+
"k8s.io/apimachinery/pkg/util/wait"
5152
)
5253

53-
// New returns a Cache implementation.
54+
//New returns a Cache implementation.
5455
func New(config *rest.Config) Cache {
5556
return newClusterStateCache(config)
5657
}
@@ -101,7 +102,7 @@ func (sc *ClusterStateCache) Run(stopCh <-chan struct{}) {
101102
go sc.nodeInformer.Informer().Run(stopCh)
102103

103104
// Update cache
104-
go sc.updateCache()
105+
go wait.Until(sc.updateCache, 1*time.Second, stopCh)
105106

106107
}
107108

@@ -243,15 +244,11 @@ func (sc *ClusterStateCache) updateState() error {
243244

244245
func (sc *ClusterStateCache) updateCache() {
245246
klog.V(9).Infof("Starting to update Cluster State Cache")
246-
247-
for {
248-
err := sc.updateState()
249-
if err != nil {
250-
klog.Errorf("Failed update state: %v", err)
251-
}
252-
253-
time.Sleep(1 * time.Second)
247+
err := sc.updateState()
248+
if err != nil {
249+
klog.Errorf("Failed update state: %v", err)
254250
}
251+
return
255252
}
256253

257254
func (sc *ClusterStateCache) Snapshot() *api.ClusterInfo {

0 commit comments

Comments
 (0)