Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(controller): Capping the replica count during a canary deployment #1742

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ Organizations below are **officially** using Argo Rollouts. Please send a PR wit
1. [Twilio SendGrid](https://sendgrid.com)
1. [Ubie](https://ubie.life/)
1. [VISITS Technologies](https://visits.world/en)
1. [ironSource](https://is.com)
46 changes: 45 additions & 1 deletion test/e2e/canary_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build e2e
// +build e2e

package e2e
Expand Down Expand Up @@ -456,7 +457,7 @@ spec:
WaitForRolloutStatus("Degraded").
WaitForRolloutStatus("Paused").
Then().
ExpectCanaryStablePodCount(1, 3).
ExpectCanaryStablePodCount(1, 2).
When().
PromoteRollout().
WaitForRolloutStatus("Degraded").
Expand Down Expand Up @@ -591,3 +592,46 @@ func (s *CanarySuite) TestCanaryDynamicStableScale() {
Then().
ExpectRevisionPodCount("1", 4)
}

func (s *CanarySuite) TestReplicasCapping() {
s.Given().
HealthyRollout(`
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: replicas-capping
spec:
replicas: 15
strategy:
canary:
steps:
- setWeight: 1
- pause: {}
- setWeight: 50
- pause: {}
selector:
matchLabels:
app: replicas-capping
template:
metadata:
labels:
app: replicas-capping
spec:
containers:
- name: replicas-capping
image: nginx:1.19-alpine
resources:
requests:
memory: 16Mi
cpu: 1m`).
When().
UpdateSpec().
WaitForRolloutStatus("Paused").
Then().
ExpectCanaryStablePodCount(1, 14).
When().
PromoteRollout().
WaitForRolloutStatus("Paused").
Then().
ExpectCanaryStablePodCount(7, 8)
}
27 changes: 25 additions & 2 deletions utils/replicaset/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,35 @@ func DesiredReplicaCountsForCanary(rollout *v1alpha1.Rollout, newRS, stableRS *a
// replicas 1 currentWeight 5 NewRS 0 stableRS 1 max unavailable 0, surge 1 - should return newRS 1 stableRS 1
// replicas 1 currentWeight 95 NewRS 0 stableRS 1 max unavailable 0, surge 1 - should return newRS 1 stableRS 1
// For more examples, check the CalculateReplicaCountsForBasicCanary test in canary/canary_test.go

func calculateRolloutSteps(rolloutSpecReplica int, desiredWeight float64) (int32, int32) {
if int32(desiredWeight) == 0 {
desiredStableRSReplicaCount := int32(rolloutSpecReplica)
desiredNewRSReplicaCount := int32(0)
return desiredNewRSReplicaCount, desiredStableRSReplicaCount
} else {
log.Infof("Total replica count is: %d", rolloutSpecReplica)
desiredStableRSReplicaCount := int32(math.Ceil(float64(rolloutSpecReplica) * (1 - (float64(desiredWeight) / 100))))
desiredNewRSReplicaCount := int32(int32(rolloutSpecReplica) - desiredStableRSReplicaCount)
if (desiredNewRSReplicaCount == 0) && (desiredStableRSReplicaCount > 1) {
desiredNewRSReplicaCount++
desiredStableRSReplicaCount--
} else if desiredNewRSReplicaCount == 0 {
desiredNewRSReplicaCount++
}
return desiredNewRSReplicaCount, desiredStableRSReplicaCount
}
}

func CalculateReplicaCountsForBasicCanary(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaSet, stableRS *appsv1.ReplicaSet, oldRSs []*appsv1.ReplicaSet) (int32, int32) {
rolloutSpecReplica := defaults.GetReplicasOrDefault(rollout.Spec.Replicas)
_, desiredWeight := GetCanaryReplicasOrWeight(rollout)

desiredStableRSReplicaCount := int32(math.Ceil(float64(rolloutSpecReplica) * (1 - (float64(desiredWeight) / 100))))
desiredNewRSReplicaCount := int32(math.Ceil(float64(rolloutSpecReplica) * (float64(desiredWeight) / 100)))
desiredNewRSReplicaCount, desiredStableRSReplicaCount := calculateRolloutSteps(int(rolloutSpecReplica), float64(desiredWeight))
log.Infof("Desired Weight: %d", desiredWeight)
log.Infof("Spec Replica: %d", rolloutSpecReplica)
log.Infof("desiredStableRSReplicaCount: %d", desiredStableRSReplicaCount)
log.Infof("desiredNewRSReplicaCount: %d", desiredNewRSReplicaCount)

stableRSReplicaCount := int32(0)
newRSReplicaCount := int32(0)
Expand Down