@@ -9,6 +9,7 @@ package tests
99
1010import (
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
3438func 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