@@ -262,6 +262,9 @@ func TestBindRouteToListeners(t *testing.T) {
262
262
Namespace : "test" ,
263
263
Name : "hr" ,
264
264
},
265
+ TypeMeta : metav1.TypeMeta {
266
+ Kind : "HTTPRoute" ,
267
+ },
265
268
Spec : gatewayv1.HTTPRouteSpec {
266
269
CommonRouteSpec : gatewayv1.CommonRouteSpec {
267
270
ParentRefs : []gatewayv1.ParentReference {
@@ -291,9 +294,9 @@ func TestBindRouteToListeners(t *testing.T) {
291
294
nil ,
292
295
)
293
296
294
- var normalRoute * L7Route
295
- createNormalRoute := func (gateway * gatewayv1.Gateway ) * L7Route {
296
- normalRoute = & L7Route {
297
+ var normalHTTPRoute * L7Route
298
+ createNormalHTTPRoute := func (gateway * gatewayv1.Gateway ) * L7Route {
299
+ normalHTTPRoute = & L7Route {
297
300
RouteType : RouteTypeHTTP ,
298
301
Source : hr ,
299
302
Spec : L7RouteSpec {
@@ -309,10 +312,11 @@ func TestBindRouteToListeners(t *testing.T) {
309
312
},
310
313
},
311
314
}
312
- return normalRoute
315
+ return normalHTTPRoute
313
316
}
314
- getLastNormalRoute := func () * L7Route {
315
- return normalRoute
317
+
318
+ getLastNormalHTTPRoute := func () * L7Route {
319
+ return normalHTTPRoute
316
320
}
317
321
318
322
invalidAttachableRoute1 := & L7Route {
@@ -430,6 +434,62 @@ func TestBindRouteToListeners(t *testing.T) {
430
434
l .Source .Hostname = helpers.GetPointer [gatewayv1.Hostname ]("bar.example.com" )
431
435
})
432
436
437
+ createGRPCRouteWithSectionNameAndPort := func (
438
+ sectionName * gatewayv1.SectionName ,
439
+ port * gatewayv1.PortNumber ,
440
+ ) * gatewayv1.GRPCRoute {
441
+ return & gatewayv1.GRPCRoute {
442
+ ObjectMeta : metav1.ObjectMeta {
443
+ Namespace : "test" ,
444
+ Name : "hr" ,
445
+ },
446
+ TypeMeta : metav1.TypeMeta {
447
+ Kind : "GRPCRoute" ,
448
+ },
449
+ Spec : gatewayv1.GRPCRouteSpec {
450
+ CommonRouteSpec : gatewayv1.CommonRouteSpec {
451
+ ParentRefs : []gatewayv1.ParentReference {
452
+ {
453
+ Name : gatewayv1 .ObjectName (gw .Name ),
454
+ SectionName : sectionName ,
455
+ Port : port ,
456
+ },
457
+ },
458
+ },
459
+ Hostnames : []gatewayv1.Hostname {
460
+ "foo.example.com" ,
461
+ },
462
+ },
463
+ }
464
+ }
465
+
466
+ gr := createGRPCRouteWithSectionNameAndPort (helpers.GetPointer [gatewayv1.SectionName ]("listener-80-1" ), nil )
467
+
468
+ var normalGRPCRoute * L7Route
469
+ createNormalGRPCRoute := func (gateway * gatewayv1.Gateway ) * L7Route {
470
+ normalGRPCRoute = & L7Route {
471
+ RouteType : RouteTypeGRPC ,
472
+ Source : gr ,
473
+ Spec : L7RouteSpec {
474
+ Hostnames : gr .Spec .Hostnames ,
475
+ },
476
+ Valid : true ,
477
+ Attachable : true ,
478
+ ParentRefs : []ParentRef {
479
+ {
480
+ Idx : 0 ,
481
+ Gateway : client .ObjectKeyFromObject (gateway ),
482
+ SectionName : gr .Spec .ParentRefs [0 ].SectionName ,
483
+ },
484
+ },
485
+ }
486
+ return normalGRPCRoute
487
+ }
488
+
489
+ getLastNormalGRPCRoute := func () * L7Route {
490
+ return normalGRPCRoute
491
+ }
492
+
433
493
tests := []struct {
434
494
route * L7Route
435
495
gateway * Gateway
@@ -439,7 +499,7 @@ func TestBindRouteToListeners(t *testing.T) {
439
499
expectedConditions []conditions.Condition
440
500
}{
441
501
{
442
- route : createNormalRoute (gw ),
502
+ route : createNormalHTTPRoute (gw ),
443
503
gateway : & Gateway {
444
504
Source : gw ,
445
505
Valid : true ,
@@ -463,7 +523,7 @@ func TestBindRouteToListeners(t *testing.T) {
463
523
expectedGatewayListeners : []* Listener {
464
524
createModifiedListener ("listener-80-1" , func (l * Listener ) {
465
525
l .Routes = map [RouteKey ]* L7Route {
466
- CreateRouteKey (hr ): getLastNormalRoute (),
526
+ CreateRouteKey (hr ): getLastNormalHTTPRoute (),
467
527
}
468
528
}),
469
529
},
@@ -620,7 +680,7 @@ func TestBindRouteToListeners(t *testing.T) {
620
680
name : "listener doesn't exist" ,
621
681
},
622
682
{
623
- route : createNormalRoute (gw ),
683
+ route : createNormalHTTPRoute (gw ),
624
684
gateway : & Gateway {
625
685
Source : gw ,
626
686
Valid : true ,
@@ -646,7 +706,7 @@ func TestBindRouteToListeners(t *testing.T) {
646
706
name : "listener isn't valid and attachable" ,
647
707
},
648
708
{
649
- route : createNormalRoute (gw ),
709
+ route : createNormalHTTPRoute (gw ),
650
710
gateway : & Gateway {
651
711
Source : gw ,
652
712
Valid : true ,
@@ -720,7 +780,7 @@ func TestBindRouteToListeners(t *testing.T) {
720
780
name : "route isn't valid" ,
721
781
},
722
782
{
723
- route : createNormalRoute (gw ),
783
+ route : createNormalHTTPRoute (gw ),
724
784
gateway : & Gateway {
725
785
Source : gw ,
726
786
Valid : false ,
@@ -746,7 +806,7 @@ func TestBindRouteToListeners(t *testing.T) {
746
806
name : "invalid gateway" ,
747
807
},
748
808
{
749
- route : createNormalRoute (gw ),
809
+ route : createNormalHTTPRoute (gw ),
750
810
gateway : & Gateway {
751
811
Source : gw ,
752
812
Valid : true ,
@@ -773,7 +833,7 @@ func TestBindRouteToListeners(t *testing.T) {
773
833
createModifiedListener ("listener-80-1" , func (l * Listener ) {
774
834
l .Valid = false
775
835
l .Routes = map [RouteKey ]* L7Route {
776
- CreateRouteKey (hr ): getLastNormalRoute (),
836
+ CreateRouteKey (hr ): getLastNormalHTTPRoute (),
777
837
}
778
838
}),
779
839
},
@@ -847,7 +907,7 @@ func TestBindRouteToListeners(t *testing.T) {
847
907
name : "invalid attachable listener with invalid attachable route" ,
848
908
},
849
909
{
850
- route : createNormalRoute (gw ),
910
+ route : createNormalHTTPRoute (gw ),
851
911
gateway : & Gateway {
852
912
Source : gw ,
853
913
Valid : true ,
@@ -889,7 +949,7 @@ func TestBindRouteToListeners(t *testing.T) {
889
949
name : "route not allowed via labels" ,
890
950
},
891
951
{
892
- route : createNormalRoute (gw ),
952
+ route : createNormalHTTPRoute (gw ),
893
953
gateway : & Gateway {
894
954
Source : gw ,
895
955
Valid : true ,
@@ -928,14 +988,14 @@ func TestBindRouteToListeners(t *testing.T) {
928
988
},
929
989
}
930
990
l .Routes = map [RouteKey ]* L7Route {
931
- CreateRouteKey (hr ): getLastNormalRoute (),
991
+ CreateRouteKey (hr ): getLastNormalHTTPRoute (),
932
992
}
933
993
}),
934
994
},
935
995
name : "route allowed via labels" ,
936
996
},
937
997
{
938
- route : createNormalRoute (gwDiffNamespace ),
998
+ route : createNormalHTTPRoute (gwDiffNamespace ),
939
999
gateway : & Gateway {
940
1000
Source : gwDiffNamespace ,
941
1001
Valid : true ,
@@ -973,7 +1033,7 @@ func TestBindRouteToListeners(t *testing.T) {
973
1033
name : "route not allowed via same namespace" ,
974
1034
},
975
1035
{
976
- route : createNormalRoute (gw ),
1036
+ route : createNormalHTTPRoute (gw ),
977
1037
gateway : & Gateway {
978
1038
Source : gw ,
979
1039
Valid : true ,
@@ -1008,14 +1068,14 @@ func TestBindRouteToListeners(t *testing.T) {
1008
1068
},
1009
1069
}
1010
1070
l .Routes = map [RouteKey ]* L7Route {
1011
- CreateRouteKey (hr ): getLastNormalRoute (),
1071
+ CreateRouteKey (hr ): getLastNormalHTTPRoute (),
1012
1072
}
1013
1073
}),
1014
1074
},
1015
1075
name : "route allowed via same namespace" ,
1016
1076
},
1017
1077
{
1018
- route : createNormalRoute (gwDiffNamespace ),
1078
+ route : createNormalHTTPRoute (gwDiffNamespace ),
1019
1079
gateway : & Gateway {
1020
1080
Source : gwDiffNamespace ,
1021
1081
Valid : true ,
@@ -1050,12 +1110,95 @@ func TestBindRouteToListeners(t *testing.T) {
1050
1110
},
1051
1111
}
1052
1112
l .Routes = map [RouteKey ]* L7Route {
1053
- CreateRouteKey (hr ): getLastNormalRoute (),
1113
+ CreateRouteKey (hr ): getLastNormalHTTPRoute (),
1054
1114
}
1055
1115
}),
1056
1116
},
1057
1117
name : "route allowed via all namespaces" ,
1058
1118
},
1119
+ {
1120
+ route : createNormalHTTPRoute (gw ),
1121
+ gateway : & Gateway {
1122
+ Source : gw ,
1123
+ Valid : true ,
1124
+ Listeners : []* Listener {
1125
+ createModifiedListener ("listener-80-1" , func (l * Listener ) {
1126
+ l .Source .AllowedRoutes = & gatewayv1.AllowedRoutes {
1127
+ Kinds : []gatewayv1.RouteGroupKind {
1128
+ {Kind : "GRPCRoute" },
1129
+ },
1130
+ }
1131
+ }),
1132
+ },
1133
+ },
1134
+ expectedSectionNameRefs : []ParentRef {
1135
+ {
1136
+ Idx : 0 ,
1137
+ Gateway : client .ObjectKeyFromObject (gw ),
1138
+ SectionName : hr .Spec .ParentRefs [0 ].SectionName ,
1139
+ Attachment : & ParentRefAttachmentStatus {
1140
+ Attached : false ,
1141
+ FailedCondition : staticConds .NewRouteNotAllowedByListeners (),
1142
+ AcceptedHostnames : map [string ][]string {},
1143
+ },
1144
+ },
1145
+ },
1146
+ expectedGatewayListeners : []* Listener {
1147
+ createModifiedListener ("listener-80-1" , func (l * Listener ) {
1148
+ l .Source .AllowedRoutes = & gatewayv1.AllowedRoutes {
1149
+ Kinds : []gatewayv1.RouteGroupKind {
1150
+ {Kind : "GRPCRoute" },
1151
+ },
1152
+ }
1153
+ }),
1154
+ },
1155
+ name : "http route not allowed when listener allows only grpc routes" ,
1156
+ },
1157
+ {
1158
+ route : createNormalGRPCRoute (gw ),
1159
+ gateway : & Gateway {
1160
+ Source : gw ,
1161
+ Valid : true ,
1162
+ Listeners : []* Listener {
1163
+ createModifiedListener ("listener-80-1" , func (l * Listener ) {
1164
+ l .Source .AllowedRoutes = & gatewayv1.AllowedRoutes {
1165
+ Kinds : []gatewayv1.RouteGroupKind {
1166
+ {Kind : "HTTPRoute" },
1167
+ },
1168
+ }
1169
+ l .Routes = map [RouteKey ]* L7Route {
1170
+ CreateRouteKey (gr ): getLastNormalGRPCRoute (),
1171
+ }
1172
+ }),
1173
+ },
1174
+ },
1175
+ expectedSectionNameRefs : []ParentRef {
1176
+ {
1177
+ Idx : 0 ,
1178
+ Gateway : client .ObjectKeyFromObject (gw ),
1179
+ SectionName : gr .Spec .ParentRefs [0 ].SectionName ,
1180
+ Attachment : & ParentRefAttachmentStatus {
1181
+ Attached : true ,
1182
+ AcceptedHostnames : map [string ][]string {
1183
+ "listener-80-1" : {"foo.example.com" },
1184
+ },
1185
+ },
1186
+ },
1187
+ },
1188
+ expectedGatewayListeners : []* Listener {
1189
+ createModifiedListener ("listener-80-1" , func (l * Listener ) {
1190
+ l .Source .AllowedRoutes = & gatewayv1.AllowedRoutes {
1191
+ Kinds : []gatewayv1.RouteGroupKind {
1192
+ {Kind : "HTTPRoute" },
1193
+ },
1194
+ }
1195
+ l .Routes = map [RouteKey ]* L7Route {
1196
+ CreateRouteKey (gr ): getLastNormalGRPCRoute (),
1197
+ }
1198
+ }),
1199
+ },
1200
+ name : "grpc route allowed when listener kind is HTTPRoute" ,
1201
+ },
1059
1202
}
1060
1203
1061
1204
namespaces := map [types.NamespacedName ]* v1.Namespace {
0 commit comments