Refactor autoscaler.go and static_autoscalar.go to move declaration of the NodeDeletion option to main.go

This commit is contained in:
Damika Gamlath 2023-07-06 11:14:19 +00:00
parent b569db410f
commit 0f8502c623
4 changed files with 11 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/expander" "k8s.io/autoscaler/cluster-autoscaler/expander"
"k8s.io/autoscaler/cluster-autoscaler/expander/factory" "k8s.io/autoscaler/cluster-autoscaler/expander/factory"
ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors" ca_processors "k8s.io/autoscaler/cluster-autoscaler/processors"
"k8s.io/autoscaler/cluster-autoscaler/simulator"
"k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot" "k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot"
"k8s.io/autoscaler/cluster-autoscaler/simulator/predicatechecker" "k8s.io/autoscaler/cluster-autoscaler/simulator/predicatechecker"
"k8s.io/autoscaler/cluster-autoscaler/utils/backoff" "k8s.io/autoscaler/cluster-autoscaler/utils/backoff"
@ -54,6 +55,7 @@ type AutoscalerOptions struct {
DebuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter DebuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
RemainingPdbTracker pdb.RemainingPdbTracker RemainingPdbTracker pdb.RemainingPdbTracker
ScaleUpOrchestrator scaleup.Orchestrator ScaleUpOrchestrator scaleup.Orchestrator
DeleteOptions simulator.NodeDeleteOptions
} }
// Autoscaler is the main component of CA which scales up/down node groups according to its configuration // Autoscaler is the main component of CA which scales up/down node groups according to its configuration
@ -85,7 +87,8 @@ func NewAutoscaler(opts AutoscalerOptions) (Autoscaler, errors.AutoscalerError)
opts.Backoff, opts.Backoff,
opts.DebuggingSnapshotter, opts.DebuggingSnapshotter,
opts.RemainingPdbTracker, opts.RemainingPdbTracker,
opts.ScaleUpOrchestrator), nil opts.ScaleUpOrchestrator,
opts.DeleteOptions), nil
} }
// Initialize default options if not provided. // Initialize default options if not provided.

View File

@ -141,7 +141,8 @@ func NewStaticAutoscaler(
backoff backoff.Backoff, backoff backoff.Backoff,
debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter, debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter,
remainingPdbTracker pdb.RemainingPdbTracker, remainingPdbTracker pdb.RemainingPdbTracker,
scaleUpOrchestrator scaleup.Orchestrator) *StaticAutoscaler { scaleUpOrchestrator scaleup.Orchestrator,
deleteOptions simulator.NodeDeleteOptions) *StaticAutoscaler {
clusterStateConfig := clusterstate.ClusterStateRegistryConfig{ clusterStateConfig := clusterstate.ClusterStateRegistryConfig{
MaxTotalUnreadyPercentage: opts.MaxTotalUnreadyPercentage, MaxTotalUnreadyPercentage: opts.MaxTotalUnreadyPercentage,
@ -166,8 +167,6 @@ func NewStaticAutoscaler(
clusterStateRegistry.RegisterProviders(providers.NewDefaultMaxNodeProvisionTimeProvider(autoscalingContext, processors.NodeGroupConfigProcessor)) clusterStateRegistry.RegisterProviders(providers.NewDefaultMaxNodeProvisionTimeProvider(autoscalingContext, processors.NodeGroupConfigProcessor))
processors.ScaleDownCandidatesNotifier.Register(clusterStateRegistry) processors.ScaleDownCandidatesNotifier.Register(clusterStateRegistry)
deleteOptions := simulator.NewNodeDeleteOptions(opts)
// TODO: Populate the ScaleDownActuator/Planner fields in AutoscalingContext // TODO: Populate the ScaleDownActuator/Planner fields in AutoscalingContext
// during the struct creation rather than here. // during the struct creation rather than here.
ndt := deletiontracker.NewNodeDeletionTracker(0 * time.Second) ndt := deletiontracker.NewNodeDeletionTracker(0 * time.Second)

View File

@ -30,6 +30,7 @@ import (
"time" "time"
"k8s.io/autoscaler/cluster-autoscaler/debuggingsnapshot" "k8s.io/autoscaler/cluster-autoscaler/debuggingsnapshot"
"k8s.io/autoscaler/cluster-autoscaler/simulator"
"k8s.io/autoscaler/cluster-autoscaler/simulator/predicatechecker" "k8s.io/autoscaler/cluster-autoscaler/simulator/predicatechecker"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -404,6 +405,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
if err != nil { if err != nil {
return nil, err return nil, err
} }
deleteOptions := simulator.NewNodeDeleteOptions(autoscalingOptions)
opts := core.AutoscalerOptions{ opts := core.AutoscalerOptions{
AutoscalingOptions: autoscalingOptions, AutoscalingOptions: autoscalingOptions,
@ -412,6 +414,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
EventsKubeClient: eventsKubeClient, EventsKubeClient: eventsKubeClient,
DebuggingSnapshotter: debuggingSnapshotter, DebuggingSnapshotter: debuggingSnapshotter,
PredicateChecker: predicateChecker, PredicateChecker: predicateChecker,
DeleteOptions: deleteOptions,
} }
opts.Processors = ca_processors.DefaultProcessors() opts.Processors = ca_processors.DefaultProcessors()
@ -421,7 +424,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter
if autoscalingOptions.ParallelDrain { if autoscalingOptions.ParallelDrain {
sdCandidatesSorting := previouscandidates.NewPreviousCandidates() sdCandidatesSorting := previouscandidates.NewPreviousCandidates()
scaleDownCandidatesComparers = []scaledowncandidates.CandidatesComparer{ scaleDownCandidatesComparers = []scaledowncandidates.CandidatesComparer{
emptycandidates.NewEmptySortingProcessor(&autoscalingOptions, emptycandidates.NewNodeInfoGetter(opts.ClusterSnapshot)), emptycandidates.NewEmptySortingProcessor(emptycandidates.NewNodeInfoGetter(opts.ClusterSnapshot), deleteOptions),
sdCandidatesSorting, sdCandidatesSorting,
} }
opts.Processors.ScaleDownCandidatesNotifier.Register(sdCandidatesSorting) opts.Processors.ScaleDownCandidatesNotifier.Register(sdCandidatesSorting)

View File

@ -20,7 +20,6 @@ import (
"time" "time"
apiv1 "k8s.io/api/core/v1" apiv1 "k8s.io/api/core/v1"
"k8s.io/autoscaler/cluster-autoscaler/config"
"k8s.io/autoscaler/cluster-autoscaler/simulator" "k8s.io/autoscaler/cluster-autoscaler/simulator"
"k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot" "k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
@ -50,8 +49,7 @@ type EmptySorting struct {
} }
// NewEmptySortingProcessor return EmptySorting struct. // NewEmptySortingProcessor return EmptySorting struct.
func NewEmptySortingProcessor(opts *config.AutoscalingOptions, n nodeInfoGetter) *EmptySorting { func NewEmptySortingProcessor(n nodeInfoGetter, deleteOptions simulator.NodeDeleteOptions) *EmptySorting {
deleteOptions := simulator.NewNodeDeleteOptions(*opts)
return &EmptySorting{n, deleteOptions} return &EmptySorting{n, deleteOptions}
} }