Skip to content

Commit

Permalink
[DROP] debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicbozzuto committed Oct 22, 2024
1 parent f33d5c5 commit c1885c0
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions cluster-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"os"
"os/signal"
"reflect"
"strconv"
"strings"
"syscall"
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit c1885c0

Please sign in to comment.