diff --git a/cluster-autoscaler/core/autoscaler.go b/cluster-autoscaler/core/autoscaler.go index 4e540f452028..ea805689aca2 100644 --- a/cluster-autoscaler/core/autoscaler.go +++ b/cluster-autoscaler/core/autoscaler.go @@ -31,6 +31,7 @@ import ( "k8s.io/autoscaler/cluster-autoscaler/expander" "k8s.io/autoscaler/cluster-autoscaler/expander/factory" 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/predicatechecker" "k8s.io/autoscaler/cluster-autoscaler/utils/backoff" @@ -54,6 +55,7 @@ type AutoscalerOptions struct { DebuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter RemainingPdbTracker pdb.RemainingPdbTracker ScaleUpOrchestrator scaleup.Orchestrator + DeleteOptions simulator.NodeDeleteOptions } // 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.DebuggingSnapshotter, opts.RemainingPdbTracker, - opts.ScaleUpOrchestrator), nil + opts.ScaleUpOrchestrator, + opts.DeleteOptions), nil } // Initialize default options if not provided. diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index 0868daa75008..6afc98dfad91 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -141,7 +141,8 @@ func NewStaticAutoscaler( backoff backoff.Backoff, debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter, remainingPdbTracker pdb.RemainingPdbTracker, - scaleUpOrchestrator scaleup.Orchestrator) *StaticAutoscaler { + scaleUpOrchestrator scaleup.Orchestrator, + deleteOptions simulator.NodeDeleteOptions) *StaticAutoscaler { clusterStateConfig := clusterstate.ClusterStateRegistryConfig{ MaxTotalUnreadyPercentage: opts.MaxTotalUnreadyPercentage, @@ -166,8 +167,6 @@ func NewStaticAutoscaler( clusterStateRegistry.RegisterProviders(providers.NewDefaultMaxNodeProvisionTimeProvider(autoscalingContext, processors.NodeGroupConfigProcessor)) processors.ScaleDownCandidatesNotifier.Register(clusterStateRegistry) - deleteOptions := simulator.NewNodeDeleteOptions(opts) - // TODO: Populate the ScaleDownActuator/Planner fields in AutoscalingContext // during the struct creation rather than here. ndt := deletiontracker.NewNodeDeletionTracker(0 * time.Second) diff --git a/cluster-autoscaler/main.go b/cluster-autoscaler/main.go index 073e3fdf1bf3..5f87329f0cb0 100644 --- a/cluster-autoscaler/main.go +++ b/cluster-autoscaler/main.go @@ -30,6 +30,7 @@ import ( "time" "k8s.io/autoscaler/cluster-autoscaler/debuggingsnapshot" + "k8s.io/autoscaler/cluster-autoscaler/simulator" "k8s.io/autoscaler/cluster-autoscaler/simulator/predicatechecker" "github.com/spf13/pflag" @@ -404,6 +405,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter if err != nil { return nil, err } + deleteOptions := simulator.NewNodeDeleteOptions(autoscalingOptions) opts := core.AutoscalerOptions{ AutoscalingOptions: autoscalingOptions, @@ -412,6 +414,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter EventsKubeClient: eventsKubeClient, DebuggingSnapshotter: debuggingSnapshotter, PredicateChecker: predicateChecker, + DeleteOptions: deleteOptions, } opts.Processors = ca_processors.DefaultProcessors() @@ -421,7 +424,7 @@ func buildAutoscaler(debuggingSnapshotter debuggingsnapshot.DebuggingSnapshotter if autoscalingOptions.ParallelDrain { sdCandidatesSorting := previouscandidates.NewPreviousCandidates() scaleDownCandidatesComparers = []scaledowncandidates.CandidatesComparer{ - emptycandidates.NewEmptySortingProcessor(&autoscalingOptions, emptycandidates.NewNodeInfoGetter(opts.ClusterSnapshot)), + emptycandidates.NewEmptySortingProcessor(emptycandidates.NewNodeInfoGetter(opts.ClusterSnapshot), deleteOptions), sdCandidatesSorting, } opts.Processors.ScaleDownCandidatesNotifier.Register(sdCandidatesSorting) diff --git a/cluster-autoscaler/processors/scaledowncandidates/emptycandidates/empty_candidates_sorting.go b/cluster-autoscaler/processors/scaledowncandidates/emptycandidates/empty_candidates_sorting.go index 9f9ce8428660..38dbeec3071a 100644 --- a/cluster-autoscaler/processors/scaledowncandidates/emptycandidates/empty_candidates_sorting.go +++ b/cluster-autoscaler/processors/scaledowncandidates/emptycandidates/empty_candidates_sorting.go @@ -20,7 +20,6 @@ import ( "time" apiv1 "k8s.io/api/core/v1" - "k8s.io/autoscaler/cluster-autoscaler/config" "k8s.io/autoscaler/cluster-autoscaler/simulator" "k8s.io/autoscaler/cluster-autoscaler/simulator/clustersnapshot" schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework" @@ -50,8 +49,7 @@ type EmptySorting struct { } // NewEmptySortingProcessor return EmptySorting struct. -func NewEmptySortingProcessor(opts *config.AutoscalingOptions, n nodeInfoGetter) *EmptySorting { - deleteOptions := simulator.NewNodeDeleteOptions(*opts) +func NewEmptySortingProcessor(n nodeInfoGetter, deleteOptions simulator.NodeDeleteOptions) *EmptySorting { return &EmptySorting{n, deleteOptions} }