Skip to content

Commit 71f5191

Browse files
committed
add e2e
Signed-off-by: zirain <zirain2009@gmail.com>
1 parent b4c40fa commit 71f5191

4 files changed

Lines changed: 136 additions & 42 deletions

File tree

site/content/en/latest/tasks/extensibility/envoy-patch-policy.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ spec:
396396
jsonPatches:
397397
- type: "type.googleapis.com/envoy.config.route.v3.RouteConfiguration"
398398
# The RouteConfiguration name is of the form <GatewayNamespace>/<GatewayName>/<GatewayListenerName>
399+
# Using empty name to patch all the RouteConfiguration resources generated for this Gateway.
399400
name: default/eg/http
400401
operation:
401402
op: add
@@ -463,15 +464,8 @@ applied to Envoy Proxy.
463464
apiVersion: gateway.envoyproxy.io/v1alpha1
464465
kind: EnvoyPatchPolicy
465466
metadata:
466-
annotations:
467-
kubectl.kubernetes.io/last-applied-configuration: |
468-
{"apiVersion":"gateway.envoyproxy.io/v1alpha1","kind":"EnvoyPatchPolicy","metadata":{"annotations":{},"name":"custom-response-patch-policy","namespace":"default"},"spec":{"jsonPatches":[{"name":"default/eg/http","operation":{"op":"add","path":"/default_filter_chain/filters/0/typed_config/local_reply_config","value":{"mappers":[{"body":{"inline_string":"could not find what you are looking for"},"filter":{"status_code_filter":{"comparison":{"op":"EQ","value":{"default_value":404}}}}}]}},"type":"type.googleapis.com/envoy.config.listener.v3.Listener"}],"priority":0,"targetRef":{"group":"gateway.networking.k8s.io","kind":"Gateway","name":"eg","namespace":"default"},"type":"JSONPatch"}}
469-
creationTimestamp: "2023-07-31T21:47:53Z"
470-
generation: 1
471467
name: custom-response-patch-policy
472468
namespace: default
473-
resourceVersion: "10265"
474-
uid: a35bda6e-a0cc-46d7-a63a-cee765174bc3
475469
spec:
476470
jsonPatches:
477471
- name: default/eg/http

test/e2e/testdata/envoy-patch-policy.yaml

Lines changed: 112 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ metadata:
66
namespace: gateway-conformance-infra
77
spec:
88
parentRefs:
9-
- name: same-namespace
9+
- name: same-namespace
1010
rules:
11-
- backendRefs:
12-
- name: infra-backend-v1
13-
port: 8080
14-
matches:
15-
- path:
16-
type: PathPrefix
17-
value: /foo
11+
- backendRefs:
12+
- name: infra-backend-v1
13+
port: 8080
14+
matches:
15+
- path:
16+
type: PathPrefix
17+
value: /epp
1818
---
1919
apiVersion: gateway.envoyproxy.io/v1alpha1
2020
kind: EnvoyPatchPolicy
@@ -28,20 +28,107 @@ spec:
2828
name: same-namespace
2929
type: JSONPatch
3030
jsonPatches:
31-
- type: "type.googleapis.com/envoy.config.listener.v3.Listener"
32-
name: "gateway-conformance-infra/same-namespace/http"
33-
operation:
34-
op: add
35-
path: "/default_filter_chain/filters/0/typed_config/local_reply_config"
36-
value:
37-
mappers:
38-
- filter:
39-
status_code_filter:
40-
comparison:
41-
op: EQ
42-
value:
43-
default_value: 404
44-
runtime_key: key_b
45-
status_code: 406
46-
body:
47-
inline_string: "not acceptable"
31+
- type: "type.googleapis.com/envoy.config.listener.v3.Listener"
32+
name: "gateway-conformance-infra/same-namespace/http"
33+
operation:
34+
op: add
35+
path: "/default_filter_chain/filters/0/typed_config/local_reply_config"
36+
value:
37+
mappers:
38+
- filter:
39+
status_code_filter:
40+
comparison:
41+
op: EQ
42+
value:
43+
default_value: 404
44+
runtime_key: key_b
45+
status_code: 406
46+
body:
47+
inline_string: "not acceptable"
48+
---
49+
apiVersion: gateway.networking.k8s.io/v1
50+
kind: Gateway
51+
metadata:
52+
name: epp-gateways
53+
namespace: gateway-conformance-infra
54+
spec:
55+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
56+
listeners:
57+
- name: http
58+
port: 80
59+
protocol: HTTP
60+
allowedRoutes:
61+
namespaces:
62+
from: Same
63+
- name: http-8080
64+
port: 8080
65+
protocol: HTTP
66+
allowedRoutes:
67+
namespaces:
68+
from: Same
69+
---
70+
apiVersion: gateway.networking.k8s.io/v1
71+
kind: HTTPRoute
72+
metadata:
73+
name: epp-http
74+
namespace: gateway-conformance-infra
75+
spec:
76+
parentRefs:
77+
- name: epp-gateways
78+
sectionName: http
79+
rules:
80+
- backendRefs:
81+
- name: infra-backend-v2
82+
port: 8080
83+
matches:
84+
- path:
85+
type: PathPrefix
86+
value: /epp
87+
---
88+
apiVersion: gateway.networking.k8s.io/v1
89+
kind: HTTPRoute
90+
metadata:
91+
name: epp-http-8080
92+
namespace: gateway-conformance-infra
93+
spec:
94+
parentRefs:
95+
- name: epp-gateways
96+
sectionName: http-8080
97+
rules:
98+
- backendRefs:
99+
- name: infra-backend-v3
100+
port: 8080
101+
matches:
102+
- path:
103+
type: PathPrefix
104+
value: /epp
105+
---
106+
apiVersion: gateway.envoyproxy.io/v1alpha1
107+
kind: EnvoyPatchPolicy
108+
metadata:
109+
name: custom-response-all-listeners
110+
namespace: gateway-conformance-infra
111+
spec:
112+
targetRef:
113+
group: gateway.networking.k8s.io
114+
kind: Gateway
115+
name: epp-gateways
116+
type: JSONPatch
117+
jsonPatches:
118+
- type: "type.googleapis.com/envoy.config.listener.v3.Listener"
119+
name: ""
120+
operation:
121+
op: add
122+
path: "/default_filter_chain/filters/0/typed_config/local_reply_config"
123+
value:
124+
mappers:
125+
- filter:
126+
status_code_filter:
127+
comparison:
128+
op: EQ
129+
value:
130+
default_value: 404
131+
runtime_key: key_b
132+
status_code: 406
133+
body:
134+
inline_string: "not acceptable"

test/e2e/tests/envoy_patch_policy.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package tests
99

1010
import (
11+
stdnet "net"
1112
"testing"
1213

1314
"k8s.io/apimachinery/pkg/types"
@@ -26,33 +27,45 @@ var EnvoyPatchPolicyTest = suite.ConformanceTest{
2627
Description: "update xds using EnvoyPatchPolicy",
2728
Manifests: []string{"testdata/envoy-patch-policy.yaml"},
2829
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
29-
t.Run("envoy patch policy", func(t *testing.T) {
30-
testEnvoyPatchPolicy(t, suite)
30+
t.Run("With name", func(t *testing.T) {
31+
testEnvoyPatchPolicy(t, suite, "same-namespace", "http-envoy-patch-policy", "infra-backend-v1")
32+
})
33+
t.Run("Without name", func(t *testing.T) {
34+
testEnvoyPatchPolicy(t, suite, "epp-gateways", "epp-http", "infra-backend-v2")
35+
testEnvoyPatchPolicyWithPort(t, suite, "epp-gateways", "epp-http-8080", "infra-backend-v3", "8080")
3136
})
3237
},
3338
}
3439

35-
func testEnvoyPatchPolicy(t *testing.T, suite *suite.ConformanceTestSuite) {
40+
func testEnvoyPatchPolicy(t *testing.T, suite *suite.ConformanceTestSuite, gwName, routeName, backendName string) {
41+
testEnvoyPatchPolicyWithPort(t, suite, gwName, routeName, backendName, "")
42+
}
43+
44+
func testEnvoyPatchPolicyWithPort(t *testing.T, suite *suite.ConformanceTestSuite, gwName, routeName, backendName, gwPort string) {
3645
ns := "gateway-conformance-infra"
37-
routeNN := types.NamespacedName{Name: "http-envoy-patch-policy", Namespace: ns}
38-
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
46+
routeNN := types.NamespacedName{Name: routeName, Namespace: ns}
47+
gwNN := types.NamespacedName{Name: gwName, Namespace: ns}
3948
gwAddr := kubernetes.GatewayAndRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), &gwapiv1.HTTPRoute{}, false, routeNN)
40-
OkResp := http.ExpectedResponse{
49+
if gwPort != "" {
50+
gwAddr = stdnet.JoinHostPort(gwAddr, gwPort)
51+
}
52+
okResp := http.ExpectedResponse{
4153
Request: http.Request{
42-
Path: "/foo",
54+
Path: "/epp",
4355
},
4456
Response: http.Response{
4557
StatusCodes: []int{200},
4658
},
59+
Backend: backendName,
4760
Namespace: ns,
4861
}
4962

5063
// Send a request to a valid path and expect a successful response
51-
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, OkResp)
64+
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, okResp)
5265

5366
customResp := http.ExpectedResponse{
5467
Request: http.Request{
55-
Path: "/bar",
68+
Path: "/not-exist-path",
5669
},
5770
Response: http.Response{
5871
StatusCodes: []int{406},

test/e2e/tests/envoy_patch_policy_xds_name_scheme_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var EnvoyPatchPolicyXDSNameSchemeV2Test = suite.ConformanceTest{
2323
Manifests: []string{"testdata/envoy-patch-policy-xds-name-scheme-v2.yaml"},
2424
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
2525
t.Run("envoy patch policy", func(t *testing.T) {
26-
testEnvoyPatchPolicy(t, suite)
26+
testEnvoyPatchPolicy(t, suite, "same-namespace", "http-envoy-patch-policy", "infra-backend-v1")
2727
})
2828
},
2929
}

0 commit comments

Comments
 (0)