Skip to content

Commit 3f8359f

Browse files
author
Ryan Lymburner
authored
Set hostnames field to required for TLSRoute (#736)
1 parent f5a3a6e commit 3f8359f

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

pkg/gateway/model_build_lattice_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ func (t *latticeServiceModelBuildTask) buildLatticeService(ctx context.Context)
111111
routeType = core.GrpcRouteType
112112
case *core.TLSRoute:
113113
routeType = core.TlsRouteType
114+
// VPC Lattice requires a custom domain name for TLS listeners
115+
if len(t.route.Spec().Hostnames()) == 0 {
116+
return nil, fmt.Errorf("TLSRoute %s/%s must specify at least one hostname as VPC Lattice requires a custom domain name",
117+
t.route.Namespace(), t.route.Name())
118+
}
114119
default:
115120
return nil, fmt.Errorf("unsupported route type: %T", t.route)
116121
}

pkg/gateway/model_build_lattice_service_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
1717
testclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
1818
gwv1 "sigs.k8s.io/gateway-api/apis/v1"
19+
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1920
)
2021

2122
func Test_LatticeServiceModelBuild(t *testing.T) {
@@ -403,6 +404,31 @@ func Test_LatticeServiceModelBuild(t *testing.T) {
403404
ServiceNetworkNames: []string{vpcLatticeGateway.Name, "gateway2"},
404405
},
405406
},
407+
{
408+
name: "TLSRoute without hostname should fail",
409+
wantIsDeleted: false,
410+
wantErrIsNil: false,
411+
gwClass: vpcLatticeGatewayClass,
412+
gws: []gwv1.Gateway{
413+
vpcLatticeGateway,
414+
},
415+
route: core.NewTLSRoute(gwv1alpha2.TLSRoute{
416+
ObjectMeta: metav1.ObjectMeta{
417+
Name: "service1",
418+
Namespace: "default",
419+
},
420+
Spec: gwv1alpha2.TLSRouteSpec{
421+
CommonRouteSpec: gwv1.CommonRouteSpec{
422+
ParentRefs: []gwv1.ParentReference{
423+
{
424+
Name: gwv1.ObjectName(vpcLatticeGateway.Name),
425+
Namespace: namespacePtr(vpcLatticeGateway.Namespace),
426+
},
427+
},
428+
},
429+
},
430+
}),
431+
},
406432
{
407433
name: "Multiple service networks with one different controller",
408434
wantIsDeleted: false,
@@ -463,6 +489,7 @@ func Test_LatticeServiceModelBuild(t *testing.T) {
463489
k8sSchema := runtime.NewScheme()
464490
clientgoscheme.AddToScheme(k8sSchema)
465491
gwv1.Install(k8sSchema)
492+
gwv1alpha2.Install(k8sSchema)
466493
k8sClient := testclient.NewClientBuilder().WithScheme(k8sSchema).Build()
467494

468495
assert.NoError(t, k8sClient.Create(ctx, tt.gwClass.DeepCopy()))

0 commit comments

Comments
 (0)