@@ -354,6 +354,121 @@ func ParseRouteParentRefs(
354354 continue
355355 }
356356
357+ matched := false
358+ reason := gatewayv1 .RouteReasonNoMatchingParent
359+ var listenerName string
360+
361+ for _ , listener := range gateway .Spec .Listeners {
362+ if parentRef .SectionName != nil {
363+ if * parentRef .SectionName != "" && * parentRef .SectionName != listener .Name {
364+ continue
365+ }
366+ }
367+
368+ if parentRef .Port != nil {
369+ if * parentRef .Port != listener .Port {
370+ continue
371+ }
372+ }
373+
374+ if ! routeMatchesListenerType (route , listener ) {
375+ continue
376+ }
377+
378+ if ! routeHostnamesIntersectsWithListenerHostname (route , listener ) {
379+ reason = gatewayv1 .RouteReasonNoMatchingListenerHostname
380+ continue
381+ }
382+
383+ listenerName = string (listener .Name )
384+ ok , err := routeMatchesListenerAllowedRoutes (ctx , mgrc , route , listener .AllowedRoutes , gateway .Namespace , parentRef .Namespace )
385+ if err != nil {
386+ log .Warnw ("failed matching listener to a route for gateway" ,
387+ zap .String ("listener" , string (listener .Name )),
388+ zap .String ("route" , route .GetName ()),
389+ zap .String ("gateway" , gateway .Name ),
390+ zap .Error (err ),
391+ )
392+ }
393+ if ! ok {
394+ reason = gatewayv1 .RouteReasonNotAllowedByListeners
395+ continue
396+ }
397+
398+ // TODO: check if the listener status is programmed
399+
400+ matched = true
401+ break
402+ }
403+
404+ if matched {
405+ gateways = append (gateways , RouteParentRefContext {
406+ Gateway : & gateway ,
407+ ListenerName : listenerName ,
408+ Conditions : []metav1.Condition {{
409+ Type : string (gatewayv1 .RouteConditionAccepted ),
410+ Status : metav1 .ConditionTrue ,
411+ Reason : string (gatewayv1 .RouteReasonAccepted ),
412+ ObservedGeneration : route .GetGeneration (),
413+ }},
414+ })
415+ } else {
416+ gateways = append (gateways , RouteParentRefContext {
417+ Gateway : & gateway ,
418+ ListenerName : listenerName ,
419+ Conditions : []metav1.Condition {{
420+ Type : string (gatewayv1 .RouteConditionAccepted ),
421+ Status : metav1 .ConditionFalse ,
422+ Reason : string (reason ),
423+ ObservedGeneration : route .GetGeneration (),
424+ }},
425+ })
426+ }
427+ }
428+
429+ return gateways , nil
430+ }
431+
432+ func ParseTCPRouteParentRefs (
433+ ctx context.Context , mgrc client.Client , route client.Object , parentRefs []gatewayv1.ParentReference ,
434+ ) ([]RouteParentRefContext , error ) {
435+ gateways := make ([]RouteParentRefContext , 0 )
436+ for _ , parentRef := range parentRefs {
437+ namespace := route .GetNamespace ()
438+ if parentRef .Namespace != nil {
439+ namespace = string (* parentRef .Namespace )
440+ }
441+ name := string (parentRef .Name )
442+
443+ if parentRef .Kind != nil && * parentRef .Kind != KindGateway {
444+ continue
445+ }
446+
447+ gateway := gatewayv1.Gateway {}
448+ if err := mgrc .Get (ctx , client.ObjectKey {
449+ Namespace : namespace ,
450+ Name : name ,
451+ }, & gateway ); err != nil {
452+ if client .IgnoreNotFound (err ) == nil {
453+ continue
454+ }
455+ return nil , fmt .Errorf ("failed to retrieve gateway for route: %w" , err )
456+ }
457+
458+ gatewayClass := gatewayv1.GatewayClass {}
459+ if err := mgrc .Get (ctx , client.ObjectKey {
460+ Name : string (gateway .Spec .GatewayClassName ),
461+ }, & gatewayClass ); err != nil {
462+ if client .IgnoreNotFound (err ) == nil {
463+ continue
464+ }
465+ return nil , fmt .Errorf ("failed to retrieve gatewayclass for gateway: %w" , err )
466+ }
467+
468+ if string (gatewayClass .Spec .ControllerName ) != config .ControllerConfig .ControllerName {
469+ continue
470+ }
471+
357472 matched := false
358473 reason := gatewayv1 .RouteReasonNoMatchingParent
359474 var listenerName string
0 commit comments