@@ -482,6 +482,14 @@ func (r *routeReconciler) validateRoute(ctx context.Context, route core.Route) e
482482 return fmt .Errorf ("validate route: %w" , err )
483483 }
484484
485+ if core .HasAllParentRefsRejected (route ) {
486+ r .eventRecorder .Event (route .K8sObject (), corev1 .EventTypeWarning ,
487+ k8s .RouteEventReasonFailedBuildModel ,
488+ "No VPC Lattice resources created. Route's parentRefs rejected by all Gateway listeners due to allowedRoutes policies. Check route status conditions for more detail." )
489+ return fmt .Errorf ("%w: route has validation errors, see status" , ErrValidation )
490+ }
491+
492+ // Additional broader validation check for any issues
485493 if r .hasNotAcceptedCondition (route ) {
486494 return fmt .Errorf ("%w: route has validation errors, see status" , ErrValidation )
487495 }
@@ -509,8 +517,9 @@ func (r *routeReconciler) hasNotAcceptedCondition(route core.Route) bool {
509517//
510518// If parent GW exists will check:
511519// - NoMatchingParent: parentRef sectionName and port matches Listener name and port
520+ // - NotAllowedByListeners: listener allowedRoutes.namespaces allows route
521+ // - NotAllowedByListeners: listener allowedRoutes.kinds contains route GroupKind
512522// - TODO: NoMatchingListenerHostname: listener hostname matches one of route hostnames
513- // - TODO: NotAllowedByListeners: listener allowedRoutes contains route GroupKind
514523func (r * routeReconciler ) validateRouteParentRefs (ctx context.Context , route core.Route ) ([]gwv1.RouteParentStatus , error ) {
515524 if len (route .Spec ().ParentRefs ()) == 0 {
516525 return nil , ErrParentRefsNotFound
@@ -525,6 +534,8 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
525534 gw := gws [0 ]
526535 for _ , parentRef := range route .Spec ().ParentRefs () {
527536 noMatchingParent := true
537+ notAllowedByAnyMatchingListener := true
538+
528539 for _ , listener := range gw .Spec .Listeners {
529540 if parentRef .Port != nil && * parentRef .Port != listener .Port {
530541 continue
@@ -533,6 +544,16 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
533544 continue
534545 }
535546 noMatchingParent = false
547+
548+ allowed , err := core .IsRouteAllowedByListener (ctx , r .client , route , gw , listener )
549+ if err != nil {
550+ return nil , err
551+ }
552+
553+ if allowed {
554+ notAllowedByAnyMatchingListener = false
555+ break
556+ }
536557 }
537558
538559 parentStatus := gwv1.RouteParentStatus {
@@ -545,6 +566,9 @@ func (r *routeReconciler) validateRouteParentRefs(ctx context.Context, route cor
545566 switch {
546567 case noMatchingParent :
547568 cnd = r .newCondition (route , gwv1 .RouteConditionAccepted , gwv1 .RouteReasonNoMatchingParent , "" )
569+ case notAllowedByAnyMatchingListener :
570+ cnd = r .newCondition (route , gwv1 .RouteConditionAccepted , gwv1 .RouteReasonNotAllowedByListeners ,
571+ "No matching listeners allow this route. Check Gateway listener allowedRoutes policies" )
548572 default :
549573 cnd = r .newCondition (route , gwv1 .RouteConditionAccepted , gwv1 .RouteReasonAccepted , "" )
550574 }
0 commit comments