From c1885c0e6c69a781d9e34a2dfe7e9dca5047babb Mon Sep 17 00:00:00 2001 From: "dom.bozzuto" Date: Mon, 21 Oct 2024 15:45:04 -0400 Subject: [PATCH] [DROP] debugging --- cluster-autoscaler/main.go | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/cluster-autoscaler/main.go b/cluster-autoscaler/main.go index 8d7c23914e77..aa19f576a524 100644 --- a/cluster-autoscaler/main.go +++ b/cluster-autoscaler/main.go @@ -23,6 +23,7 @@ import ( "net/http" "os" "os/signal" + "reflect" "strconv" "strings" "syscall" @@ -611,12 +612,41 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter klog.V(1).Info("Started shared informer factory, waiting for initial cache sync") syncStart := time.Now() - informerFactory.WaitForCacheSync(stop) + allSynced := false + for !allSynced { + syncStatus := waitForCacheSyncWithTimeout(informerFactory, time.Second*10) + currentAllSynced := true + for _, synced := range syncStatus { + currentAllSynced = currentAllSynced && synced + } + allSynced = currentAllSynced + } klog.V(1).Infof("Shared informer factory initialized, took %v", time.Since(syncStart)) - return autoscaler, nil } +func waitForCacheSyncWithTimeout(informerFactory informers.SharedInformerFactory, timeout time.Duration) map[reflect.Type]bool { + stopCh := make(chan struct{}) + defer close(stopCh) + + doneCh := make(chan map[reflect.Type]bool) + go func() { + syncStatus := informerFactory.WaitForCacheSync(stopCh) + doneCh <- syncStatus + }() + + for { + select { + // WaitForCacheSync has returned; return the resulting status + case syncStatus := <-doneCh: + return syncStatus + // The timeout has expired, signal the stop channel and then read the result from the done channel + case <-time.After(timeout): + stopCh <- struct{}{} + } + } +} + func run(healthCheck *metrics.HealthCheck, debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter) { metrics.RegisterAll(*emitPerNodeGroupMetrics)