Skip to content

Commit

Permalink
Merge pull request #7414 from yaroslava-serdiuk/provreq-context
Browse files Browse the repository at this point in the history
Move ProvisioningRequestScaleUpMode to AutoscalingContext
  • Loading branch information
k8s-ci-robot authored Nov 4, 2024
2 parents d06fe04 + fd0e848 commit 8d90fc4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cluster-autoscaler/context/autoscaling_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -41,6 +41,7 @@ const (

func TestWrapperScaleUp(t *testing.T) {
o := WrapperOrchestrator{
autoscalingContext: &context.AutoscalingContext{ProvisioningRequstScaleUpMode: true},
provReqOrchestrator: &fakeScaleUp{provisioningRequestErrorMsg},
podsOrchestrator: &fakeScaleUp{regularPodsErrorMsg},
}
Expand Down

0 comments on commit 8d90fc4

Please sign in to comment.