From 7bb1f84250a13701f95e1b44ae93c8a73fb18a4c Mon Sep 17 00:00:00 2001 From: asingh51 Date: Wed, 7 Feb 2024 13:30:39 -0800 Subject: [PATCH] fix: stuck rollout when rollout is paused Signed-off-by: asingh51 --- rollout/canary.go | 2 +- test/e2e/canary_test.go | 17 ++++ ...nary-deploy-new-rev-on-paused-rollout.yaml | 91 +++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 test/e2e/functional/canary-deploy-new-rev-on-paused-rollout.yaml diff --git a/rollout/canary.go b/rollout/canary.go index a003b092a3..ed27bd0a79 100644 --- a/rollout/canary.go +++ b/rollout/canary.go @@ -184,7 +184,7 @@ func (c *rolloutContext) scaleDownOldReplicaSetsForCanary(oldRSs []*appsv1.Repli annotationedRSs := int32(0) for _, targetRS := range oldRSs { - if c.isReplicaSetReferenced(targetRS) { + if c.rollout.Spec.Strategy.Canary.TrafficRouting != nil && c.isReplicaSetReferenced(targetRS) { // We might get here if user interrupted an an update in order to move back to stable. c.log.Infof("Skip scale down of older RS '%s': still referenced", targetRS.Name) continue diff --git a/test/e2e/canary_test.go b/test/e2e/canary_test.go index bc5e60b6c3..8dd98703ca 100644 --- a/test/e2e/canary_test.go +++ b/test/e2e/canary_test.go @@ -565,6 +565,23 @@ func (s *CanarySuite) TestCanaryScaleDownOnAbortNoTrafficRouting() { ExpectRevisionPodCount("2", 0) } +func (s *CanarySuite) TestCanaryWhenRolloutPaused() { + s.Given(). + HealthyRollout(`@functional/canary-deploy-new-rev-on-paused-rollout.yaml`). + When(). + UpdateSpec(). // update to revision 2 + WaitForRolloutStatus("Paused"). + UpdateSpec(). // update to revision 3 + WaitForRolloutStatus("Healthy"). + Then(). + // Expect that the canary service selector has been moved back to stable + ExpectServiceSelector("canary-next-canary", map[string]string{"app": "canary-next-canary", "rollouts-pod-template-hash": "66597877b7"}, false). + When(). + Sleep(3*time.Second). + Then(). + ExpectRevisionPodCount("2", 0) +} + func (s *CanarySuite) TestCanaryUnScaleDownOnAbort() { s.Given(). HealthyRollout(`@functional/canary-unscaledownonabort.yaml`). diff --git a/test/e2e/functional/canary-deploy-new-rev-on-paused-rollout.yaml b/test/e2e/functional/canary-deploy-new-rev-on-paused-rollout.yaml new file mode 100644 index 0000000000..74c1a18f4b --- /dev/null +++ b/test/e2e/functional/canary-deploy-new-rev-on-paused-rollout.yaml @@ -0,0 +1,91 @@ +apiVersion: v1 +kind: Service +metadata: + name: canary-next-root +spec: + type: NodePort + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app: canary-next +--- +apiVersion: v1 +kind: Service +metadata: + name: canary-next-canary +spec: + type: NodePort + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app: canary-next +--- +apiVersion: v1 +kind: Service +metadata: + name: canary-next-stable +spec: + type: NodePort + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app: canary-next +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: canary-next-ingress + annotations: + kubernetes.io/ingress.class: alb +spec: + rules: + - http: + paths: + - path: /* + pathType: Prefix + backend: + service: + name: canary-next-root + port: + name: use-annotation +--- +apiVersion: argoproj.io/v1alpha1 +kind: Rollout +metadata: + name: canary-scaledownd-on-abort +spec: + selector: + matchLabels: + app: canary-next + template: + metadata: + labels: + app: canary-next + spec: + containers: + - name: canary-next + image: nginx:1.19-alpine + ports: + - name: http + containerPort: 80 + protocol: TCP + resources: + requests: + memory: 16Mi + cpu: 5m + strategy: + canary: + canaryService: canary-next-canary + stableService: canary-next-stable + steps: + - setWeight: 50 + - pause: {}