-
Notifications
You must be signed in to change notification settings - Fork 482
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
Backendref httproute filter request redirect #3134
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
|
||
"sigs.k8s.io/gateway-api/conformance/utils/http" | ||
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes" | ||
"sigs.k8s.io/gateway-api/conformance/utils/suite" | ||
"sigs.k8s.io/gateway-api/pkg/features" | ||
) | ||
|
||
func init() { | ||
ConformanceTests = append(ConformanceTests, HTTPRouteFilterRequestRedirect) | ||
} | ||
|
||
var HTTPRouteFilterRequestRedirect = suite.ConformanceTest{ | ||
ShortName: "HTTPRouteFilterRequestRedirect", | ||
Description: "A single HTTPRoute with a redirection filter for different backends", | ||
Features: []features.SupportedFeature{ | ||
features.SupportGateway, | ||
features.SupportHTTPRoute, | ||
}, | ||
Manifests: []string{"tests/httproute-filter-request-redirect.yaml"}, | ||
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) { | ||
ns := "gateway-conformance-infra" | ||
routeNN := types.NamespacedName{Name: "filter-request-redirect", Namespace: ns} | ||
gwNN := types.NamespacedName{Name: "same-namespace", Namespace: ns} | ||
gwAddr := kubernetes.GatewayAndHTTPRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN) | ||
kubernetes.HTTPRouteMustHaveResolvedRefsConditionsTrue(t, suite.Client, suite.TimeoutConfig, routeNN, gwNN) | ||
|
||
testCases := []http.ExpectedResponse{{ | ||
Request: http.Request{Path: "/"}, | ||
Backend: "infra-backend-v1", | ||
Namespace: ns, | ||
Response: http.Response{StatusCode: 302, Headers: map[string]string{"Location": "https://gateway-api.sigs.k8s.io"}}, | ||
}, { | ||
Request: http.Request{Path: "/"}, | ||
Backend: "infra-backend-v2", | ||
Namespace: ns, | ||
Response: http.Response{StatusCode: 302, Headers: map[string]string{"Location": "http://www.redirect-example.com"}}, | ||
}} | ||
|
||
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) | ||
}) | ||
} | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: gateway.networking.k8s.io/v1 | ||
kind: HTTPRoute | ||
metadata: | ||
name: filter-request-redirect | ||
namespace: gateway-conformance-infra | ||
spec: | ||
parentRefs: | ||
- name: same-namespace | ||
rules: | ||
- matches: | ||
- path: | ||
type: PathPrefix | ||
value: / | ||
backendRefs: | ||
- name: infra-backend-v1 | ||
port: 8080 | ||
filters: | ||
- type: FilterRequestRedirect | ||
filterRequestRedirect: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the filter name is just |
||
scheme: https | ||
hostname: gateway-api.sigs.k8s.io | ||
port: 443 | ||
- name: infra-backend-v2 | ||
port: 8080 | ||
filters: | ||
- type: FilterRequestRedirect | ||
filterRequestRedirect: | ||
scheme: http | ||
hostname: www.redirect-example.com | ||
port: 80 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,9 @@ const ( | |
|
||
// This option indicates support for HTTPRoute with a backendref with an appProtoocol 'kubernetes.io/ws' (extended conformance) | ||
SupportHTTPRouteBackendProtocolWebSocket SupportedFeature = "HTTPRouteBackendProtocolWebSocket" | ||
|
||
// This option indicates support for HTTPRoute filter request redirect (extended conformance) | ||
SupportHTTPRouteFilterRequestRedirect SupportedFeature = "HTTPRouteFilterRequestRedirect" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this test is about backend filters, and we already have the |
||
) | ||
|
||
// HTTPRouteExtendedFeatures includes all extended features for HTTPRoute | ||
|
@@ -172,6 +175,7 @@ var HTTPRouteExtendedFeatures = sets.New( | |
SupportHTTPRouteBackendRequestHeaderModification, | ||
SupportHTTPRouteBackendProtocolH2C, | ||
SupportHTTPRouteBackendProtocolWebSocket, | ||
SupportHTTPRouteFilterRequestRedirect, | ||
) | ||
|
||
// ----------------------------------------------------------------------------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to add here the new feature
SupportHTTPRouteFilterRequestRedirect
.