diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index d73c9f5e19..d8ad236e08 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -187,12 +187,11 @@ func CalculateReplicaCountsForCanary(rollout *v1alpha1.Rollout, newRS *appsv1.Re } scaleDownCount := replicasToScaleDown - minAvailableReplicaCount - if !isIncreasing { // Skip scalingDown Stable replicaSet when Canary availability is not taken into calculation for scaleDown newRSReplicaCount = calculateScaleDownReplicaCount(newRS, desiredNewRSReplicaCount, scaleDownCount, newRSReplicaCount) newRSReplicaCount, stableRSReplicaCount = adjustReplicaWithinLimits(newRS, stableRS, newRSReplicaCount, stableRSReplicaCount, maxReplicaCountAllowed, minAvailableReplicaCount) - } else { + } else if scaleStableRS { // Skip scalingDown canary replicaSet when StableSet availability is not taken into calculation for scaleDown stableRSReplicaCount = calculateScaleDownReplicaCount(stableRS, desiredStableRSReplicaCount, scaleDownCount, stableRSReplicaCount) stableRSReplicaCount, newRSReplicaCount = adjustReplicaWithinLimits(stableRS, newRS, stableRSReplicaCount, newRSReplicaCount, maxReplicaCountAllowed, minAvailableReplicaCount) diff --git a/utils/replicaset/canary_test.go b/utils/replicaset/canary_test.go index c82ba28836..1c5f046fb5 100644 --- a/utils/replicaset/canary_test.go +++ b/utils/replicaset/canary_test.go @@ -602,6 +602,15 @@ func TestCalculateReplicaCountsForCanary(t *testing.T) { } } +func TestCalculateReplicaCountsForNewDeployment(t *testing.T) { + rollout := newRollout(10, 10, intstr.FromInt(0), intstr.FromInt(1), "canary", "stable", nil, nil) + stableRS := newRS("stable", 10, 0) + newRS := newRS("stable", 10, 0) + newRSReplicaCount, stableRSReplicaCount := CalculateReplicaCountsForCanary(rollout, newRS, stableRS, nil) + assert.Equal(t, int32(10), newRSReplicaCount) + assert.Equal(t, int32(0), stableRSReplicaCount) +} + func TestCalculateReplicaCountsForCanaryTrafficRouting(t *testing.T) { rollout := newRollout(10, 10, intstr.FromInt(0), intstr.FromInt(1), "canary", "stable", nil, nil) rollout.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{}