Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPBackendRef RequestMirror Conformance Test #2819

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions conformance/tests/httproute-request-mirror-backend.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: request-mirror
namespace: gateway-conformance-infra
spec:
parentRefs:
- name: same-namespace
rules:
- backendRefs:
- name: infra-backend-v1
namespace: gateway-conformance-infra
port: 8080
filters:
- type: RequestMirror
requestMirror:
backendRef:
name: infra-backend-v2
namespace: gateway-conformance-infra
port: 8080
140 changes: 81 additions & 59 deletions conformance/tests/httproute-request-mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,24 @@ import (
)

func init() {
ConformanceTests = append(ConformanceTests, HTTPRouteRequestMirror)
ConformanceTests = append(ConformanceTests,
HTTPRouteRequestMirror,
HTTPRouteBackendRequestMirror,
)
}

var HTTPRouteBackendRequestMirror = suite.ConformanceTest{
ShortName: "HTTPRouteBackendRequestMirror",
Description: "An HTTPRoute backendRef with request mirror filter",
Manifests: []string{"tests/httproute-request-mirror-backend.yaml"},
Features: []features.SupportedFeature{
features.SupportGateway,
features.SupportHTTPRoute,
features.SupportHTTPRouteBackendRequestMirror,
},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
RunHTTPRouteRequestMirrorTest(t, suite, HTTPRouteRequestMirrorTestCases)
},
}

var HTTPRouteRequestMirror = suite.ConformanceTest{
Expand All @@ -41,64 +58,69 @@ var HTTPRouteRequestMirror = suite.ConformanceTest{
features.SupportHTTPRouteRequestMirror,
},
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "request-mirror", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
RunHTTPRouteRequestMirrorTest(t, suite, HTTPRouteRequestMirrorTestCases)
RunHTTPRouteRequestMirrorTest(t, suite, HTTPRouteRequestMirrorAndModifyRequestHeaderTestCases)
},
}

testCases := []http.ExpectedResponse{
{
Request: http.Request{
Path: "/mirror",
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/mirror",
},
},
Backend: "infra-backend-v1",
MirroredTo: []http.BackendRef{{
Name: "infra-backend-v2",
Namespace: ns,
}},
Namespace: ns,
},
{
Request: http.Request{
Path: "/mirror-and-modify-headers",
Headers: map[string]string{
"X-Header-Remove": "remove-val",
"X-Header-Add-Append": "append-val-1",
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/mirror-and-modify-headers",
Headers: map[string]string{
"X-Header-Add": "header-val-1",
"X-Header-Add-Append": "append-val-1,header-val-2",
"X-Header-Set": "set-overwrites-values",
},
},
AbsentHeaders: []string{"X-Header-Remove"},
},
Namespace: ns,
Backend: "infra-backend-v1",
MirroredTo: []http.BackendRef{{
Name: "infra-backend-v2",
Namespace: ns,
}},
func RunHTTPRouteRequestMirrorTest(t *testing.T, suite *suite.ConformanceTestSuite, testCases []http.ExpectedResponse) {
ns := "gateway-conformance-infra"
routeNN := types.NamespacedName{Name: "request-mirror", Namespace: ns}
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns}
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)

for i := range testCases {
// Declare tc here to avoid loop variable
// reuse issues across parallel tests.
tc := testCases[i]
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
t.Parallel()
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
http.ExpectMirroredRequest(t, suite.Client, suite.Clientset, tc.MirroredTo, tc.Request.Path)
})
}
}

var HTTPRouteRequestMirrorTestCases = []http.ExpectedResponse{{
Request: http.Request{
Path: "/mirror",
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/mirror",
},
},
Backend: "infra-backend-v1",
MirroredTo: []http.BackendRef{{
Name: "infra-backend-v2",
Namespace: "gateway-conformance-infra",
}},
Namespace: "gateway-conformance-infra",
}}

var HTTPRouteRequestMirrorAndModifyRequestHeaderTestCases = []http.ExpectedResponse{{
Request: http.Request{
Path: "/mirror-and-modify-headers",
Headers: map[string]string{
"X-Header-Remove": "remove-val",
"X-Header-Add-Append": "append-val-1",
},
},
ExpectedRequest: &http.ExpectedRequest{
Request: http.Request{
Path: "/mirror-and-modify-headers",
Headers: map[string]string{
"X-Header-Add": "header-val-1",
"X-Header-Add-Append": "append-val-1,header-val-2",
"X-Header-Set": "set-overwrites-values",
},
}
for i := range testCases {
// Declare tc here to avoid loop variable
// reuse issues across parallel tests.
tc := testCases[i]
t.Run(tc.GetTestCaseName(i), func(t *testing.T) {
t.Parallel()
http.MakeRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, tc)
http.ExpectMirroredRequest(t, suite.Client, suite.Clientset, tc.MirroredTo, tc.Request.Path)
})
}
},
AbsentHeaders: []string{"X-Header-Remove"},
},
}
Namespace: "gateway-conformance-infra",
Backend: "infra-backend-v1",
MirroredTo: []http.BackendRef{{
Name: "infra-backend-v2",
Namespace: "gateway-conformance-infra",
}},
}}
4 changes: 4 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ const (
// This option indicates support for HTTPRoute request mirror (extended conformance).
SupportHTTPRouteRequestMirror SupportedFeature = "HTTPRouteRequestMirror"

// This option indicates support for HTTPRoute backend request mirror (extended conformance).
SupportHTTPRouteBackendRequestMirror SupportedFeature = "HTTPRouteBackendRequestMirror"

// This option indicates support for multiple RequestMirror filters within the same HTTPRoute rule (extended conformance).
SupportHTTPRouteRequestMultipleMirrors SupportedFeature = "HTTPRouteRequestMultipleMirrors"

Expand All @@ -154,6 +157,7 @@ var HTTPRouteExtendedFeatures = sets.New(
SupportHTTPRouteHostRewrite,
SupportHTTPRoutePathRewrite,
SupportHTTPRouteRequestMirror,
SupportHTTPRouteBackendRequestMirror,
SupportHTTPRouteRequestMultipleMirrors,
SupportHTTPRouteRequestTimeout,
SupportHTTPRouteBackendTimeout,
Expand Down