diff --git a/cluster-autoscaler/context/autoscaling_context.go b/cluster-autoscaler/context/autoscaling_context.go index fb9e53c66f55..9ccd07cb8f60 100644 --- a/cluster-autoscaler/context/autoscaling_context.go +++ b/cluster-autoscaler/context/autoscaling_context.go @@ -61,6 +61,8 @@ type AutoscalingContext struct { RemainingPdbTracker pdb.RemainingPdbTracker // ClusterStateRegistry tracks the health of the node groups and pending scale-ups and scale-downs ClusterStateRegistry *clusterstate.ClusterStateRegistry + //ProvisionRequstScaleUpMode indicates whether ClusterAutoscaler tries to accommodate ProvisioningRequest in current scale up iteration. + ProvisioningRequstScaleUpMode bool } // AutoscalingKubeClients contains all Kubernetes API clients, diff --git a/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator.go b/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator.go index 07a902b2e54b..4d723a9a4cc0 100644 --- a/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator.go +++ b/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator.go @@ -36,8 +36,7 @@ import ( // Each loop WrapperOrchestrator split out regular and pods from ProvisioningRequest, pick one group that // wasn't picked in the last loop and run ScaleUp for it. type WrapperOrchestrator struct { - // scaleUpRegularPods indicates that ScaleUp for regular pods will be run in the current CA loop, if they are present. - scaleUpRegularPods bool + autoscalingContext *context.AutoscalingContext podsOrchestrator scaleup.Orchestrator provReqOrchestrator scaleup.Orchestrator } @@ -58,6 +57,7 @@ func (o *WrapperOrchestrator) Initialize( estimatorBuilder estimator.EstimatorBuilder, taintConfig taints.TaintConfig, ) { + o.autoscalingContext = autoscalingContext o.podsOrchestrator.Initialize(autoscalingContext, processors, clusterStateRegistry, estimatorBuilder, taintConfig) o.provReqOrchestrator.Initialize(autoscalingContext, processors, clusterStateRegistry, estimatorBuilder, taintConfig) } @@ -70,19 +70,21 @@ func (o *WrapperOrchestrator) ScaleUp( nodeInfos map[string]*schedulerframework.NodeInfo, allOrNothing bool, ) (*status.ScaleUpStatus, errors.AutoscalerError) { - defer func() { o.scaleUpRegularPods = !o.scaleUpRegularPods }() + defer func() { + o.autoscalingContext.ProvisioningRequstScaleUpMode = !o.autoscalingContext.ProvisioningRequstScaleUpMode + }() provReqPods, regularPods := splitOut(unschedulablePods) if len(provReqPods) == 0 { - o.scaleUpRegularPods = true + o.autoscalingContext.ProvisioningRequstScaleUpMode = false } else if len(regularPods) == 0 { - o.scaleUpRegularPods = false + o.autoscalingContext.ProvisioningRequstScaleUpMode = true } - if o.scaleUpRegularPods { - return o.podsOrchestrator.ScaleUp(regularPods, nodes, daemonSets, nodeInfos, allOrNothing) + if o.autoscalingContext.ProvisioningRequstScaleUpMode { + return o.provReqOrchestrator.ScaleUp(provReqPods, nodes, daemonSets, nodeInfos, allOrNothing) } - return o.provReqOrchestrator.ScaleUp(provReqPods, nodes, daemonSets, nodeInfos, allOrNothing) + return o.podsOrchestrator.ScaleUp(regularPods, nodes, daemonSets, nodeInfos, allOrNothing) } func splitOut(unschedulablePods []*apiv1.Pod) (provReqPods, regularPods []*apiv1.Pod) { diff --git a/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator_test.go b/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator_test.go index 64644ee8d3f3..993b15a2581e 100644 --- a/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator_test.go +++ b/cluster-autoscaler/provisioningrequest/orchestrator/wrapper_orchestrator_test.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/assert" appsv1 "k8s.io/api/apps/v1" apiv1 "k8s.io/api/core/v1" - "k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest/autoscaling.x-k8s.io/v1" + v1 "k8s.io/autoscaler/cluster-autoscaler/apis/provisioningrequest/autoscaling.x-k8s.io/v1" "k8s.io/autoscaler/cluster-autoscaler/clusterstate" "k8s.io/autoscaler/cluster-autoscaler/context" "k8s.io/autoscaler/cluster-autoscaler/estimator" @@ -41,6 +41,7 @@ const ( func TestWrapperScaleUp(t *testing.T) { o := WrapperOrchestrator{ + autoscalingContext: &context.AutoscalingContext{ProvisioningRequstScaleUpMode: true}, provReqOrchestrator: &fakeScaleUp{provisioningRequestErrorMsg}, podsOrchestrator: &fakeScaleUp{regularPodsErrorMsg}, }