Skip to content

Commit

Permalink
fix: replica count for new deployment (#1449)
Browse files Browse the repository at this point in the history
fix: replica count for new deployment (#1449)

Signed-off-by: hari rongali <hari_rongali@intuit.com>
  • Loading branch information
harikrongali authored and alexmt committed Aug 26, 2021
1 parent 980a56d commit 5b332f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions utils/replicaset/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions utils/replicaset/canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 5b332f6

Please sign in to comment.