@@ -54,6 +54,8 @@ type gatewayRoute interface {
54
54
Metadata () * metav1.ObjectMeta
55
55
// Hostnames returns the route's specified hostnames.
56
56
Hostnames () []v1.Hostname
57
+ // ParentRefs returns the route's parent references as defined in the route spec.
58
+ ParentRefs () []v1.ParentReference
57
59
// Protocol returns the route's protocol type.
58
60
Protocol () v1.ProtocolType
59
61
// RouteStatus returns the route's common status.
@@ -294,18 +296,31 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
294
296
}
295
297
hostTargets := make (map [string ]endpoint.Targets )
296
298
299
+ routeParentRefs := rt .ParentRefs ()
300
+
301
+ if len (routeParentRefs ) == 0 {
302
+ log .Debugf ("No parent references found for %s %s/%s" , c .src .rtKind , rt .Metadata ().Namespace , rt .Metadata ().Name )
303
+ return hostTargets , nil
304
+ }
305
+
297
306
meta := rt .Metadata ()
298
307
for _ , rps := range rt .RouteStatus ().Parents {
299
308
// Confirm the Parent is the standard Gateway kind.
300
309
ref := rps .ParentRef
310
+ namespace := strVal ((* string )(ref .Namespace ), meta .Namespace )
311
+ // Ensure that the parent reference is in the routeParentRefs list
312
+ if ! gwRouteHasParentRef (routeParentRefs , ref , meta ) {
313
+ log .Debugf ("Parent reference %s/%s not found in routeParentRefs for %s %s/%s" , namespace , string (ref .Name ), c .src .rtKind , meta .Namespace , meta .Name )
314
+ continue
315
+ }
316
+
301
317
group := strVal ((* string )(ref .Group ), gatewayGroup )
302
318
kind := strVal ((* string )(ref .Kind ), gatewayKind )
303
319
if group != gatewayGroup || kind != gatewayKind {
304
320
log .Debugf ("Unsupported parent %s/%s for %s %s/%s" , group , kind , c .src .rtKind , meta .Namespace , meta .Name )
305
321
continue
306
322
}
307
323
// Lookup the Gateway and its Listeners.
308
- namespace := strVal ((* string )(ref .Namespace ), meta .Namespace )
309
324
gw , ok := c .gws [namespacedName (namespace , string (ref .Name ))]
310
325
if ! ok {
311
326
log .Debugf ("Gateway %s/%s not found for %s %s/%s" , namespace , ref .Name , c .src .rtKind , meta .Namespace , meta .Name )
@@ -316,6 +331,7 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
316
331
log .Debugf ("Gateway %s/%s does not match %s %s/%s" , namespace , ref .Name , c .src .gwName , meta .Namespace , meta .Name )
317
332
continue
318
333
}
334
+
319
335
// Confirm the Gateway has accepted the Route.
320
336
if ! gwRouteIsAccepted (rps .Conditions ) {
321
337
log .Debugf ("Gateway %s/%s has not accepted %s %s/%s" , namespace , ref .Name , c .src .rtKind , meta .Namespace , meta .Name )
@@ -458,6 +474,26 @@ func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1.Liste
458
474
return false
459
475
}
460
476
477
+ func gwRouteHasParentRef (routeParentRefs []v1.ParentReference , ref v1.ParentReference , meta * metav1.ObjectMeta ) bool {
478
+ // Ensure that the parent reference is in the routeParentRefs list
479
+ namespace := strVal ((* string )(ref .Namespace ), meta .Namespace )
480
+ group := strVal ((* string )(ref .Group ), gatewayGroup )
481
+ kind := strVal ((* string )(ref .Kind ), gatewayKind )
482
+ for _ , rpr := range routeParentRefs {
483
+ rprGroup := strVal ((* string )(rpr .Group ), gatewayGroup )
484
+ rprKind := strVal ((* string )(rpr .Kind ), gatewayKind )
485
+ if rprGroup != group || rprKind != kind {
486
+ continue
487
+ }
488
+ rprNamespace := strVal ((* string )(rpr .Namespace ), meta .Namespace )
489
+ if string (rpr .Name ) != string (ref .Name ) || rprNamespace != namespace {
490
+ continue
491
+ }
492
+ return true
493
+ }
494
+ return false
495
+ }
496
+
461
497
func gwRouteIsAccepted (conds []metav1.Condition ) bool {
462
498
for _ , c := range conds {
463
499
if v1 .RouteConditionType (c .Type ) == v1 .RouteConditionAccepted {
0 commit comments