From 5b332f6bb76f6399bbc26067caa9a28c59f2bade Mon Sep 17 00:00:00 2001 From: harikrongali <81331774+harikrongali@users.noreply.github.com> Date: Wed, 25 Aug 2021 22:17:19 -0700 Subject: [PATCH] fix: replica count for new deployment (#1449) fix: replica count for new deployment (#1449) Signed-off-by: hari rongali --- utils/replicaset/canary.go | 3 +-- utils/replicaset/canary_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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{}