@@ -11,6 +11,7 @@ import (
11
11
12
12
"github.com/kong/kubernetes-ingress-controller/v3/internal/dataplane/kongstate"
13
13
"github.com/kong/kubernetes-ingress-controller/v3/internal/gatewayapi"
14
+ "github.com/kong/kubernetes-ingress-controller/v3/internal/store"
14
15
"github.com/kong/kubernetes-ingress-controller/v3/internal/util"
15
16
)
16
17
@@ -29,6 +30,7 @@ func makeTestGRPCRoute(
29
30
name string , namespace string , annotations map [string ]string ,
30
31
hostnames []string ,
31
32
rules []gatewayapi.GRPCRouteRule ,
33
+ parentRef []gatewayapi.ParentReference ,
32
34
) * gatewayapi.GRPCRoute {
33
35
return & gatewayapi.GRPCRoute {
34
36
TypeMeta : metav1.TypeMeta {
@@ -45,6 +47,9 @@ func makeTestGRPCRoute(
45
47
return gatewayapi .Hostname (h )
46
48
}),
47
49
Rules : rules ,
50
+ CommonRouteSpec : gatewayapi.CommonRouteSpec {
51
+ ParentRefs : parentRef ,
52
+ },
48
53
},
49
54
}
50
55
}
@@ -57,6 +62,8 @@ func TestGenerateKongRoutesFromGRPCRouteRule(t *testing.T) {
57
62
hostnames []string
58
63
rule gatewayapi.GRPCRouteRule
59
64
expectedRoutes []kongstate.Route
65
+ parentRef []gatewayapi.ParentReference
66
+ storer store.Storer
60
67
}{
61
68
{
62
69
name : "single match without hostname" ,
@@ -277,13 +284,70 @@ func TestGenerateKongRoutesFromGRPCRouteRule(t *testing.T) {
277
284
},
278
285
},
279
286
},
287
+ {
288
+ name : "no match with hostname from gateway" ,
289
+ objectName : "hostname-from-gateway" ,
290
+ annotations : map [string ]string {},
291
+ rule : gatewayapi.GRPCRouteRule {},
292
+ expectedRoutes : []kongstate.Route {
293
+ {
294
+ Ingress : util.K8sObjectInfo {
295
+ Name : "hostname-from-gateway" ,
296
+ Namespace : "default" ,
297
+ Annotations : map [string ]string {},
298
+ GroupVersionKind : grpcRouteGVK ,
299
+ },
300
+ Route : kong.Route {
301
+ Name : kong .String ("grpcroute.default.hostname-from-gateway.0.0" ),
302
+ Hosts : kong .StringSlice ("bar.com" ),
303
+ Protocols : kong .StringSlice ("grpc" , "grpcs" ),
304
+ Tags : kong .StringSlice (
305
+ "k8s-name:hostname-from-gateway" ,
306
+ "k8s-namespace:default" ,
307
+ "k8s-kind:GRPCRoute" ,
308
+ "k8s-group:gateway.networking.k8s.io" ,
309
+ "k8s-version:v1" ,
310
+ ),
311
+ },
312
+ },
313
+ },
314
+ parentRef : []gatewayapi.ParentReference {
315
+ {
316
+ Name : "gateway" ,
317
+ Namespace : lo .ToPtr (gatewayapi .Namespace ("default" )),
318
+ SectionName : lo .ToPtr (gatewayapi .SectionName ("listener-1" )),
319
+ },
320
+ },
321
+ storer : lo .Must (store .NewFakeStore (store.FakeObjects {
322
+ Gateways : []* gatewayapi.Gateway {
323
+ {
324
+ ObjectMeta : metav1.ObjectMeta {
325
+ Name : "gateway" ,
326
+ Namespace : "default" ,
327
+ },
328
+ TypeMeta : metav1.TypeMeta {
329
+ Kind : "Gateway" ,
330
+ APIVersion : "gateway.networking.k8s.io/v1" ,
331
+ },
332
+ Spec : gatewayapi.GatewaySpec {
333
+ Listeners : []gatewayapi.Listener {
334
+ {
335
+ Name : "listener-1" ,
336
+ Hostname : lo .ToPtr (gatewayapi .Hostname ("bar.com" )),
337
+ },
338
+ },
339
+ },
340
+ },
341
+ },
342
+ })),
343
+ },
280
344
}
281
345
282
346
for _ , tc := range testCases {
283
347
tc := tc
284
348
t .Run (tc .name , func (t * testing.T ) {
285
- grpcroute := makeTestGRPCRoute (tc .objectName , "default" , tc .annotations , tc .hostnames , []gatewayapi.GRPCRouteRule {tc .rule })
286
- routes := GenerateKongRoutesFromGRPCRouteRule (grpcroute , 0 )
349
+ grpcroute := makeTestGRPCRoute (tc .objectName , "default" , tc .annotations , tc .hostnames , []gatewayapi.GRPCRouteRule {tc .rule }, tc . parentRef )
350
+ routes := GenerateKongRoutesFromGRPCRouteRule (grpcroute , 0 , tc . storer )
287
351
require .Equal (t , tc .expectedRoutes , routes )
288
352
})
289
353
}
@@ -325,7 +389,8 @@ func TestGetGRPCRouteHostnamesAsSliceOfStringPointers(t *testing.T) {
325
389
},
326
390
} {
327
391
t .Run (tC .name , func (t * testing.T ) {
328
- result := getGRPCRouteHostnamesAsSliceOfStringPointers (tC .grpcroute )
392
+ storer := lo .Must (store .NewFakeStore (store.FakeObjects {}))
393
+ result := getGRPCRouteHostnamesAsSliceOfStringPointers (tC .grpcroute , storer )
329
394
require .Equal (t , tC .expected , result )
330
395
})
331
396
}
0 commit comments