@@ -11,18 +11,18 @@ import (
1111 gwv1 "sigs.k8s.io/gateway-api/apis/v1"
1212)
1313
14- func buildListenerStatus (controllerName string , gateway gwv1.Gateway , attachedRoutesMap map [gwv1.SectionName ]int32 , validateListenerResults * routeutils.ListenerValidationResults ) []gwv1.ListenerStatus {
14+ func buildListenerStatus (controllerName string , gateway gwv1.Gateway , attachedRoutesMap map [gwv1.SectionName ]int32 , validateListenerResults * routeutils.ListenerValidationResults , isProgrammed bool ) []gwv1.ListenerStatus {
1515 var listenerStatuses []gwv1.ListenerStatus
1616
1717 // if validateListenerResults is nil, getListenerConditions will build condition with accepted condition
1818 for _ , listener := range gateway .Spec .Listeners {
1919 supportedKinds , _ := routeutils .GetSupportedKinds (controllerName , listener )
2020 var condition []metav1.Condition
2121 if validateListenerResults == nil {
22- condition = getListenerConditions (gateway , nil )
22+ condition = getListenerConditions (gateway , nil , isProgrammed )
2323 } else {
2424 listenerValidationResult := validateListenerResults .Results [listener .Name ]
25- condition = getListenerConditions (gateway , & listenerValidationResult )
25+ condition = getListenerConditions (gateway , & listenerValidationResult , isProgrammed )
2626 }
2727
2828 listenerStatus := gwv1.ListenerStatus {
@@ -36,29 +36,82 @@ func buildListenerStatus(controllerName string, gateway gwv1.Gateway, attachedRo
3636 return listenerStatuses
3737}
3838
39- func getListenerConditions (gw gwv1.Gateway , listenerValidationResult * routeutils.ListenerValidationResult ) []metav1.Condition {
39+ func getListenerConditions (gw gwv1.Gateway , listenerValidationResult * routeutils.ListenerValidationResult , isProgrammed bool ) []metav1.Condition {
4040 var conditions []metav1.Condition
4141
42- // Determine condition type based on reason
43- if listenerValidationResult == nil {
44- return append (conditions , buildAcceptedCondition (gw , gwv1 .ListenerReasonAccepted , gateway_constants .ListenerAcceptedMessage ))
42+ // Default
43+ listenerReason := gwv1 .ListenerReasonAccepted
44+ listenerErrMessage := gateway_constants .ListenerAcceptedMessage
45+
46+ if listenerValidationResult != nil {
47+ listenerReason = listenerValidationResult .Reason
48+ listenerErrMessage = listenerValidationResult .Message
4549 }
46- listenerReason := listenerValidationResult . Reason
47- listenerErrMessage := listenerValidationResult . Message
50+
51+ // Build Conflict Conditions
4852 switch listenerReason {
4953 case gwv1 .ListenerReasonHostnameConflict , gwv1 .ListenerReasonProtocolConflict :
5054 conditions = append (conditions , buildConflictedCondition (gw , listenerReason , listenerErrMessage ))
55+ default :
56+ conditions = append (conditions , buildConflictedCondition (gw , gwv1 .ListenerReasonNoConflicts , gateway_constants .ListenerNoConflictMessage ))
57+ }
58+
59+ // Build Accepted Conditions
60+ switch listenerReason {
5161 case gwv1 .ListenerReasonPortUnavailable , gwv1 .ListenerReasonUnsupportedProtocol :
5262 conditions = append (conditions , buildAcceptedCondition (gw , listenerReason , listenerErrMessage ))
63+ default :
64+ conditions = append (conditions , buildAcceptedCondition (gw , gwv1 .ListenerReasonAccepted , gateway_constants .ListenerAcceptedMessage ))
65+ }
66+
67+ // Build ResolvedRefs Conditions
68+ switch listenerReason {
5369 case gwv1 .ListenerReasonInvalidRouteKinds , gwv1 .ListenerReasonRefNotPermitted :
5470 conditions = append (conditions , buildResolvedRefsCondition (gw , listenerReason , listenerErrMessage ))
5571 default :
56- conditions = append (conditions , buildAcceptedCondition (gw , gwv1 .ListenerReasonAccepted , gateway_constants .ListenerAcceptedMessage ))
72+ conditions = append (conditions , buildResolvedRefsCondition (gw , gwv1 .ListenerReasonResolvedRefs , gateway_constants .ListenerResolvedRefMessage ))
5773 }
5874
75+ // Build Programmed Conditions
76+ isAccepted := listenerReason == gwv1 .ListenerReasonAccepted
77+ conditions = append (conditions , buildProgrammedCondition (gw , isProgrammed , isAccepted ))
78+
5979 return conditions
6080}
6181
82+ func buildProgrammedCondition (gw gwv1.Gateway , isProgrammed bool , isAccepted bool ) metav1.Condition {
83+ if ! isAccepted {
84+ return metav1.Condition {
85+ Type : string (gwv1 .ListenerConditionProgrammed ),
86+ Status : metav1 .ConditionFalse ,
87+ Reason : string (gwv1 .ListenerReasonInvalid ),
88+ Message : gateway_constants .ListenerNotAcceptedMessage ,
89+ LastTransitionTime : metav1 .NewTime (time .Now ()),
90+ ObservedGeneration : gw .GetGeneration (),
91+ }
92+ }
93+
94+ if isProgrammed {
95+ return metav1.Condition {
96+ Type : string (gwv1 .ListenerConditionProgrammed ),
97+ Status : metav1 .ConditionTrue ,
98+ Reason : string (gwv1 .ListenerReasonProgrammed ),
99+ Message : gateway_constants .ListenerProgrammedMessage ,
100+ LastTransitionTime : metav1 .NewTime (time .Now ()),
101+ ObservedGeneration : gw .GetGeneration (),
102+ }
103+ }
104+
105+ return metav1.Condition {
106+ Type : string (gwv1 .ListenerConditionProgrammed ),
107+ Status : metav1 .ConditionFalse ,
108+ Reason : string (gwv1 .ListenerReasonPending ),
109+ Message : gateway_constants .ListenerPendingProgrammedMessage ,
110+ LastTransitionTime : metav1 .NewTime (time .Now ()),
111+ ObservedGeneration : gw .GetGeneration (),
112+ }
113+ }
114+
62115func buildAcceptedCondition (gw gwv1.Gateway , reason gwv1.ListenerConditionReason , message string ) metav1.Condition {
63116 status := metav1 .ConditionTrue
64117 if reason != gwv1 .ListenerReasonAccepted {
@@ -77,7 +130,7 @@ func buildAcceptedCondition(gw gwv1.Gateway, reason gwv1.ListenerConditionReason
77130
78131func buildConflictedCondition (gw gwv1.Gateway , reason gwv1.ListenerConditionReason , message string ) metav1.Condition {
79132 status := metav1 .ConditionTrue
80- if reason != gwv1 .ListenerReasonAccepted {
133+ if reason != gwv1 .ListenerReasonNoConflicts {
81134 status = metav1 .ConditionFalse
82135 }
83136 return metav1.Condition {
@@ -92,7 +145,7 @@ func buildConflictedCondition(gw gwv1.Gateway, reason gwv1.ListenerConditionReas
92145
93146func buildResolvedRefsCondition (gw gwv1.Gateway , reason gwv1.ListenerConditionReason , message string ) metav1.Condition {
94147 status := metav1 .ConditionTrue
95- if reason != gwv1 .ListenerReasonAccepted {
148+ if reason != gwv1 .ListenerReasonResolvedRefs {
96149 status = metav1 .ConditionFalse
97150 }
98151 return metav1.Condition {
@@ -131,6 +184,13 @@ func isListenerStatusIdentical(listenerStatus []gwv1.ListenerStatus, listenerSta
131184 if len (listenerStatus [i ].Conditions ) != len (listenerStatusOld [i ].Conditions ) {
132185 return false
133186 }
187+ // Sort conditions by Type before comparison
188+ sort .Slice (listenerStatus [i ].Conditions , func (j , k int ) bool {
189+ return listenerStatus [i ].Conditions [j ].Type < listenerStatus [i ].Conditions [k ].Type
190+ })
191+ sort .Slice (listenerStatusOld [i ].Conditions , func (j , k int ) bool {
192+ return listenerStatusOld [i ].Conditions [j ].Type < listenerStatusOld [i ].Conditions [k ].Type
193+ })
134194 for j := range listenerStatus [i ].Conditions {
135195 if listenerStatus [i ].Conditions [j ].Type != listenerStatusOld [i ].Conditions [j ].Type {
136196 return false
0 commit comments