@@ -38,6 +38,7 @@ import (
3838 "sigs.k8s.io/gateway-api/apis/v1alpha2"
3939
4040 "github.com/apache/apisix-ingress-controller/api/v1alpha1"
41+ "github.com/apache/apisix-ingress-controller/internal/controller/config"
4142 "github.com/apache/apisix-ingress-controller/internal/controller/indexer"
4243 "github.com/apache/apisix-ingress-controller/internal/provider"
4344)
@@ -207,44 +208,32 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
207208 }
208209
209210 // TODO: diff the old and new status
210- hrNN := types.NamespacedName {Namespace : hr .GetNamespace (), Name : hr .GetName ()}
211211 hr .Status .Parents = make ([]gatewayv1.RouteParentStatus , 0 , len (gateways ))
212212 for _ , gateway := range gateways {
213- var (
214- parentStatus gatewayv1.RouteParentStatus
215- gwNN = types.NamespacedName {
216- Namespace : gateway .Gateway .GetNamespace (),
217- Name : gateway .Gateway .GetName (),
218- }
219- conditionAccepted = metav1.Condition {
220- Type : string (gatewayv1 .RouteConditionAccepted ),
221- Status : ConditionStatus (acceptStatus .status ),
222- ObservedGeneration : hr .GetGeneration (),
223- LastTransitionTime : metav1 .Now (),
224- Reason : string (gatewayv1 .RouteReasonAccepted ),
225- Message : acceptStatus .msg ,
226- }
227- )
228- if ok := setControllerNameAndParentRef (& parentStatus , gwNN , hrNN ); ! ok {
229- conditionAccepted = metav1.Condition {
230- Type : string (gatewayv1 .RouteConditionAccepted ),
231- Status : metav1 .ConditionFalse ,
232- ObservedGeneration : hr .GetGeneration (),
233- LastTransitionTime : metav1 .Now (),
234- Reason : string (gatewayv1 .RouteReasonNotAllowedByListeners ),
235- Message : fmt .Sprintf ("A HTTPRoute in the namespace %s failed to attach to a Gateway in another namespace %s" ,
236- hrNN .Namespace , gwNN .Namespace ),
237- }
213+ parentStatus := gatewayv1.RouteParentStatus {
214+ ParentRef : gatewayv1.ParentReference {
215+ Kind : ptr .To (gatewayv1 .Kind (KindGateway )),
216+ Group : ptr .To (gatewayv1 .Group (gatewayv1 .GroupName )),
217+ Name : gatewayv1 .ObjectName (gateway .Gateway .GetName ()),
218+ Namespace : ptr .To (gatewayv1 .Namespace (gateway .Gateway .GetNamespace ())),
219+ },
220+ ControllerName : gatewayv1 .GatewayController (config .ControllerConfig .ControllerName ),
238221 }
239222 for _ , condition := range gateway .Conditions {
240223 parentStatus .Conditions = MergeCondition (parentStatus .Conditions , condition )
241224 }
242- SetRouteConditionResolvedRefs (& parentStatus , hr .GetGeneration (), resolveRefStatus .status , resolveRefStatus .msg )
243- hr .Status .Parents = append (hr .Status .Parents , parentStatus )
244225 if gateway .ListenerName == "" {
245226 continue
246227 }
247- SetRouteParentStatusCondtion (& parentStatus , conditionAccepted )
228+ SetRouteConditionResolvedRefs (& parentStatus , hr .GetGeneration (), resolveRefStatus .status , resolveRefStatus .msg )
229+ // if the HTTPRoute is not accepted, the length of .Status.Parents should be 0 or 1. If it is 1, it can only contain a condition with Status="False"
230+ if accepted := SetRouteConditionAccepted (& parentStatus , gateway .Gateway , hr , acceptStatus .status , acceptStatus .msg ); ! accepted {
231+ hr .Status .Parents = []gatewayv1.RouteParentStatus {
232+ parentStatus ,
233+ }
234+ break
235+ }
236+ hr .Status .Parents = append (hr .Status .Parents , parentStatus )
248237 }
249238 if err := r .Status ().Update (ctx , hr ); err != nil {
250239 return ctrl.Result {}, err
0 commit comments