@@ -17,6 +17,7 @@ import (
1717 "fmt"
1818 "path"
1919 "reflect"
20+ "slices"
2021 "strings"
2122
2223 "github.com/api7/gopkg/pkg/log"
@@ -230,26 +231,21 @@ func ConditionStatus(status bool) metav1.ConditionStatus {
230231 return metav1 .ConditionFalse
231232}
232233
233- func SetRouteConditionAccepted (routeParentStatus * gatewayv1.RouteParentStatus , gw * gatewayv1. Gateway , hr * gatewayv1. HTTPRoute , acceptedStatus bool , acceptStatusMsg string ) ( accepted bool ) {
234+ func SetRouteConditionAccepted (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
234235 condition := metav1.Condition {
235236 Type : string (gatewayv1 .RouteConditionAccepted ),
236- Status : ConditionStatus (acceptedStatus ),
237- ObservedGeneration : hr .GetGeneration (),
238- LastTransitionTime : metav1 .Now (),
237+ Status : ConditionStatus (status ),
239238 Reason : string (gatewayv1 .RouteReasonAccepted ),
240- Message : acceptStatusMsg ,
241- }
242- // if it is across the namespace between the Gateway and HTTPRoute, set .Status="False"
243- if gw .GetNamespace () != hr .GetNamespace () {
244- condition .Status = metav1 .ConditionFalse
245- condition .Reason = string (gatewayv1 .RouteReasonNotAllowedByListeners )
246- condition .Message = fmt .Sprintf ("A HTTPRoute in the namespace %s failed to attach to a Gateway in another namespace %s" ,
247- hr .GetNamespace (), gw .GetNamespace ())
239+ ObservedGeneration : generation ,
240+ Message : message ,
241+ LastTransitionTime : metav1 .Now (),
248242 }
249- if ! IsConditionPresentAndEqual (routeParentStatus .Conditions , condition ) {
243+
244+ if ! IsConditionPresentAndEqual (routeParentStatus .Conditions , condition ) && ! slices .ContainsFunc (routeParentStatus .Conditions , func (item metav1.Condition ) bool {
245+ return item .Type == condition .Type && item .Status == metav1 .ConditionFalse && condition .Status == metav1 .ConditionTrue
246+ }) {
250247 routeParentStatus .Conditions = MergeCondition (routeParentStatus .Conditions , condition )
251248 }
252- return condition .Status == metav1 .ConditionTrue
253249}
254250
255251func SetRouteConditionResolvedRefs (routeParentStatus * gatewayv1.RouteParentStatus , generation int64 , status bool , message string ) {
@@ -273,6 +269,19 @@ func SetRouteConditionResolvedRefs(routeParentStatus *gatewayv1.RouteParentStatu
273269 }
274270}
275271
272+ func SetRouteParentRef (routeParentStatus * gatewayv1.RouteParentStatus , gatewayName string , namespace string ) {
273+ kind := gatewayv1 .Kind (KindGateway )
274+ group := gatewayv1 .Group (gatewayv1 .GroupName )
275+ ns := gatewayv1 .Namespace (namespace )
276+ routeParentStatus .ParentRef = gatewayv1.ParentReference {
277+ Kind : & kind ,
278+ Group : & group ,
279+ Name : gatewayv1 .ObjectName (gatewayName ),
280+ Namespace : & ns ,
281+ }
282+ routeParentStatus .ControllerName = gatewayv1 .GatewayController (config .ControllerConfig .ControllerName )
283+ }
284+
276285func ParseRouteParentRefs (
277286 ctx context.Context , mgrc client.Client , route client.Object , parentRefs []gatewayv1.ParentReference ,
278287) ([]RouteParentRefContext , error ) {
@@ -339,19 +348,21 @@ func ParseRouteParentRefs(
339348 continue
340349 }
341350
342- if ok , err := routeMatchesListenerAllowedRoutes (ctx , mgrc , route , listener .AllowedRoutes , gateway .Namespace , parentRef .Namespace ); err != nil {
343- return nil , fmt .Errorf ("failed matching listener %s to a route %s for gateway %s: %w" ,
351+ listenerName = string (listener .Name )
352+ ok , err := routeMatchesListenerAllowedRoutes (ctx , mgrc , route , listener .AllowedRoutes , gateway .Namespace , parentRef .Namespace )
353+ if err != nil {
354+ log .Warnf ("failed matching listener %s to a route %s for gateway %s: %v" ,
344355 listener .Name , route .GetName (), gateway .Name , err ,
345356 )
346- } else if ! ok {
357+ }
358+ if ! ok {
347359 reason = gatewayv1 .RouteReasonNotAllowedByListeners
348360 continue
349361 }
350362
351363 // TODO: check if the listener status is programmed
352364
353365 matched = true
354- listenerName = string (listener .Name )
355366 break
356367 }
357368
@@ -368,7 +379,8 @@ func ParseRouteParentRefs(
368379 })
369380 } else {
370381 gateways = append (gateways , RouteParentRefContext {
371- Gateway : & gateway ,
382+ Gateway : & gateway ,
383+ ListenerName : listenerName ,
372384 Conditions : []metav1.Condition {{
373385 Type : string (gatewayv1 .RouteConditionAccepted ),
374386 Status : metav1 .ConditionFalse ,
0 commit comments