Skip to content

Commit

Permalink
Add an e2e test to verify that canary weight is reinitialized to zero
Browse files Browse the repository at this point in the history
Signed-off-by: Chetan Banavikalmutt <[email protected]>
  • Loading branch information
chetan-rns authored and jgwest committed Aug 22, 2024
1 parent e993c28 commit 142230a
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/data/route_with_weights.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
apiVersion: v1
kind: Service
metadata:
name: rollouts-demo-stable
spec:
ports:
- port: 8080
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo

---
apiVersion: v1
kind: Service
metadata:
name: rollouts-demo-canary
spec:
ports:
- port: 8080
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo

---

kind: Route
apiVersion: route.openshift.io/v1
metadata:
name: rollouts-demo
annotations:
haproxy.router.openshift.io/disable_cookies: "true"
spec:
to:
kind: Service
name: rollouts-demo-stable
weight: 50
alternateBackends:
- kind: Service
name: rollouts-demo-canary
weight: 50
port:
targetPort: http
wildcardPolicy: None
41 changes: 41 additions & 0 deletions tests/data/sample_rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollouts-demo
spec:
replicas: 5
strategy:
canary:
canaryService: rollouts-demo-canary
stableService: rollouts-demo-stable
steps:
- setWeight: 20
- pause: {}
- setWeight: 70
- pause: {}
trafficRouting:
plugins:
argoproj-labs/openshift:
routes:
- rollouts-demo
namespace: argo-rollouts-e2e
revisionHistoryLimit: 2
selector:
matchLabels:
app: rollouts-demo
template:
metadata:
labels:
app: rollouts-demo
spec:
containers:
- name: rollouts-demo
image: quay.io/nginx/nginx-unprivileged
ports:
- name: http
containerPort: 8080
protocol: TCP
resources:
requests:
memory: 32Mi
cpu: 5m
29 changes: 29 additions & 0 deletions tests/e2e/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ var _ = Describe("OpenShift Route Traffic Plugin Tests", func() {
Expect(err).ToNot(HaveOccurred())
})

It("should initialize the canary weight to zero when a Rollout is created", func() {
By("create a Route with predefined weights for stable and canary")
err := fixtures.ApplyResources("../data/route_with_weights.yaml", namespace)
Expect(err).ToNot(HaveOccurred())

By("Route should retain the weights set for canary and stable")
route := &routeapi.Route{
ObjectMeta: metav1.ObjectMeta{
Name: "rollouts-demo",
Namespace: namespace,
},
}
Eventually(route, "30s", "1s").Should(routeFixture.HaveWeights(50, 50))

By("apply the Rollout and verify if the weights have been reinitialized")
err = fixtures.ApplyResources("../data/sample_rollout.yaml", namespace)
Expect(err).ToNot(HaveOccurred())

rollout, err := rolloutClient.ArgoprojV1alpha1().Rollouts(namespace).Get(
ctx,
rolloutName,
metav1.GetOptions{},
)
Expect(err).ToNot(HaveOccurred())
Eventually(rollout, "60s", "1s").Should(rolloutFixture.HavePhase(rolloutsv1alpha1.RolloutPhaseHealthy))

Eventually(route, "30s", "1s").Should(routeFixture.HaveWeights(100, 0))
})

It("should handle a Rollout with multiple steps", func() {
err := fixtures.ApplyResources("../data/single_route.yaml", namespace)
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 142230a

Please sign in to comment.