diff --git a/tests/data/route_with_weights.yaml b/tests/data/route_with_weights.yaml new file mode 100644 index 0000000..2c9550f --- /dev/null +++ b/tests/data/route_with_weights.yaml @@ -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 \ No newline at end of file diff --git a/tests/data/sample_rollout.yaml b/tests/data/sample_rollout.yaml new file mode 100644 index 0000000..54fc70d --- /dev/null +++ b/tests/data/sample_rollout.yaml @@ -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 \ No newline at end of file diff --git a/tests/e2e/plugin_test.go b/tests/e2e/plugin_test.go index 64a1564..6c9358e 100644 --- a/tests/e2e/plugin_test.go +++ b/tests/e2e/plugin_test.go @@ -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())