Skip to content

Commit 115ca97

Browse files
committed
add tls test
Signed-off-by: Huabing (Robin) Zhao <zhaohuabing@gmail.com>
1 parent bf2cc88 commit 115ca97

File tree

2 files changed

+116
-1
lines changed

2 files changed

+116
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: gateway.networking.x-k8s.io/v1alpha1
2+
kind: XListenerSet
3+
metadata:
4+
name: xlistener-set-tls
5+
namespace: gateway-conformance-infra
6+
spec:
7+
parentRef:
8+
name: xlistener-gateway
9+
namespace: gateway-conformance-infra
10+
listeners:
11+
- name: extra-tls
12+
port: 18444
13+
protocol: TLS
14+
hostname: "*.example.com"
15+
tls:
16+
mode: Passthrough
17+
allowedRoutes:
18+
namespaces:
19+
from: Same
20+
kinds:
21+
- kind: TLSRoute
22+
group: gateway.networking.k8s.io
23+
---
24+
apiVersion: gateway.networking.k8s.io/v1alpha2
25+
kind: TLSRoute
26+
metadata:
27+
name: xlistener-tlsroute
28+
namespace: gateway-conformance-infra
29+
spec:
30+
parentRefs:
31+
- group: gateway.networking.x-k8s.io
32+
kind: XListenerSet
33+
namespace: gateway-conformance-infra
34+
name: xlistener-set-tls
35+
sectionName: extra-tls
36+
hostnames:
37+
- "tls.example.com"
38+
rules:
39+
- backendRefs:
40+
- name: tls-backend
41+
port: 10443

test/e2e/tests/xlistenerset.go

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package tests
99

1010
import (
1111
"context"
12+
"fmt"
1213
"net"
1314
"testing"
1415
"time"
@@ -18,9 +19,12 @@ import (
1819
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1920
"k8s.io/apimachinery/pkg/types"
2021
"k8s.io/apimachinery/pkg/util/wait"
22+
"sigs.k8s.io/controller-runtime/pkg/client"
2123
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
24+
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
2225
gwapixv1a1 "sigs.k8s.io/gateway-api/apisx/v1alpha1"
2326
"sigs.k8s.io/gateway-api/conformance/echo-basic/grpcechoserver"
27+
"sigs.k8s.io/gateway-api/conformance/utils/config"
2428
"sigs.k8s.io/gateway-api/conformance/utils/grpc"
2529
"sigs.k8s.io/gateway-api/conformance/utils/http"
2630
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
@@ -32,7 +36,8 @@ import (
3236
)
3337

3438
func init() {
35-
ConformanceTests = append(ConformanceTests, XListenerSetHTTPTest, XListenerSetHTTPSTest, XListenerSetGRPCTest, XListenerSetTCPTest, XListenerSetUDPTest)
39+
ConformanceTests = append(ConformanceTests, XListenerSetHTTPTest, XListenerSetHTTPSTest,
40+
XListenerSetGRPCTest, XListenerSetTCPTest, XListenerSetUDPTest, XListenerSetTLSTest)
3641
}
3742

3843
// getListenerAddr extracts the host from a gateway address and joins it with a port
@@ -264,3 +269,72 @@ var XListenerSetUDPTest = suite.ConformanceTest{
264269
}
265270
},
266271
}
272+
273+
var XListenerSetTLSTest = suite.ConformanceTest{
274+
ShortName: "XListenerSetTLS",
275+
Description: "TLSRoute should attach to an XListenerSet TLS listener and serve traffic",
276+
Manifests: []string{
277+
"testdata/xlistenerset-base.yaml",
278+
"testdata/xlistenerset-tls.yaml",
279+
},
280+
Test: func(t *testing.T, suite *suite.ConformanceTestSuite) {
281+
ns := "gateway-conformance-infra"
282+
gwNN := types.NamespacedName{Name: "xlistener-gateway", Namespace: ns}
283+
routeNN := types.NamespacedName{Name: "xlistener-tlsroute", Namespace: ns}
284+
285+
gwAddrWithPort, err := kubernetes.WaitForGatewayAddress(t, suite.Client, suite.TimeoutConfig, kubernetes.NewGatewayRef(gwNN, "core"))
286+
require.NoError(t, err)
287+
288+
listenerAddr := getListenerAddr(gwAddrWithPort, "18444")
289+
parents := []gwapiv1.RouteParentStatus{
290+
createXListenerSetParent(suite.ControllerName, "xlistener-set-tls", "extra-tls"),
291+
}
292+
293+
TLSRouteMustHaveParents(t, suite.Client, &suite.TimeoutConfig, routeNN, parents)
294+
295+
expected := http.ExpectedResponse{
296+
Request: http.Request{
297+
Host: "tls.example.com",
298+
Path: "/",
299+
},
300+
Response: http.Response{
301+
StatusCodes: []int{200},
302+
},
303+
Namespace: ns,
304+
}
305+
306+
req := http.MakeRequest(t, &expected, listenerAddr, "HTTPS", "https")
307+
308+
certNN := types.NamespacedName{Name: "backend-tls-certificate", Namespace: ns}
309+
cPem, keyPem, _, err := GetTLSSecret(suite.Client, certNN)
310+
require.NoError(t, err)
311+
312+
WaitForConsistentMTLSResponse(
313+
t,
314+
suite.RoundTripper,
315+
&req,
316+
&expected,
317+
suite.TimeoutConfig.RequiredConsecutiveSuccesses,
318+
suite.TimeoutConfig.MaxTimeToConsistency,
319+
cPem,
320+
keyPem,
321+
"tls.example.com")
322+
},
323+
}
324+
325+
// TLSRouteMustHaveParents waits for the TLSRoute to have parents matching the expected parents
326+
func TLSRouteMustHaveParents(t *testing.T, client client.Client, timeoutConfig *config.TimeoutConfig, routeName types.NamespacedName, parents []gwapiv1.RouteParentStatus) {
327+
t.Helper()
328+
var actual []gwapiv1.RouteParentStatus
329+
waitErr := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, timeoutConfig.RouteMustHaveParents, true, func(ctx context.Context) (bool, error) {
330+
route := &gwapiv1a2.TLSRoute{}
331+
err := client.Get(ctx, routeName, route)
332+
if err != nil {
333+
return false, fmt.Errorf("error fetching TLSRoute: %w", err)
334+
}
335+
336+
actual = route.Status.Parents
337+
return parentsForRouteMatch(t, routeName, parents, actual, false), nil
338+
})
339+
require.NoErrorf(t, waitErr, "error waiting for TLSRoute to have parents matching expectations")
340+
}

0 commit comments

Comments
 (0)