@@ -43,6 +43,15 @@ func setGatewayCondition(gw *gatewayv1.Gateway, newCondition metav1.Condition) {
4343 gw .Status .Conditions = MergeCondition (gw .Status .Conditions , newCondition )
4444}
4545
46+ func setListenerCondition (gw * gatewayv1.Gateway , listenerName string , newCondition metav1.Condition ) {
47+ for i , listener := range gw .Status .Listeners {
48+ if listener .Name == gatewayv1 .SectionName (listenerName ) {
49+ gw .Status .Listeners [i ].Conditions = MergeCondition (listener .Conditions , newCondition )
50+ return
51+ }
52+ }
53+ }
54+
4655func reconcileGatewaysMatchGatewayClass (gatewayClass client.Object , gateways []gatewayv1.Gateway ) (recs []reconcile.Request ) {
4756 for _ , gateway := range gateways {
4857 if string (gateway .Spec .GatewayClassName ) == gatewayClass .GetName () {
@@ -91,6 +100,72 @@ func SetGatewayConditionAccepted(gw *gatewayv1.Gateway, status bool, message str
91100 return
92101}
93102
103+ func SetGatewayListenerConditionAccepted (gw * gatewayv1.Gateway , listenerName string , status bool , message string ) (ok bool ) {
104+ conditionStatus := metav1 .ConditionTrue
105+ if ! status {
106+ conditionStatus = metav1 .ConditionFalse
107+ }
108+
109+ condition := metav1.Condition {
110+ Type : string (gatewayv1 .ListenerConditionAccepted ),
111+ Status : conditionStatus ,
112+ Reason : string (gatewayv1 .ListenerConditionAccepted ),
113+ ObservedGeneration : gw .GetGeneration (),
114+ Message : message ,
115+ LastTransitionTime : metav1 .Now (),
116+ }
117+
118+ if ! IsConditionPresentAndEqual (gw .Status .Conditions , condition ) {
119+ setListenerCondition (gw , listenerName , condition )
120+ ok = true
121+ }
122+ return
123+ }
124+
125+ func SetGatewayListenerConditionProgrammed (gw * gatewayv1.Gateway , listenerName string , status bool , message string ) (ok bool ) {
126+ conditionStatus := metav1 .ConditionTrue
127+ if ! status {
128+ conditionStatus = metav1 .ConditionFalse
129+ }
130+
131+ condition := metav1.Condition {
132+ Type : string (gatewayv1 .ListenerConditionProgrammed ),
133+ Status : conditionStatus ,
134+ Reason : string (gatewayv1 .ListenerReasonProgrammed ),
135+ ObservedGeneration : gw .GetGeneration (),
136+ Message : message ,
137+ LastTransitionTime : metav1 .Now (),
138+ }
139+
140+ if ! IsConditionPresentAndEqual (gw .Status .Conditions , condition ) {
141+ setListenerCondition (gw , listenerName , condition )
142+ ok = true
143+ }
144+ return
145+ }
146+
147+ func SetGatewayListenerConditionResolvedRefs (gw * gatewayv1.Gateway , listenerName string , status bool , message string ) (ok bool ) {
148+ conditionStatus := metav1 .ConditionTrue
149+ if ! status {
150+ conditionStatus = metav1 .ConditionFalse
151+ }
152+
153+ condition := metav1.Condition {
154+ Type : string (gatewayv1 .ListenerConditionResolvedRefs ),
155+ Status : conditionStatus ,
156+ Reason : string (gatewayv1 .ListenerReasonResolvedRefs ),
157+ ObservedGeneration : gw .GetGeneration (),
158+ Message : message ,
159+ LastTransitionTime : metav1 .Now (),
160+ }
161+
162+ if ! IsConditionPresentAndEqual (gw .Status .Conditions , condition ) {
163+ setListenerCondition (gw , listenerName , condition )
164+ ok = true
165+ }
166+ return
167+ }
168+
94169func SetGatewayConditionProgrammed (gw * gatewayv1.Gateway , status bool , message string ) (ok bool ) {
95170 conditionStatus := metav1 .ConditionTrue
96171 if ! status {
@@ -288,21 +363,17 @@ func checkRouteAcceptedByListener(
288363 return false , gatewayv1 .RouteReasonNoMatchingParent , nil
289364 }
290365 }
291-
292366 if parentRef .Port != nil {
293367 if * parentRef .Port != listener .Port {
294368 return false , gatewayv1 .RouteReasonNoMatchingParent , nil
295369 }
296370 }
297-
298371 if ! routeMatchesListenerType (route , listener ) {
299372 return false , gatewayv1 .RouteReasonNoMatchingParent , nil
300373 }
301-
302374 if ! routeHostnamesIntersectsWithListenerHostname (route , listener ) {
303375 return false , gatewayv1 .RouteReasonNoMatchingListenerHostname , nil
304376 }
305-
306377 if ok , err := routeMatchesListenerAllowedRoutes (ctx , mgrc , route , listener .AllowedRoutes , gateway .Namespace , parentRef .Namespace ); err != nil {
307378 return false , gatewayv1 .RouteReasonNotAllowedByListeners , fmt .Errorf ("failed matching listener %s to a route %s for gateway %s: %w" ,
308379 listener .Name , route .GetName (), gateway .Name , err ,
@@ -480,7 +551,6 @@ func getAttachedRoutesForListener(ctx context.Context, mgrc client.Client, gatew
480551 if err := mgrc .List (ctx , & httpRouteList ); err != nil {
481552 return 0 , err
482553 }
483-
484554 var attachedRoutes int32
485555 for _ , route := range httpRouteList .Items {
486556 route := route
@@ -534,7 +604,6 @@ func getListenerStatus(
534604 if err != nil {
535605 return nil , err
536606 }
537-
538607 var (
539608 reasonResolvedRef = string (gatewayv1 .ListenerReasonResolvedRefs )
540609 statusResolvedRef = metav1 .ConditionTrue
0 commit comments