Move the condition for ScaleDownInProgress to legacy scaledown code

This commit is contained in:
Daniel Kłobuszewski 2022-04-29 11:35:28 +02:00
parent 561a9da9e4
commit d0f8cc7806
2 changed files with 18 additions and 16 deletions

View File

@ -687,6 +687,12 @@ func (sd *ScaleDown) TryToScaleDown(
currentTime time.Time, currentTime time.Time,
pdbs []*policyv1.PodDisruptionBudget, pdbs []*policyv1.PodDisruptionBudget,
) (*status.ScaleDownStatus, errors.AutoscalerError) { ) (*status.ScaleDownStatus, errors.AutoscalerError) {
_, drained := sd.nodeDeletionTracker.DeletionsInProgress()
if len(drained) > 0 {
return &status.ScaleDownStatus{
Result: status.ScaleDownInProgress,
}, nil
}
ndr, ts := sd.nodeDeletionTracker.DeletionResults() ndr, ts := sd.nodeDeletionTracker.DeletionResults()
scaleDownStatus := &status.ScaleDownStatus{NodeDeleteResults: ndr, NodeDeleteResultsAsOf: ts} scaleDownStatus := &status.ScaleDownStatus{NodeDeleteResults: ndr, NodeDeleteResultsAsOf: ts}
nodeDeletionDuration := time.Duration(0) nodeDeletionDuration := time.Duration(0)

View File

@ -523,32 +523,28 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError
a.lastScaleUpTime.Add(a.ScaleDownDelayAfterAdd).After(currentTime) || a.lastScaleUpTime.Add(a.ScaleDownDelayAfterAdd).After(currentTime) ||
a.lastScaleDownFailTime.Add(a.ScaleDownDelayAfterFailure).After(currentTime) || a.lastScaleDownFailTime.Add(a.ScaleDownDelayAfterFailure).After(currentTime) ||
a.lastScaleDownDeleteTime.Add(a.ScaleDownDelayAfterDelete).After(currentTime) a.lastScaleDownDeleteTime.Add(a.ScaleDownDelayAfterDelete).After(currentTime)
// TODO(x13n): Move nonEmptyDeletionsCount > 0 condition to the legacy scaledown implementation.
_, nonEmptyDeletionsInProgress := actuationStatus.DeletionsInProgress()
nonEmptyDeletionsCount := len(nonEmptyDeletionsInProgress)
// In dry run only utilization is updated
calculateUnneededOnly := scaleDownInCooldown || nonEmptyDeletionsCount > 0
klog.V(4).Infof("Scale down status: unneededOnly=%v lastScaleUpTime=%s "+ klog.V(4).Infof("Scale down status: lastScaleUpTime=%s lastScaleDownDeleteTime=%v "+
"lastScaleDownDeleteTime=%v lastScaleDownFailTime=%s scaleDownForbidden=%v "+ "lastScaleDownFailTime=%s scaleDownForbidden=%v scaleDownInCooldown=%v",
"nonEmptyDeletionsCount=%v scaleDownInCooldown=%v", a.lastScaleUpTime, a.lastScaleDownDeleteTime, a.lastScaleDownFailTime,
calculateUnneededOnly, a.lastScaleUpTime, a.processorCallbacks.disableScaleDownForLoop, scaleDownInCooldown)
a.lastScaleDownDeleteTime, a.lastScaleDownFailTime, a.processorCallbacks.disableScaleDownForLoop,
nonEmptyDeletionsCount, scaleDownInCooldown)
metrics.UpdateScaleDownInCooldown(scaleDownInCooldown) metrics.UpdateScaleDownInCooldown(scaleDownInCooldown)
if scaleDownInCooldown { if scaleDownInCooldown {
scaleDownStatus.Result = status.ScaleDownInCooldown scaleDownStatus.Result = status.ScaleDownInCooldown
} else if nonEmptyDeletionsCount > 0 {
scaleDownStatus.Result = status.ScaleDownInProgress
} else { } else {
klog.V(4).Infof("Starting scale down") klog.V(4).Infof("Starting scale down")
// We want to delete unneeded Node Groups only if there was no recent scale up, // We want to delete unneeded Node Groups only if there was no recent scale up,
// and there is no current delete in progress and there was no recent errors. // and there is no current delete in progress and there was no recent errors.
removedNodeGroups, err := a.processors.NodeGroupManager.RemoveUnneededNodeGroups(autoscalingContext) _, drained := actuationStatus.DeletionsInProgress()
if err != nil { var removedNodeGroups []cloudprovider.NodeGroup
klog.Errorf("Error while removing unneeded node groups: %v", err) if len(drained) == 0 {
var err error
removedNodeGroups, err = a.processors.NodeGroupManager.RemoveUnneededNodeGroups(autoscalingContext)
if err != nil {
klog.Errorf("Error while removing unneeded node groups: %v", err)
}
} }
scaleDownStart := time.Now() scaleDownStart := time.Now()