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 6e1f445
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cluster-autoscaler/core/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package core

import (
kube_util "k8s.io/autoscaler/cluster-autoscaler/utils/kubernetes"
"strings"
"time"

Expand Down Expand Up @@ -76,6 +77,8 @@ type Autoscaler interface {
LastScaleUpTime() time.Time
// LastScaleUpTime is a time of the last scale down
LastScaleDownDeleteTime() time.Time

GetListerRegistry() kube_util.ListerRegistry
}

// NewAutoscaler creates an autoscaler of an appropriate type according to the parameters
Expand Down
4 changes: 4 additions & 0 deletions cluster-autoscaler/core/static_autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ type StaticAutoscaler struct {
taintConfig taints.TaintConfig
}

func (a *StaticAutoscaler) GetListerRegistry() kube_util.ListerRegistry {
return a.ListerRegistry
}

type staticAutoscalerProcessorCallbacks struct {
disableScaleDownForLoop bool
extraValues map[string]interface{}
Expand Down
37 changes: 35 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 @@ -608,15 +609,47 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
// additional informers might have been registered in the factory during NewAutoscaler.
stop := make(chan struct{})
informerFactory.Start(stop)
p, err := autoscaler.GetListerRegistry().AllPodLister().List()
klog.V(1).Infof("Initial list call: %v (%v)", p, err)

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 6e1f445

Please sign in to comment.