@@ -54,6 +54,8 @@ type gatewayRoute interface {
5454 Metadata () * metav1.ObjectMeta
5555 // Hostnames returns the route's specified hostnames.
5656 Hostnames () []v1.Hostname
57+ // ParentRefs returns the route's parent references as defined in the route spec.
58+ ParentRefs () []v1.ParentReference
5759 // Protocol returns the route's protocol type.
5860 Protocol () v1.ProtocolType
5961 // RouteStatus returns the route's common status.
@@ -294,18 +296,31 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
294296 }
295297 hostTargets := make (map [string ]endpoint.Targets )
296298
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+
297306 meta := rt .Metadata ()
298307 for _ , rps := range rt .RouteStatus ().Parents {
299308 // Confirm the Parent is the standard Gateway kind.
300309 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+
301317 group := strVal ((* string )(ref .Group ), gatewayGroup )
302318 kind := strVal ((* string )(ref .Kind ), gatewayKind )
303319 if group != gatewayGroup || kind != gatewayKind {
304320 log .Debugf ("Unsupported parent %s/%s for %s %s/%s" , group , kind , c .src .rtKind , meta .Namespace , meta .Name )
305321 continue
306322 }
307323 // Lookup the Gateway and its Listeners.
308- namespace := strVal ((* string )(ref .Namespace ), meta .Namespace )
309324 gw , ok := c .gws [namespacedName (namespace , string (ref .Name ))]
310325 if ! ok {
311326 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
316331 log .Debugf ("Gateway %s/%s does not match %s %s/%s" , namespace , ref .Name , c .src .gwName , meta .Namespace , meta .Name )
317332 continue
318333 }
334+
319335 // Confirm the Gateway has accepted the Route.
320336 if ! gwRouteIsAccepted (rps .Conditions ) {
321337 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
458474 return false
459475}
460476
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+
461497func gwRouteIsAccepted (conds []metav1.Condition ) bool {
462498 for _ , c := range conds {
463499 if v1 .RouteConditionType (c .Type ) == v1 .RouteConditionAccepted {
0 commit comments