Skip to content

Commit 5b332f6

Browse files
harikrongalialexmt
authored andcommitted
fix: replica count for new deployment (argoproj#1449)
fix: replica count for new deployment (argoproj#1449) Signed-off-by: hari rongali <[email protected]>
1 parent 980a56d commit 5b332f6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

utils/replicaset/canary.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,11 @@ func CalculateReplicaCountsForCanary(rollout *v1alpha1.Rollout, newRS *appsv1.Re
187187
}
188188

189189
scaleDownCount := replicasToScaleDown - minAvailableReplicaCount
190-
191190
if !isIncreasing {
192191
// Skip scalingDown Stable replicaSet when Canary availability is not taken into calculation for scaleDown
193192
newRSReplicaCount = calculateScaleDownReplicaCount(newRS, desiredNewRSReplicaCount, scaleDownCount, newRSReplicaCount)
194193
newRSReplicaCount, stableRSReplicaCount = adjustReplicaWithinLimits(newRS, stableRS, newRSReplicaCount, stableRSReplicaCount, maxReplicaCountAllowed, minAvailableReplicaCount)
195-
} else {
194+
} else if scaleStableRS {
196195
// Skip scalingDown canary replicaSet when StableSet availability is not taken into calculation for scaleDown
197196
stableRSReplicaCount = calculateScaleDownReplicaCount(stableRS, desiredStableRSReplicaCount, scaleDownCount, stableRSReplicaCount)
198197
stableRSReplicaCount, newRSReplicaCount = adjustReplicaWithinLimits(stableRS, newRS, stableRSReplicaCount, newRSReplicaCount, maxReplicaCountAllowed, minAvailableReplicaCount)

utils/replicaset/canary_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,15 @@ func TestCalculateReplicaCountsForCanary(t *testing.T) {
602602
}
603603
}
604604

605+
func TestCalculateReplicaCountsForNewDeployment(t *testing.T) {
606+
rollout := newRollout(10, 10, intstr.FromInt(0), intstr.FromInt(1), "canary", "stable", nil, nil)
607+
stableRS := newRS("stable", 10, 0)
608+
newRS := newRS("stable", 10, 0)
609+
newRSReplicaCount, stableRSReplicaCount := CalculateReplicaCountsForCanary(rollout, newRS, stableRS, nil)
610+
assert.Equal(t, int32(10), newRSReplicaCount)
611+
assert.Equal(t, int32(0), stableRSReplicaCount)
612+
}
613+
605614
func TestCalculateReplicaCountsForCanaryTrafficRouting(t *testing.T) {
606615
rollout := newRollout(10, 10, intstr.FromInt(0), intstr.FromInt(1), "canary", "stable", nil, nil)
607616
rollout.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{}

0 commit comments

Comments
 (0)