Skip to content

Add mesh conformance tests for httproute port and scheme redirect #3776

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

Open
wants to merge 1 commit 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
113 changes: 113 additions & 0 deletions conformance/tests/mesh/httproute-redirect-port.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright 2025 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 meshtests

import (
"testing"

"sigs.k8s.io/gateway-api/conformance/utils/echo"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func init() {
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteRedirectPort)
}

var MeshHTTPRouteRedirectPort = suite.ConformanceTest{
Copy link
Member

Choose a reason for hiding this comment

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

I think I missed this from the earlier conversations, but what's the plan to make these tests more sustainable + maintainable? Would it be viable to just have a simple script that did the copying and modification required for any tests that should be replicated for mesh? Is there a way to share the same test definitions for both?

ShortName: "MeshHTTPRouteRedirectPort",
Description: "An HTTPRoute with a port redirect filter",
Manifests: []string{"tests/mesh/httproute-redirect-port.yaml"},
Features: []features.FeatureName{
features.SupportMesh,
features.SupportHTTPRoute,
features.SupportMeshHTTPRouteRedirectPort,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
ns := "gateway-conformance-mesh"
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)

testCases := []http.ExpectedResponse{
{
Request: http.Request{
Host: "echo",
Path: "/port",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Port: "8083",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/port-and-host",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
Port: "8083",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/port-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Port: "8083",
},
Namespace: ns,
}, {
Request: http.Request{
Host: "echo",
Path: "/port-and-host-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Port: "8083",
Host: "example.org",
},
Namespace: ns,
},
}
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()
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
})
}
},
}
48 changes: 48 additions & 0 deletions conformance/tests/mesh/httproute-redirect-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mesh-redirect-port
namespace: gateway-conformance-mesh
spec:
parentRefs:
- group: ""
kind: Service
name: echo
port: 80
rules:
- matches:
- path:
type: PathPrefix
value: /port
filters:
- type: RequestRedirect
requestRedirect:
port: 8083
- matches:
- path:
type: PathPrefix
value: /port-and-host
filters:
- type: RequestRedirect
requestRedirect:
hostname: example.org
port: 8083
- matches:
- path:
type: PathPrefix
value: /port-and-status
filters:
- type: RequestRedirect
requestRedirect:
port: 8083
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /port-and-host-and-status
filters:
- type: RequestRedirect
requestRedirect:
port: 8083
hostname: example.org
statusCode: 302
116 changes: 116 additions & 0 deletions conformance/tests/mesh/httproute-redirect-scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
Copyright 2025 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 meshtests

import (
"testing"

"sigs.k8s.io/gateway-api/conformance/utils/echo"
"sigs.k8s.io/gateway-api/conformance/utils/http"
"sigs.k8s.io/gateway-api/conformance/utils/roundtripper"
"sigs.k8s.io/gateway-api/conformance/utils/suite"
"sigs.k8s.io/gateway-api/pkg/features"
)

func init() {
MeshConformanceTests = append(MeshConformanceTests, MeshHTTPRouteSchemeRedirect)
}

var MeshHTTPRouteSchemeRedirect = suite.ConformanceTest{
ShortName: "MeshHTTPRouteSchemeRedirect",
Description: "An HTTPRoute with a scheme redirect filter",
Manifests: []string{"tests/mesh/httproute-redirect-scheme.yaml"},
Features: []features.FeatureName{
features.SupportMesh,
features.SupportHTTPRoute,
features.SupportMeshHTTPRouteSchemeRedirect,
},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
ns := "gateway-conformance-mesh"
client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1)

testCases := []http.ExpectedResponse{
{
Request: http.Request{
Host: "echo",
Path: "/scheme",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Scheme: "https",
},
Namespace: ns,
},
{
Request: http.Request{
Host: "echo",
Path: "/scheme-and-host",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
Scheme: "https",
},
Namespace: ns,
},
{
Request: http.Request{
Host: "echo",
Path: "/scheme-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 301,
},
RedirectRequest: &roundtripper.RedirectRequest{
Scheme: "https",
},
Namespace: ns,
},
{
Request: http.Request{
Host: "echo",
Path: "/scheme-and-host-and-status",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 302,
},
RedirectRequest: &roundtripper.RedirectRequest{
Scheme: "https",
Host: "example.org",
},
Namespace: ns,
},
}
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()
client.MakeRequestAndExpectEventuallyConsistentResponse(t, tc, s.TimeoutConfig)
})
}
},
}
49 changes: 49 additions & 0 deletions conformance/tests/mesh/httproute-redirect-scheme.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: mesh-redirect-scheme
namespace: gateway-conformance-mesh
spec:
parentRefs:
- group: ""
kind: Service
name: echo
port: 80
rules:
- matches:
- path:
type: PathPrefix
value: /scheme
filters:
- type: RequestRedirect
requestRedirect:
scheme: "https"
- matches:
- path:
type: PathPrefix
value: /scheme-and-host
filters:
- type: RequestRedirect
requestRedirect:
hostname: example.org
scheme: "https"
- matches:
- path:
type: PathPrefix
value: /scheme-and-status
filters:
- type: RequestRedirect
requestRedirect:
scheme: "https"
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /scheme-and-host-and-status
filters:
- type: RequestRedirect
requestRedirect:
scheme: "https"
statusCode: 302
hostname: example.org

2 changes: 1 addition & 1 deletion conformance/tests/mesh/httproute-rewrite-path.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var MeshHTTPRouteRewritePath = suite.ConformanceTest{
Description: "An HTTPRoute with path rewrite filter",
Features: []features.FeatureName{
features.SupportMesh,
features.SupportMeshHTTPRouteRewritePath,
features.SupportHTTPRoute,
features.SupportMeshHTTPRouteRewritePath,
},
Manifests: []string{"tests/mesh/httproute-rewrite-path.yaml"},
Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
Expand Down
17 changes: 17 additions & 0 deletions pkg/features/mesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const (
SupportMeshConsumerRoute FeatureName = "MeshConsumerRoute"
// This option indicates mesh support for HTTPRoute path rewrite (extended conformance)
SupportMeshHTTPRouteRewritePath FeatureName = "MeshHTTPRouteRewritePath"
// This option indicates mesh support for HTTPRoute scheme redirect (extended conformance)
SupportMeshHTTPRouteSchemeRedirect FeatureName = "MeshHTTPRouteSchemeRedirect"
// This option indicates mesh support for HTTPRoute port redirect (extended conformance)
SupportMeshHTTPRouteRedirectPort FeatureName = "MeshHTTPRouteRedirectPort"
)

var (
Expand All @@ -69,6 +73,18 @@ var (
Name: SupportMeshHTTPRouteRewritePath,
Channel: FeatureChannelStandard,
}

// MeshHTTPRouteSchemeRedirect contains metadata for the MeshHTTPRouteSchemeRedirect feature.
MeshHTTPRouteSchemeRedirect = Feature{
Name: SupportMeshHTTPRouteRewritePath,
Channel: FeatureChannelStandard,
}

// MeshHTTPRouteRedirectPort contains metadata for the MeshHTTPRouteRedirectPort feature.
MeshHTTPRouteRedirectPort = Feature{
Name: SupportMeshHTTPRouteRedirectPort,
Channel: FeatureChannelStandard,
}
)

// MeshExtendedFeatures includes all the supported features for the service mesh at
Expand All @@ -77,4 +93,5 @@ var MeshExtendedFeatures = sets.New(
MeshClusterIPMatchingFeature,
MeshConsumerRouteFeature,
MeshHTTPRouteRewritePath,
MeshHTTPRouteSchemeRedirect,
)