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

Backendref httproute filter request redirect #3134

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
Empty file added conformance/tests/http
Empty file.
71 changes: 71 additions & 0 deletions conformance/tests/httproute-filter-request-redirect.go
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,
Copy link
Member

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.

},
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)
})
}
},
}
30 changes: 30 additions & 0 deletions conformance/tests/httproute-filter-request-redirect.yaml
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filter name is just requestRedirect

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
4 changes: 4 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this test is about backend filters, and we already have the SupportHTTPRoute*Redirect features in place, I'd suggest to rename this one to SupportHTTPRouteBackendPathRedirect. The same renaming should be applied to the tests.

)

// HTTPRouteExtendedFeatures includes all extended features for HTTPRoute
Expand All @@ -172,6 +175,7 @@ var HTTPRouteExtendedFeatures = sets.New(
SupportHTTPRouteBackendRequestHeaderModification,
SupportHTTPRouteBackendProtocolH2C,
SupportHTTPRouteBackendProtocolWebSocket,
SupportHTTPRouteFilterRequestRedirect,
)

// -----------------------------------------------------------------------------
Expand Down