@@ -130,11 +130,25 @@ func TestBuildConfiguration(t *testing.T) {
130
130
131
131
createInternalRoute := func (
132
132
source * v1beta1.HTTPRoute ,
133
+ listenerName string ,
133
134
paths []pathAndType ,
134
135
) * graph.Route {
136
+ hostnames := make ([]string , 0 , len (source .Spec .Hostnames ))
137
+ for _ , h := range source .Spec .Hostnames {
138
+ hostnames = append (hostnames , string (h ))
139
+ }
135
140
r := & graph.Route {
136
141
Source : source ,
137
142
Rules : createRules (source , paths ),
143
+ ParentRefs : []graph.ParentRef {
144
+ {
145
+ Attachment : & graph.ParentRefAttachmentStatus {
146
+ AcceptedHostnames : map [string ][]string {
147
+ listenerName : hostnames ,
148
+ },
149
+ },
150
+ },
151
+ },
138
152
}
139
153
return r
140
154
}
@@ -162,7 +176,7 @@ func TestBuildConfiguration(t *testing.T) {
162
176
* v1beta1.HTTPRoute , []BackendGroup , * graph.Route ,
163
177
) {
164
178
hr := createRoute (name , hostname , listenerName , paths ... )
165
- route := createInternalRoute (hr , paths )
179
+ route := createInternalRoute (hr , listenerName , paths )
166
180
groups := createExpBackendGroupsForRoute (route )
167
181
return hr , groups , route
168
182
}
@@ -224,14 +238,6 @@ func TestBuildConfiguration(t *testing.T) {
224
238
pathAndType {path : "/valid" , pathType : prefix }, pathAndType {path : "/valid" , pathType : v1beta1 .PathMatchExact },
225
239
)
226
240
227
- hrNoHost , expHRNoHostGroups , routeNoHost := createTestResources (
228
- "route-no-host" ,
229
- "" ,
230
- "listener-80-1" ,
231
- pathAndType {path : "/" , pathType : prefix },
232
- )
233
- routeNoHost .Source .Spec .Hostnames = []v1beta1.Hostname {}
234
-
235
241
httpsHR1 , expHTTPSHR1Groups , httpsRouteHR1 := createTestResources (
236
242
"https-hr-1" ,
237
243
"foo.example.com" ,
@@ -266,6 +272,8 @@ func TestBuildConfiguration(t *testing.T) {
266
272
"listener-443-with-hostname" ,
267
273
pathAndType {path : "/" , pathType : prefix },
268
274
)
275
+ // add extra attachment for this route for duplicate listener test
276
+ httpsRouteHR5 .ParentRefs [0 ].Attachment .AcceptedHostnames ["listener-443-1" ] = []string {"example.com" }
269
277
270
278
httpsHR6 , expHTTPSHR6Groups , httpsRouteHR6 := createTestResources (
271
279
"https-hr-6" ,
@@ -360,10 +368,9 @@ func TestBuildConfiguration(t *testing.T) {
360
368
Source : & v1beta1.Gateway {},
361
369
Listeners : map [string ]* graph.Listener {
362
370
"listener-80-1" : {
363
- Source : listener80 ,
364
- Valid : true ,
365
- Routes : map [types.NamespacedName ]* graph.Route {},
366
- AcceptedHostnames : map [string ]struct {}{},
371
+ Source : listener80 ,
372
+ Valid : true ,
373
+ Routes : map [types.NamespacedName ]* graph.Route {},
367
374
},
368
375
},
369
376
},
@@ -389,18 +396,16 @@ func TestBuildConfiguration(t *testing.T) {
389
396
Source : & v1beta1.Gateway {},
390
397
Listeners : map [string ]* graph.Listener {
391
398
"listener-443-1" : {
392
- Source : listener443 , // nil hostname
393
- Valid : true ,
394
- Routes : map [types.NamespacedName ]* graph.Route {},
395
- AcceptedHostnames : map [string ]struct {}{},
396
- SecretPath : secretPath ,
399
+ Source : listener443 , // nil hostname
400
+ Valid : true ,
401
+ Routes : map [types.NamespacedName ]* graph.Route {},
402
+ SecretPath : secretPath ,
397
403
},
398
404
"listener-443-with-hostname" : {
399
- Source : listener443WithHostname , // non-nil hostname
400
- Valid : true ,
401
- Routes : map [types.NamespacedName ]* graph.Route {},
402
- AcceptedHostnames : map [string ]struct {}{},
403
- SecretPath : secretPath ,
405
+ Source : listener443WithHostname , // non-nil hostname
406
+ Valid : true ,
407
+ Routes : map [types.NamespacedName ]* graph.Route {},
408
+ SecretPath : secretPath ,
404
409
},
405
410
},
406
411
},
@@ -466,10 +471,6 @@ func TestBuildConfiguration(t *testing.T) {
466
471
{Namespace : "test" , Name : "hr-1" }: routeHR1 ,
467
472
{Namespace : "test" , Name : "hr-2" }: routeHR2 ,
468
473
},
469
- AcceptedHostnames : map [string ]struct {}{
470
- "foo.example.com" : {},
471
- "bar.example.com" : {},
472
- },
473
474
},
474
475
},
475
476
},
@@ -524,60 +525,6 @@ func TestBuildConfiguration(t *testing.T) {
524
525
},
525
526
msg : "one http listener with two routes for different hostnames" ,
526
527
},
527
- {
528
- graph : & graph.Graph {
529
- GatewayClass : & graph.GatewayClass {
530
- Source : & v1beta1.GatewayClass {},
531
- Valid : true ,
532
- },
533
- Gateway : & graph.Gateway {
534
- Source : & v1beta1.Gateway {},
535
- Listeners : map [string ]* graph.Listener {
536
- "listener-80-1" : {
537
- Source : listener80 ,
538
- Valid : true ,
539
- Routes : map [types.NamespacedName ]* graph.Route {
540
- {Namespace : "test" , Name : "route-no-host" }: routeNoHost ,
541
- },
542
- AcceptedHostnames : map [string ]struct {}{
543
- wildcardHostname : {},
544
- },
545
- },
546
- },
547
- },
548
- Routes : map [types.NamespacedName ]* graph.Route {
549
- {Namespace : "test" , Name : "route-no-host" }: routeNoHost ,
550
- },
551
- },
552
- expConf : Configuration {
553
- HTTPServers : []VirtualServer {
554
- {
555
- IsDefault : true ,
556
- },
557
- {
558
- Hostname : wildcardHostname ,
559
- PathRules : []PathRule {
560
- {
561
- Path : "/" ,
562
- PathType : PathTypePrefix ,
563
- MatchRules : []MatchRule {
564
- {
565
- MatchIdx : 0 ,
566
- RuleIdx : 0 ,
567
- BackendGroup : expHRNoHostGroups [0 ],
568
- Source : hrNoHost ,
569
- },
570
- },
571
- },
572
- },
573
- },
574
- },
575
- SSLServers : []VirtualServer {},
576
- Upstreams : []Upstream {fooUpstream },
577
- BackendGroups : []BackendGroup {expHRNoHostGroups [0 ]},
578
- },
579
- msg : "one listener and route without hostnames" ,
580
- },
581
528
{
582
529
graph : & graph.Graph {
583
530
GatewayClass : & graph.GatewayClass {
@@ -595,10 +542,6 @@ func TestBuildConfiguration(t *testing.T) {
595
542
{Namespace : "test" , Name : "https-hr-1" }: httpsRouteHR1 ,
596
543
{Namespace : "test" , Name : "https-hr-2" }: httpsRouteHR2 ,
597
544
},
598
- AcceptedHostnames : map [string ]struct {}{
599
- "foo.example.com" : {},
600
- "bar.example.com" : {},
601
- },
602
545
},
603
546
"listener-443-with-hostname" : {
604
547
Source : listener443WithHostname ,
@@ -607,9 +550,6 @@ func TestBuildConfiguration(t *testing.T) {
607
550
Routes : map [types.NamespacedName ]* graph.Route {
608
551
{Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
609
552
},
610
- AcceptedHostnames : map [string ]struct {}{
611
- "example.com" : {},
612
- },
613
553
},
614
554
},
615
555
},
@@ -711,9 +651,6 @@ func TestBuildConfiguration(t *testing.T) {
711
651
{Namespace : "test" , Name : "hr-3" }: routeHR3 ,
712
652
{Namespace : "test" , Name : "hr-4" }: routeHR4 ,
713
653
},
714
- AcceptedHostnames : map [string ]struct {}{
715
- "foo.example.com" : {},
716
- },
717
654
},
718
655
"listener-443-1" : {
719
656
Source : listener443 ,
@@ -723,9 +660,6 @@ func TestBuildConfiguration(t *testing.T) {
723
660
{Namespace : "test" , Name : "https-hr-3" }: httpsRouteHR3 ,
724
661
{Namespace : "test" , Name : "https-hr-4" }: httpsRouteHR4 ,
725
662
},
726
- AcceptedHostnames : map [string ]struct {}{
727
- "foo.example.com" : {},
728
- },
729
663
},
730
664
},
731
665
},
@@ -877,9 +811,6 @@ func TestBuildConfiguration(t *testing.T) {
877
811
Routes : map [types.NamespacedName ]* graph.Route {
878
812
{Namespace : "test" , Name : "hr-1" }: routeHR1 ,
879
813
},
880
- AcceptedHostnames : map [string ]struct {}{
881
- "foo.example.com" : {},
882
- },
883
814
},
884
815
},
885
816
},
@@ -902,9 +833,6 @@ func TestBuildConfiguration(t *testing.T) {
902
833
Routes : map [types.NamespacedName ]* graph.Route {
903
834
{Namespace : "test" , Name : "hr-1" }: routeHR1 ,
904
835
},
905
- AcceptedHostnames : map [string ]struct {}{
906
- "foo.example.com" : {},
907
- },
908
836
},
909
837
},
910
838
},
@@ -942,9 +870,6 @@ func TestBuildConfiguration(t *testing.T) {
942
870
Routes : map [types.NamespacedName ]* graph.Route {
943
871
{Namespace : "test" , Name : "hr-5" }: routeHR5 ,
944
872
},
945
- AcceptedHostnames : map [string ]struct {}{
946
- "foo.example.com" : {},
947
- },
948
873
},
949
874
},
950
875
},
@@ -1014,9 +939,6 @@ func TestBuildConfiguration(t *testing.T) {
1014
939
Routes : map [types.NamespacedName ]* graph.Route {
1015
940
{Namespace : "test" , Name : "hr-6" }: routeHR6 ,
1016
941
},
1017
- AcceptedHostnames : map [string ]struct {}{
1018
- "foo.example.com" : {},
1019
- },
1020
942
},
1021
943
"listener-443-1" : {
1022
944
Source : listener443 ,
@@ -1025,9 +947,6 @@ func TestBuildConfiguration(t *testing.T) {
1025
947
Routes : map [types.NamespacedName ]* graph.Route {
1026
948
{Namespace : "test" , Name : "https-hr-6" }: httpsRouteHR6 ,
1027
949
},
1028
- AcceptedHostnames : map [string ]struct {}{
1029
- "foo.example.com" : {},
1030
- },
1031
950
},
1032
951
},
1033
952
},
@@ -1111,9 +1030,6 @@ func TestBuildConfiguration(t *testing.T) {
1111
1030
Routes : map [types.NamespacedName ]* graph.Route {
1112
1031
{Namespace : "test" , Name : "hr-7" }: routeHR7 ,
1113
1032
},
1114
- AcceptedHostnames : map [string ]struct {}{
1115
- "foo.example.com" : {},
1116
- },
1117
1033
},
1118
1034
},
1119
1035
},
@@ -1178,9 +1094,6 @@ func TestBuildConfiguration(t *testing.T) {
1178
1094
Routes : map [types.NamespacedName ]* graph.Route {
1179
1095
{Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
1180
1096
},
1181
- AcceptedHostnames : map [string ]struct {}{
1182
- "example.com" : {},
1183
- },
1184
1097
},
1185
1098
"listener-443-1" : {
1186
1099
Source : listener443 ,
@@ -1189,9 +1102,6 @@ func TestBuildConfiguration(t *testing.T) {
1189
1102
Routes : map [types.NamespacedName ]* graph.Route {
1190
1103
{Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
1191
1104
},
1192
- AcceptedHostnames : map [string ]struct {}{
1193
- "example.com" : {},
1194
- },
1195
1105
},
1196
1106
},
1197
1107
},
0 commit comments