From afa2c9c24d9153221f6e32869735684e05a4cc36 Mon Sep 17 00:00:00 2001 From: hari rongali Date: Wed, 25 Aug 2021 17:44:46 -0700 Subject: [PATCH 1/4] fix: replica count for new deployment Signed-off-by: hari rongali --- utils/replicaset/canary.go | 5 +++-- utils/replicaset/canary_test.go | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index 2068e4b983..3599fa2ed9 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -187,14 +187,15 @@ 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 { // Skip scalingDown canary replicaSet when StableSet availability is not taken into calculation for scaleDown - stableRSReplicaCount = calculateScaleDownReplicaCount(stableRS, desiredStableRSReplicaCount, scaleDownCount, stableRSReplicaCount) + if scaleStableRS { + stableRSReplicaCount = calculateScaleDownReplicaCount(stableRS, desiredStableRSReplicaCount, scaleDownCount, stableRSReplicaCount) + } stableRSReplicaCount, newRSReplicaCount = adjustReplicaWithinLimits(stableRS, newRS, stableRSReplicaCount, newRSReplicaCount, maxReplicaCountAllowed, minAvailableReplicaCount) } return newRSReplicaCount, stableRSReplicaCount diff --git a/utils/replicaset/canary_test.go b/utils/replicaset/canary_test.go index 28e3f3e3c3..21b93a9d26 100644 --- a/utils/replicaset/canary_test.go +++ b/utils/replicaset/canary_test.go @@ -643,6 +643,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{} From 7ff403f14de4620c3b76d5d370765138096b2a1e Mon Sep 17 00:00:00 2001 From: hari rongali Date: Wed, 25 Aug 2021 17:48:31 -0700 Subject: [PATCH 2/4] fix: replica count for new deployment Signed-off-by: hari rongali --- utils/replicaset/canary.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index 3599fa2ed9..705cc54dbb 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -191,11 +191,9 @@ func CalculateReplicaCountsForCanary(rollout *v1alpha1.Rollout, newRS *appsv1.Re // 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 - if scaleStableRS { - stableRSReplicaCount = calculateScaleDownReplicaCount(stableRS, desiredStableRSReplicaCount, scaleDownCount, stableRSReplicaCount) - } + stableRSReplicaCount = calculateScaleDownReplicaCount(stableRS, desiredStableRSReplicaCount, scaleDownCount, stableRSReplicaCount) stableRSReplicaCount, newRSReplicaCount = adjustReplicaWithinLimits(stableRS, newRS, stableRSReplicaCount, newRSReplicaCount, maxReplicaCountAllowed, minAvailableReplicaCount) } return newRSReplicaCount, stableRSReplicaCount From ee060b39c87343c9f8a9b64577b762d5a5fc00f3 Mon Sep 17 00:00:00 2001 From: hari rongali Date: Wed, 25 Aug 2021 17:52:53 -0700 Subject: [PATCH 3/4] fix: lint Signed-off-by: hari rongali --- utils/replicaset/canary.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index 705cc54dbb..6f89d184c6 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -191,7 +191,7 @@ func CalculateReplicaCountsForCanary(rollout *v1alpha1.Rollout, newRS *appsv1.Re // 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 if scaleStableRS{ + } 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) From 65b7d0b8ed260c5c009bbfb1cf83b30a16b272ee Mon Sep 17 00:00:00 2001 From: hari rongali Date: Wed, 25 Aug 2021 18:25:13 -0700 Subject: [PATCH 4/4] Trigger Build Signed-off-by: hari rongali