Skip to content

Commit 4766a78

Browse files
test: added e2e test for merging headers
Signed-off-by: Kostis Kapelonis <kostis.kapelonis@octopus.com>
1 parent 68d780b commit 4766a78

8 files changed

Lines changed: 245 additions & 0 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: httproute-two-headers
5+
namespace: default
6+
spec:
7+
(length(rules)): 1
8+
rules:
9+
- matches:
10+
- headers:
11+
- name: X-Security
12+
type: Exact
13+
value: secret123
14+
backendRefs:
15+
- name: httproute-two-headers-stable-service
16+
- name: httproute-two-headers-canary-service
17+
(weight): 0
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: httproute-two-headers
5+
namespace: default
6+
spec:
7+
(length(rules)): 1
8+
rules:
9+
- matches:
10+
- headers:
11+
- name: X-Security
12+
type: Exact
13+
value: secret123
14+
backendRefs:
15+
- name: httproute-two-headers-stable-service
16+
- name: httproute-two-headers-canary-service
17+
(weight): 0
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: httproute-two-headers
5+
namespace: default
6+
spec:
7+
(length(rules)): 2
8+
rules:
9+
- matches:
10+
- headers:
11+
- name: X-Security
12+
type: Exact
13+
value: secret123
14+
backendRefs:
15+
- name: httproute-two-headers-stable-service
16+
(weight): 50
17+
- name: httproute-two-headers-canary-service
18+
(weight): 50
19+
- name: canary-route1
20+
matches:
21+
- (length(headers)): 2
22+
headers:
23+
- name: X-Security
24+
type: Exact
25+
value: secret123
26+
- name: X-QA
27+
type: Exact
28+
value: "true"
29+
backendRefs:
30+
- name: httproute-two-headers-canary-service
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Rollout
3+
metadata:
4+
name: httproute-two-headers-rollout
5+
namespace: default
6+
status:
7+
(phase == 'Healthy'): true
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
apiVersion: chainsaw.kyverno.io/v1alpha1
2+
kind: Test
3+
metadata:
4+
name: httproute-two-headers
5+
labels:
6+
route-type: http
7+
test-scope: headers
8+
spec:
9+
description: >
10+
Verifies header-based routing when the static HTTPRoute already contains a header match
11+
(X-Security) and the Rollout's setHeaderRoute uses a different header (X-QA) — the scenario
12+
from issue #151. The plugin must merge static-rule headers into the managed rule so that the
13+
managed rule has both headers (X-Security + X-QA), giving it higher specificity than the
14+
1-header static rule. After the rollout completes the managed rule must be fully removed.
15+
namespace: default
16+
concurrent: false
17+
18+
steps:
19+
- name: create-resources
20+
description: Create the HTTPRoute (with existing X-Security header match) and Rollout.
21+
try:
22+
- apply:
23+
file: resources/services.yaml
24+
- apply:
25+
file: resources/httproute.yaml
26+
- apply:
27+
file: resources/rollout.yaml
28+
29+
- name: assert-initial-state
30+
description: Plugin initializes the HTTPRoute with 1 rule (X-Security match) and canary weight 0.
31+
try:
32+
- assert:
33+
timeout: 30s
34+
file: assertions/httproute-initial.yaml
35+
36+
- name: wait-for-initial-healthy
37+
description: Wait for the initial rollout to reach Healthy before triggering a canary.
38+
try:
39+
- assert:
40+
timeout: 5m
41+
file: assertions/rollout-healthy.yaml
42+
43+
- name: trigger-canary
44+
description: Update the rollout image to start a canary (setWeight:50 -> setHeaderRoute:X-QA -> pause:30s).
45+
try:
46+
- patch:
47+
resource:
48+
apiVersion: argoproj.io/v1alpha1
49+
kind: Rollout
50+
metadata:
51+
name: httproute-two-headers-rollout
52+
namespace: default
53+
spec:
54+
template:
55+
spec:
56+
containers:
57+
- name: rollouts-demo
58+
image: argoproj/rollouts-demo:green
59+
60+
- name: assert-header-routing-active
61+
description: >
62+
Plugin must merge static-route headers into the managed rule. The managed rule must have
63+
exactly 2 headers (X-Security inherited from the static rule + X-QA from setHeaderRoute),
64+
ensuring it takes precedence over the 1-header static rule. Key assertion for issue #151.
65+
try:
66+
- assert:
67+
timeout: 2m
68+
file: assertions/httproute-with-header-route.yaml
69+
70+
- name: assert-rollout-healthy
71+
description: Wait for the canary to complete (30s pause auto-expires).
72+
try:
73+
- assert:
74+
timeout: 5m
75+
file: assertions/rollout-healthy.yaml
76+
77+
- name: assert-cleanup
78+
description: >
79+
Plugin must remove the managed X-QA rule after rollout completes. Only the original
80+
X-Security rule must remain, with canary weight reset to 0. No orphaned routes.
81+
try:
82+
- assert:
83+
timeout: 60s
84+
file: assertions/httproute-after-cleanup.yaml
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: httproute-two-headers
5+
namespace: default
6+
spec:
7+
parentRefs:
8+
- name: traefik-gateway
9+
namespace: default
10+
rules:
11+
- matches:
12+
- headers:
13+
- name: X-Security
14+
type: Exact
15+
value: secret123
16+
backendRefs:
17+
- name: httproute-two-headers-stable-service
18+
port: 80
19+
- name: httproute-two-headers-canary-service
20+
port: 80
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Rollout
3+
metadata:
4+
name: httproute-two-headers-rollout
5+
namespace: default
6+
spec:
7+
replicas: 2
8+
strategy:
9+
canary:
10+
canaryService: httproute-two-headers-canary-service
11+
stableService: httproute-two-headers-stable-service
12+
trafficRouting:
13+
managedRoutes:
14+
- name: canary-route1
15+
plugins:
16+
argoproj-labs/gatewayAPI:
17+
httpRoutes:
18+
- name: httproute-two-headers
19+
useHeaderRoutes: true
20+
namespace: default
21+
steps:
22+
- setWeight: 50
23+
- setHeaderRoute:
24+
name: canary-route1
25+
match:
26+
- headerName: X-QA
27+
headerValue:
28+
exact: "true"
29+
- pause: {duration: 30s} # auto-promotes — no promote command needed in tests
30+
revisionHistoryLimit: 2
31+
selector:
32+
matchLabels:
33+
app: httproute-two-headers
34+
template:
35+
metadata:
36+
labels:
37+
app: httproute-two-headers
38+
spec:
39+
containers:
40+
- name: rollouts-demo
41+
image: argoproj/rollouts-demo:red
42+
ports:
43+
- name: http
44+
containerPort: 8080
45+
protocol: TCP
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: httproute-two-headers-stable-service
5+
spec:
6+
ports:
7+
- port: 80
8+
targetPort: http
9+
protocol: TCP
10+
name: http
11+
selector:
12+
app: httproute-two-headers
13+
---
14+
apiVersion: v1
15+
kind: Service
16+
metadata:
17+
name: httproute-two-headers-canary-service
18+
spec:
19+
ports:
20+
- port: 80
21+
targetPort: http
22+
protocol: TCP
23+
name: http
24+
selector:
25+
app: httproute-two-headers

0 commit comments

Comments
 (0)