Skip to content

Commit 3e280d9

Browse files
committed
init
1 parent 530c1ee commit 3e280d9

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
"time"
22+
23+
"k8s.io/apimachinery/pkg/types"
24+
25+
"sigs.k8s.io/gateway-api/conformance/utils/config"
26+
"sigs.k8s.io/gateway-api/conformance/utils/http"
27+
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
28+
"sigs.k8s.io/gateway-api/conformance/utils/suite"
29+
"sigs.k8s.io/gateway-api/conformance/utils/tls"
30+
"sigs.k8s.io/gateway-api/pkg/features"
31+
)
32+
33+
func init() {
34+
ConformanceTests = append(ConformanceTests, TLSRouteTerminateSimpleSameNamespace)
35+
}
36+
37+
var TLSRouteTerminateSimpleSameNamespace = suite.ConformanceTest{
38+
ShortName: "TLSRouteTerminateSimpleSameNamespace",
39+
Description: "A single TLSRoute in the gateway-conformance-infra namespace attaches to a Gateway using Terminate mode in the same namespace",
40+
Features: []features.FeatureName{
41+
features.SupportGateway,
42+
features.SupportTLSRoute,
43+
},
44+
Manifests: []string{"tests/tlsroute-terminate-simple-same-namespace.yaml"},
45+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
46+
ns := "gateway-conformance-infra"
47+
routeNN := types.NamespacedName{Name: "gateway-conformance-infra-test", Namespace: ns}
48+
gwNN := types.NamespacedName{Name: "gateway-tlsroute-terminate", Namespace: ns}
49+
certNN := types.NamespacedName{Name: "tls-checks-certificate", Namespace: ns}
50+
51+
timeoutConfig := config.DefaultTimeoutConfig()
52+
timeoutConfig.RouteMustHaveParents = 5 * time.Minute
53+
54+
kubernetes.NamespacesMustBeReady(t, suite.Client, suite.TimeoutConfig, []string{ns})
55+
56+
gwAddr, hostnames := kubernetes.GatewayAndTLSRoutesMustBeAccepted(t, suite.Client, timeoutConfig, suite.ControllerName, kubernetes.NewGatewayRef(gwNN), routeNN)
57+
if len(hostnames) != 1 {
58+
t.Fatalf("unexpected error in test configuration, found %d hostnames", len(hostnames))
59+
}
60+
serverStr := string(hostnames[0])
61+
62+
cPem, keyPem, err := GetTLSSecret(suite.Client, certNN)
63+
if err != nil {
64+
t.Fatalf("unexpected error finding TLS secret: %v", err)
65+
}
66+
t.Run("Simple TLS request matching TLSRoute should reach infra-backend", func(t *testing.T) {
67+
tls.MakeTLSRequestAndExpectEventuallyConsistentResponse(t, suite.RoundTripper, suite.TimeoutConfig, gwAddr, cPem, keyPem, serverStr,
68+
http.ExpectedResponse{
69+
Request: http.Request{Host: serverStr, Path: "/"},
70+
Backend: "tls-backend",
71+
Namespace: "gateway-conformance-infra",
72+
})
73+
})
74+
},
75+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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: tls-backend
15+
port: 443
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: "*.example.com"
29+
allowedRoutes:
30+
namespaces:
31+
from: Same
32+
kinds:
33+
- kind: TLSRoute
34+
tls:
35+
mode: Terminate
36+
certificateRefs:
37+
- group: ""
38+
kind: Secret
39+
name: tls-checks-certificate

0 commit comments

Comments
 (0)