diff --git a/internal/gatewayapi/contexts.go b/internal/gatewayapi/contexts.go index 6813e9f3b1d4..f3d225c83be3 100644 --- a/internal/gatewayapi/contexts.go +++ b/internal/gatewayapi/contexts.go @@ -670,3 +670,15 @@ func (r *RouteParentContext) IsAccepted(route RouteContext) bool { return false } + +func (r *RouteParentContext) HasUnResolvedRefs(route RouteContext) bool { + var conditions []metav1.Condition + routeStatus := route.GetRouteStatus() + conditions = routeStatus.Parents[r.routeParentStatusIdx].Conditions + for _, cond := range conditions { + if cond.Type == string(v1beta1.RouteConditionResolvedRefs) && cond.Status == metav1.ConditionFalse { + return true + } + } + return false +} diff --git a/internal/gatewayapi/route.go b/internal/gatewayapi/route.go index 9211fe256f84..aee0273eebf2 100644 --- a/internal/gatewayapi/route.go +++ b/internal/gatewayapi/route.go @@ -108,6 +108,16 @@ func (t *Translator) processHTTPRouteParentRefs(httpRoute *HTTPRouteContext, res "Route is accepted", ) } + + // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" + if !parentRef.HasUnResolvedRefs(httpRoute) { + parentRef.SetCondition(httpRoute, + v1beta1.RouteConditionResolvedRefs, + metav1.ConditionTrue, + v1beta1.RouteReasonResolvedRefs, + "Resolved all the Object references for the Route", + ) + } } } @@ -303,6 +313,16 @@ func (t *Translator) processGRPCRouteParentRefs(grpcRoute *GRPCRouteContext, res "Route is accepted", ) } + + // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" + if !parentRef.HasUnResolvedRefs(grpcRoute) { + parentRef.SetCondition(grpcRoute, + v1beta1.RouteConditionResolvedRefs, + metav1.ConditionTrue, + v1beta1.RouteReasonResolvedRefs, + "Resolved all the Object references for the Route", + ) + } } } @@ -613,6 +633,16 @@ func (t *Translator) processTLSRouteParentRefs(tlsRoute *TLSRouteContext, resour "Route is accepted", ) } + + // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" + if !parentRef.HasUnResolvedRefs(tlsRoute) { + parentRef.SetCondition(tlsRoute, + v1beta1.RouteConditionResolvedRefs, + metav1.ConditionTrue, + v1beta1.RouteReasonResolvedRefs, + "Resolved all the Object references for the Route", + ) + } } } @@ -730,6 +760,7 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour "Route is accepted", ) } + if !accepted { parentRef.SetCondition(udpRoute, v1beta1.RouteConditionAccepted, @@ -738,6 +769,17 @@ func (t *Translator) processUDPRouteParentRefs(udpRoute *UDPRouteContext, resour "Multiple routes on the same UDP listener", ) } + + // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" + if !parentRef.HasUnResolvedRefs(udpRoute) { + parentRef.SetCondition(udpRoute, + v1beta1.RouteConditionResolvedRefs, + metav1.ConditionTrue, + v1beta1.RouteReasonResolvedRefs, + "Resolved all the Object references for the Route", + ) + } + } } @@ -863,6 +905,16 @@ func (t *Translator) processTCPRouteParentRefs(tcpRoute *TCPRouteContext, resour "Multiple routes on the same TCP listener", ) } + + // If no negative condition has been set for ResolvedRefs, set "ResolvedRefs=True" + if !parentRef.HasUnResolvedRefs(tcpRoute) { + parentRef.SetCondition(tcpRoute, + v1beta1.RouteConditionResolvedRefs, + metav1.ConditionTrue, + v1beta1.RouteReasonResolvedRefs, + "Resolved all the Object references for the Route", + ) + } } }