@@ -18,6 +18,7 @@ import (
18
18
"fmt"
19
19
"path"
20
20
"reflect"
21
+ "slices"
21
22
"strings"
22
23
23
24
"github.com/api7/gopkg/pkg/log"
@@ -228,37 +229,34 @@ func SetGatewayConditionProgrammed(gw *gatewayv1.Gateway, status bool, message s
228
229
return
229
230
}
230
231
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
240
235
}
236
+ return metav1 .ConditionFalse
237
+ }
241
238
239
+ func SetRouteConditionAccepted (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
242
240
condition := metav1.Condition {
243
241
Type : string (gatewayv1 .RouteConditionAccepted ),
244
- Status : conditionStatus ,
245
- Reason : string (reason ),
242
+ Status : ConditionStatus ( status ) ,
243
+ Reason : string (gatewayv1 . RouteReasonAccepted ),
246
244
ObservedGeneration : generation ,
247
245
Message : message ,
248
246
LastTransitionTime : metav1 .Now (),
249
247
}
248
+ if message == ErrNoMatchingListenerHostname .Error () {
249
+ condition .Reason = string (gatewayv1 .RouteReasonNoMatchingListenerHostname )
250
+ }
250
251
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
+ }) {
252
255
routeParentStatus .Conditions = MergeCondition (routeParentStatus .Conditions , condition )
253
256
}
254
257
}
255
258
256
259
func SetRouteConditionResolvedRefs (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
257
- conditionStatus := metav1 .ConditionTrue
258
- if ! status {
259
- conditionStatus = metav1 .ConditionFalse
260
- }
261
-
262
260
reason := string (gatewayv1 .RouteReasonResolvedRefs )
263
261
// check if the error message contains InvalidKind
264
262
if ! status && strings .Contains (message , string (gatewayv1 .RouteReasonInvalidKind )) {
@@ -270,7 +268,7 @@ func SetRouteConditionResolvedRefs(routeParentStatus *gatewayv1.RouteParentStatu
270
268
271
269
condition := metav1.Condition {
272
270
Type : string (gatewayv1 .RouteConditionResolvedRefs ),
273
- Status : conditionStatus ,
271
+ Status : ConditionStatus ( status ) ,
274
272
Reason : reason ,
275
273
ObservedGeneration : generation ,
276
274
Message : message ,
@@ -361,19 +359,21 @@ func ParseRouteParentRefs(
361
359
continue
362
360
}
363
361
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" ,
366
366
listener .Name , route .GetName (), gateway .Name , err ,
367
367
)
368
- } else if ! ok {
368
+ }
369
+ if ! ok {
369
370
reason = gatewayv1 .RouteReasonNotAllowedByListeners
370
371
continue
371
372
}
372
373
373
374
// TODO: check if the listener status is programmed
374
375
375
376
matched = true
376
- listenerName = string (listener .Name )
377
377
break
378
378
}
379
379
@@ -390,7 +390,8 @@ func ParseRouteParentRefs(
390
390
})
391
391
} else {
392
392
gateways = append (gateways , RouteParentRefContext {
393
- Gateway : & gateway ,
393
+ Gateway : & gateway ,
394
+ ListenerName : listenerName ,
394
395
Conditions : []metav1.Condition {{
395
396
Type : string (gatewayv1 .RouteConditionAccepted ),
396
397
Status : metav1 .ConditionFalse ,
0 commit comments