Skip to content

Commit 82b0822

Browse files
committed
conformance: TLSRoute simple Terminate mode
1 parent 530c1ee commit 82b0822

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright 2025 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package tests
18+
19+
import (
20+
"testing"
21+
22+
"k8s.io/apimachinery/pkg/types"
23+
24+
"sigs.k8s.io/gateway-api/conformance/utils/http"
25+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
26+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
27+
"sigs.k8s.io/gateway-api/conformance/utils/tls"
28+
"sigs.k8s.io/gateway-api/pkg/features"
29+
)
30+
31+
func init() {
32+
ConformanceTests = append(ConformanceTests, TLSRouteTerminateSimpleSameNamespace)
33+
}
34+
35+
var TLSRouteTerminateSimpleSameNamespace = suite.ConformanceTest{
36+
ShortName: "TLSRouteTerminateSimpleSameNamespace",
37+
Description: "A single TLSRoute in the gateway-conformance-infra namespace attaches to a Gateway using Terminate mode in the same namespace",
38+
Features: []features.FeatureName{
39+
features.SupportGateway,
40+
features.SupportTLSRoute,
41+
},
42+
Manifests: []string{"tests/tlsroute-terminate-simple-same-namespace.yaml"},
43+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
44+
ns := "gateway-conformance-infra"
45+
routeNN := types.NamespacedName{Name: "gateway-conformance-infra-test", Namespace: ns}
46+
gwNN := types.NamespacedName{Name: "gateway-tlsroute-terminate", Namespace: ns}
47+
certNN := types.NamespacedName{Name: "tls-checks-certificate", Namespace: ns}
48+
49+
kubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, []string{ns})
50+
51+
gwAddr, hostnames := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, suite.TimeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
52+
if len(hostnames) != 1 {
53+
t.Fatalf("unexpected error in test configuration, found %d hostnames", len(hostnames))
54+
}
55+
serverStr := string(hostnames[0])
56+
57+
cPem, keyPem, err := GetTLSSecret(suite.Client, certNN)
58+
if err != nil {
59+
t.Fatalf("unexpected error finding TLS secret: %v", err)
60+
}
61+
t.Run("Simple TLS request matching TLSRoute should reach infra-backend", func(t *testing.T) {
62+
tls.MakeTLSRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, cPem, keyPem, serverStr,
63+
http.ExpectedResponse{
64+
Request: http.Request{Host: serverStr, Path: "/"},
65+
Backend: "infra-backend-v2",
66+
Namespace: "gateway-conformance-infra",
67+
})
68+
})
69+
},
70+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: gateway.networking.k8s.io/v1alpha3
2+
kind: TLSRoute
3+
metadata:
4+
name: gateway-conformance-infra-test
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRefs:
8+
- name: gateway-tlsroute-terminate
9+
namespace: gateway-conformance-infra
10+
hostnames:
11+
- abc.example.com
12+
rules:
13+
- backendRefs:
14+
- name: infra-backend-v2
15+
port: 8080
16+
---
17+
apiVersion: gateway.networking.k8s.io/v1
18+
kind: Gateway
19+
metadata:
20+
name: gateway-tlsroute-terminate
21+
namespace: gateway-conformance-infra
22+
spec:
23+
gatewayClassName: "{GATEWAY_CLASS_NAME}"
24+
listeners:
25+
- name: https
26+
port: 443
27+
protocol: TLS
28+
hostname: abc.example.com
29+
allowedRoutes:
30+
namespaces:
31+
from: Same
32+
kinds:
33+
- kind: TLSRoute
34+
tls:
35+
mode: Terminate
36+
certificateRefs:
37+
- name: tls-checks-certificate

0 commit comments

Comments
 (0)