@@ -18,6 +18,7 @@ import (
1818 "fmt"
1919 "path"
2020 "reflect"
21+ "slices"
2122 "strings"
2223
2324 "github.com/api7/gopkg/pkg/log"
@@ -228,37 +229,34 @@ func SetGatewayConditionProgrammed(gw *gatewayv1.Gateway, status bool, message s
228229 return
229230}
230231
231- func SetRouteConditionAccepted (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
232- conditionStatus := metav1 .ConditionTrue
233- if ! status {
234- conditionStatus = metav1 .ConditionFalse
235- }
236-
237- reason := gatewayv1 .RouteReasonAccepted
238- if message == ErrNoMatchingListenerHostname .Error () {
239- reason = gatewayv1 .RouteReasonNoMatchingListenerHostname
232+ func ConditionStatus (status bool ) metav1.ConditionStatus {
233+ if status {
234+ return metav1 .ConditionTrue
240235 }
236+ return metav1 .ConditionFalse
237+ }
241238
239+ func SetRouteConditionAccepted (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
242240 condition := metav1.Condition {
243241 Type : string (gatewayv1 .RouteConditionAccepted ),
244- Status : conditionStatus ,
245- Reason : string (reason ),
242+ Status : ConditionStatus ( status ) ,
243+ Reason : string (gatewayv1 . RouteReasonAccepted ),
246244 ObservedGeneration : generation ,
247245 Message : message ,
248246 LastTransitionTime : metav1 .Now (),
249247 }
248+ if message == ErrNoMatchingListenerHostname .Error () {
249+ condition .Reason = string (gatewayv1 .RouteReasonNoMatchingListenerHostname )
250+ }
250251
251- if ! IsConditionPresentAndEqual (routeParentStatus .Conditions , condition ) {
252+ if ! IsConditionPresentAndEqual (routeParentStatus .Conditions , condition ) && ! slices .ContainsFunc (routeParentStatus .Conditions , func (item metav1.Condition ) bool {
253+ return item .Type == condition .Type && item .Status == metav1 .ConditionFalse && condition .Status == metav1 .ConditionTrue
254+ }) {
252255 routeParentStatus .Conditions = MergeCondition (routeParentStatus .Conditions , condition )
253256 }
254257}
255258
256259func SetRouteConditionResolvedRefs (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
257- conditionStatus := metav1 .ConditionTrue
258- if ! status {
259- conditionStatus = metav1 .ConditionFalse
260- }
261-
262260 reason := string (gatewayv1 .RouteReasonResolvedRefs )
263261 // check if the error message contains InvalidKind
264262 if ! status && strings .Contains (message , string (gatewayv1 .RouteReasonInvalidKind )) {
@@ -270,7 +268,7 @@ func SetRouteConditionResolvedRefs(routeParentStatus *gatewayv1.RouteParentStatu
270268
271269 condition := metav1.Condition {
272270 Type : string (gatewayv1 .RouteConditionResolvedRefs ),
273- Status : conditionStatus ,
271+ Status : ConditionStatus ( status ) ,
274272 Reason : reason ,
275273 ObservedGeneration : generation ,
276274 Message : message ,
@@ -361,19 +359,21 @@ func ParseRouteParentRefs(
361359 continue
362360 }
363361
364- if ok , err := routeMatchesListenerAllowedRoutes (ctx , mgrc , route , listener .AllowedRoutes , gateway .Namespace , parentRef .Namespace ); err != nil {
365- return nil , fmt .Errorf ("failed matching listener %s to a route %s for gateway %s: %w" ,
362+ listenerName = string (listener .Name )
363+ ok , err := routeMatchesListenerAllowedRoutes (ctx , mgrc , route , listener .AllowedRoutes , gateway .Namespace , parentRef .Namespace )
364+ if err != nil {
365+ log .Warnf ("failed matching listener %s to a route %s for gateway %s: %v" ,
366366 listener .Name , route .GetName (), gateway .Name , err ,
367367 )
368- } else if ! ok {
368+ }
369+ if ! ok {
369370 reason = gatewayv1 .RouteReasonNotAllowedByListeners
370371 continue
371372 }
372373
373374 // TODO: check if the listener status is programmed
374375
375376 matched = true
376- listenerName = string (listener .Name )
377377 break
378378 }
379379
@@ -390,7 +390,8 @@ func ParseRouteParentRefs(
390390 })
391391 } else {
392392 gateways = append (gateways , RouteParentRefContext {
393- Gateway : & gateway ,
393+ Gateway : & gateway ,
394+ ListenerName : listenerName ,
394395 Conditions : []metav1.Condition {{
395396 Type : string (gatewayv1 .RouteConditionAccepted ),
396397 Status : metav1 .ConditionFalse ,
0 commit comments