diff --git a/cluster-autoscaler/core/scaleup/orchestrator/executor.go b/cluster-autoscaler/core/scaleup/orchestrator/executor.go index 15851b99594b..c6504c2da9b0 100644 --- a/cluster-autoscaler/core/scaleup/orchestrator/executor.go +++ b/cluster-autoscaler/core/scaleup/orchestrator/executor.go @@ -165,15 +165,22 @@ func (e *scaleUpExecutor) executeScaleUp( e.autoscalingContext.LogRecorder.Eventf(apiv1.EventTypeNormal, "ScaledUpGroup", "Scale-up: setting group %s size to %d instead of %d (max: %d)", info.Group.Id(), info.NewSize, info.CurrentSize, info.MaxSize) increase := info.NewSize - info.CurrentSize + if increase < 0 { + err := errors.NewAutoscalerError( + errors.InternalError, + fmt.Sprintf("increase in number of nodes cannot be negative (current: %d, new: %d, delta: %d)", info.CurrentSize, info.NewSize, increase), + ) + e.autoscalingContext.LogRecorder.Eventf(apiv1.EventTypeWarning, "FailedToScaleUpGroup", "Scale-up aborted for group %s: %v", info.Group.Id(), err) + e.scaleStateNotifier.RegisterFailedScaleUp(info.Group, string(err.Type()), err.Error(), gpuResourceName, gpuType, now) + + return err + } if err := e.increaseSize(info.Group, increase, atomic); err != nil { e.autoscalingContext.LogRecorder.Eventf(apiv1.EventTypeWarning, "FailedToScaleUpGroup", "Scale-up failed for group %s: %v", info.Group.Id(), err) aerr := errors.ToAutoscalerError(errors.CloudProviderError, err).AddPrefix("failed to increase node group size: ") e.scaleStateNotifier.RegisterFailedScaleUp(info.Group, string(aerr.Type()), aerr.Error(), gpuResourceName, gpuType, now) return aerr } - if increase < 0 { - return errors.NewAutoscalerError(errors.InternalError, fmt.Sprintf("increase in number of nodes cannot be negative, got: %v", increase)) - } if !info.Group.Exist() && e.asyncNodeGroupStateChecker.IsUpcoming(info.Group) { // Don't emit scale up event for upcoming node group as it will be generated after // the node group is created, during initial scale up.