@@ -34,6 +34,7 @@ import (
3434 coreinformers "k8s.io/client-go/informers/core/v1"
3535 cache "k8s.io/client-go/tools/cache"
3636 v1 "sigs.k8s.io/gateway-api/apis/v1"
37+ "sigs.k8s.io/gateway-api/apis/v1alpha2"
3738 v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
3839 gateway "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
3940 informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
@@ -293,19 +294,39 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
293294 return nil , err
294295 }
295296 hostTargets := make (map [string ]endpoint.Targets )
296- currentGeneration := rt .Metadata ().Generation
297+
298+ routeParentRefs := getRouteParentRefs (rt )
299+
300+ if len (routeParentRefs ) == 0 {
301+ log .Debugf ("No parent references found for %s %s/%s" , c .src .rtKind , rt .Metadata ().Namespace , rt .Metadata ().Name )
302+ return hostTargets , nil
303+ }
304+
297305 meta := rt .Metadata ()
298306 for _ , rps := range rt .RouteStatus ().Parents {
299307 // Confirm the Parent is the standard Gateway kind.
300308 ref := rps .ParentRef
309+ // Ensure that the parent reference is in the routeParentRefs list
310+ found := false
311+ for _ , rpr := range routeParentRefs {
312+ if string (rpr .Name ) == string (ref .Name ) && string (* rpr .Namespace ) == string (* ref .Namespace ) {
313+ found = true
314+ break
315+ }
316+ }
317+ namespace := strVal ((* string )(ref .Namespace ), meta .Namespace )
318+ if ! found {
319+ 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 )
320+ continue
321+ }
322+
301323 group := strVal ((* string )(ref .Group ), gatewayGroup )
302324 kind := strVal ((* string )(ref .Kind ), gatewayKind )
303325 if group != gatewayGroup || kind != gatewayKind {
304326 log .Debugf ("Unsupported parent %s/%s for %s %s/%s" , group , kind , c .src .rtKind , meta .Namespace , meta .Name )
305327 continue
306328 }
307329 // Lookup the Gateway and its Listeners.
308- namespace := strVal ((* string )(ref .Namespace ), meta .Namespace )
309330 gw , ok := c .gws [namespacedName (namespace , string (ref .Name ))]
310331 if ! ok {
311332 log .Debugf ("Gateway %s/%s not found for %s %s/%s" , namespace , ref .Name , c .src .rtKind , meta .Namespace , meta .Name )
@@ -316,8 +337,9 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
316337 log .Debugf ("Gateway %s/%s does not match %s %s/%s" , namespace , ref .Name , c .src .gwName , meta .Namespace , meta .Name )
317338 continue
318339 }
340+
319341 // Confirm the Gateway has accepted the Route, and that the generation matches.
320- if ! gwRouteIsAccepted (rps .Conditions , currentGeneration ) {
342+ if ! gwRouteIsAccepted (rps .Conditions ) {
321343 log .Debugf ("Gateway %s/%s has not accepted %s %s/%s" , namespace , ref .Name , c .src .rtKind , meta .Namespace , meta .Name )
322344 continue
323345 }
@@ -458,14 +480,29 @@ func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1.Liste
458480 return false
459481}
460482
461- func gwRouteIsAccepted (conds []metav1.Condition , currentGeneration int64 ) bool {
483+ func gwRouteIsAccepted (conds []metav1.Condition ) bool {
462484 for _ , c := range conds {
463- if v1 .RouteConditionType (c .Type ) == v1 .RouteConditionAccepted && c . ObservedGeneration == currentGeneration {
485+ if v1 .RouteConditionType (c .Type ) == v1 .RouteConditionAccepted {
464486 return c .Status == metav1 .ConditionTrue
465487 }
466488 }
467489 return false
468490}
491+ func getRouteParentRefs (rt gatewayRoute ) []v1.ParentReference {
492+ routeParentRefs := make ([]v1.ParentReference , 0 )
493+
494+ switch rt .Object ().(type ) {
495+ case * v1.HTTPRoute :
496+ routeParentRefs = rt .Object ().(* v1.HTTPRoute ).Spec .ParentRefs
497+ case * v1.GRPCRoute :
498+ routeParentRefs = rt .Object ().(* v1.GRPCRoute ).Spec .ParentRefs
499+ case * v1alpha2.UDPRoute :
500+ routeParentRefs = rt .Object ().(* v1alpha2.UDPRoute ).Spec .ParentRefs
501+ case * v1alpha2.TCPRoute :
502+ routeParentRefs = rt .Object ().(* v1alpha2.TCPRoute ).Spec .ParentRefs
503+ }
504+ return routeParentRefs
505+ }
469506
470507func uniqueTargets (targets endpoint.Targets ) endpoint.Targets {
471508 if len (targets ) < 2 {
0 commit comments