From 8c71984e1960bff5a96e30485193ffd34b66e842 Mon Sep 17 00:00:00 2001 From: yonatanelkad Date: Mon, 3 Jan 2022 22:25:05 +0200 Subject: [PATCH 1/3] Cap the replica count during a canary deployment --- test/e2e/canary_test.go | 45 ++++++++++++++++++++++++++++++++++++++ utils/replicaset/canary.go | 27 +++++++++++++++++++++-- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/test/e2e/canary_test.go b/test/e2e/canary_test.go index dd6a9c1c75..5533c81b7e 100644 --- a/test/e2e/canary_test.go +++ b/test/e2e/canary_test.go @@ -1,3 +1,4 @@ +//go:build e2e // +build e2e package e2e @@ -591,3 +592,47 @@ func (s *CanarySuite) TestCanaryDynamicStableScale() { Then(). ExpectRevisionPodCount("1", 4) } + +func (s *CanarySuite) TestSinglePodWithMinimumWeight() { + s.Given(). + HealthyRollout(` +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + name: single-pod +spec: + replicas: 15 + strategy: + canary: + steps: + - setWeight: 1 + - pause: {} + selector: + matchLabels: + app: single-pod + template: + metadata: + labels: + app: single-pod + spec: + containers: + - name: single-pod + image: nginx:1.19-alpine + # slow down the start/stop of pods so our pod count checks will not flake + lifecycle: + postStart: + exec: + command: [sleep, "5"] + preStop: + exec: + command: [sleep, "5"] + resources: + requests: + memory: 16Mi + cpu: 1m`). + When(). + UpdateSpec(). + WaitForRolloutStatus("Paused"). + Then(). + ExpectCanaryStablePodCount(1, 14) +} diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index 01055d1931..9cba96bcce 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 > 3) { + 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) From 4e46455bdc3297becb66b18ef870aa8f97fafd81 Mon Sep 17 00:00:00 2001 From: yonatanelkad Date: Tue, 4 Jan 2022 20:19:54 +0200 Subject: [PATCH 2/3] Adding and fixing tests according to the replica capping Signed-off-by: yonatanelkad --- test/e2e/canary_test.go | 29 ++++++++++++++--------------- utils/replicaset/canary.go | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/test/e2e/canary_test.go b/test/e2e/canary_test.go index 5533c81b7e..190c600bdf 100644 --- a/test/e2e/canary_test.go +++ b/test/e2e/canary_test.go @@ -457,7 +457,7 @@ spec: WaitForRolloutStatus("Degraded"). WaitForRolloutStatus("Paused"). Then(). - ExpectCanaryStablePodCount(1, 3). + ExpectCanaryStablePodCount(1, 2). When(). PromoteRollout(). WaitForRolloutStatus("Degraded"). @@ -593,13 +593,13 @@ func (s *CanarySuite) TestCanaryDynamicStableScale() { ExpectRevisionPodCount("1", 4) } -func (s *CanarySuite) TestSinglePodWithMinimumWeight() { +func (s *CanarySuite) TestReplicasCapping() { s.Given(). HealthyRollout(` apiVersion: argoproj.io/v1alpha1 kind: Rollout metadata: - name: single-pod + name: replicas-capping spec: replicas: 15 strategy: @@ -607,25 +607,19 @@ spec: steps: - setWeight: 1 - pause: {} + - setWeight: 50 + - pause: {} selector: matchLabels: - app: single-pod + app: replicas-capping template: metadata: labels: - app: single-pod + app: replicas-capping spec: containers: - - name: single-pod + - name: replicas-capping image: nginx:1.19-alpine - # slow down the start/stop of pods so our pod count checks will not flake - lifecycle: - postStart: - exec: - command: [sleep, "5"] - preStop: - exec: - command: [sleep, "5"] resources: requests: memory: 16Mi @@ -634,5 +628,10 @@ spec: UpdateSpec(). WaitForRolloutStatus("Paused"). Then(). - ExpectCanaryStablePodCount(1, 14) + ExpectCanaryStablePodCount(1, 14). + When(). + PromoteRollout(). + WaitForRolloutStatus("Paused"). + Then(). + ExpectCanaryStablePodCount(7, 8) } diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index 9cba96bcce..99ea7bbed8 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -138,7 +138,7 @@ func calculateRolloutSteps(rolloutSpecReplica int, desiredWeight float64) (int32 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 > 3) { + if (desiredNewRSReplicaCount == 0) && (desiredStableRSReplicaCount > 1) { desiredNewRSReplicaCount++ desiredStableRSReplicaCount-- } else if desiredNewRSReplicaCount == 0 { From 2a9e1344ddf9aee936f6fb79307172a3e2faae7c Mon Sep 17 00:00:00 2001 From: yonatanelkad Date: Tue, 4 Jan 2022 21:05:48 +0200 Subject: [PATCH 3/3] Adding ironSource to USERS.md file Signed-off-by: yonatanelkad --- USERS.md | 1 + 1 file changed, 1 insertion(+) 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)