diff --git a/USERS.md b/USERS.md index 97897944aa..91e06024e5 100644 --- a/USERS.md +++ b/USERS.md @@ -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) diff --git a/test/e2e/canary_test.go b/test/e2e/canary_test.go index dd6a9c1c75..190c600bdf 100644 --- a/test/e2e/canary_test.go +++ b/test/e2e/canary_test.go @@ -1,3 +1,4 @@ +//go:build e2e // +build e2e package e2e @@ -456,7 +457,7 @@ spec: WaitForRolloutStatus("Degraded"). WaitForRolloutStatus("Paused"). Then(). - ExpectCanaryStablePodCount(1, 3). + ExpectCanaryStablePodCount(1, 2). When(). PromoteRollout(). WaitForRolloutStatus("Degraded"). @@ -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) +} diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index 01055d1931..99ea7bbed8 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -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)