diff --git a/operator/pkg/resources/statefulset_scale.go b/operator/pkg/resources/statefulset_scale.go index c1a443912..e3c86c0e7 100644 --- a/operator/pkg/resources/statefulset_scale.go +++ b/operator/pkg/resources/statefulset_scale.go @@ -75,14 +75,6 @@ const ( func (r *StatefulSetResource) handleScaling(ctx context.Context) error { log := r.logger.WithName("handleScaling").WithValues("nodepool", r.nodePool.Name) - // This is special - we allow only one decom at a time, ACROSS ALL nodePools. It's not per nodepool. - // if a decommission is already in progress, handle it first. If it's not finished, it will return an error - // which will requeue the reconciliation. We can't (and don't want to) do any further scaling until it's finished. - // handleDecommissionInProgress is supposed to exit with error if a decom is already in progress, so we don't start another decom. - if err := r.handleDecommissionInProgress(ctx, log); err != nil { - return err - } - npStatus := r.getNodePoolStatus() if npStatus.CurrentReplicas == 0 && ptr.Deref(r.nodePool.Replicas, 0) != 0 && !r.nodePool.Deleted { // Initialize the currentReplicas field. @@ -102,6 +94,14 @@ func (r *StatefulSetResource) handleScaling(ctx context.Context) error { return r.setCurrentReplicas(ctx, *r.nodePool.Replicas, r.nodePool.Name, r.logger) } + // This is special - we allow only one decom at a time, ACROSS ALL nodePools. It's not per nodepool. + // if a decommission is already in progress, handle it first. If it's not finished, it will return an error + // which will requeue the reconciliation. We can't (and don't want to) do any further scaling until it's finished. + // handleDecommissionInProgress is supposed to exit with error if a decom is already in progress, so we don't start another decom. + if err := r.handleDecommissionInProgress(ctx, log); err != nil { + return err + } + if ptr.Deref(r.nodePool.Replicas, 0) == npCurrentReplicas { log.V(logger.DebugLevel).Info("No scaling changes required for this nodepool", "replicas", *r.nodePool.Replicas, "spec replicas", *r.LastObservedState.Spec.Replicas) // No changes to replicas, we do nothing here return nil