@@ -174,11 +174,12 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
174174 }
175175 }
176176
177- var httpRouteErr error
177+ var backendRefErr error
178178 if err := r .processHTTPRoute (tctx , hr ); err != nil {
179- httpRouteErr = err
180179 // When encountering a backend reference error, it should not affect the acceptance status
181- if ! IsSomeReasonError (err , gatewayv1 .RouteReasonInvalidKind ) {
180+ if IsSomeReasonError (err , gatewayv1 .RouteReasonInvalidKind ) {
181+ backendRefErr = err
182+ } else {
182183 acceptStatus .status = false
183184 acceptStatus .msg = err .Error ()
184185 }
@@ -189,16 +190,12 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
189190 acceptStatus .msg = err .Error ()
190191 }
191192
192- // Store the backend reference error for later use
193- var backendRefErr error
194- if err := r .processHTTPRouteBackendRefs (tctx , req .NamespacedName ); err != nil {
193+ // Store the backend reference error for later use.
194+ // If the backend reference error is because of an invalid kind, use this error first
195+ if err := r .processHTTPRouteBackendRefs (tctx , req .NamespacedName ); err != nil && backendRefErr == nil {
195196 backendRefErr = err
196197 }
197198
198- // If the backend reference error is because of an invalid kind, use this error first
199- if IsSomeReasonError (err , gatewayv1 .RouteReasonInvalidKind ) {
200- backendRefErr = httpRouteErr
201- }
202199 ProcessBackendTrafficPolicy (r .Client , r .Log , tctx )
203200
204201 filteredHTTPRoute , err := filterHostnames (gateways , hr .DeepCopy ())
@@ -436,7 +433,7 @@ func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.Transla
436433 }
437434
438435 if backend .Kind != nil && * backend .Kind != "Service" {
439- terr = & ReasonError {
436+ terr = ReasonError {
440437 Reason : string (gatewayv1 .RouteReasonInvalidKind ),
441438 Message : fmt .Sprintf ("invalid kind %s, only Service is supported" , * backend .Kind ),
442439 }
@@ -452,7 +449,7 @@ func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.Transla
452449 if err := r .Get (tctx , targetNN , & service ); err != nil {
453450 terr = err
454451 if client .IgnoreNotFound (err ) == nil {
455- terr = & ReasonError {
452+ terr = ReasonError {
456453 Reason : string (gatewayv1 .RouteReasonBackendNotFound ),
457454 Message : fmt .Sprintf ("Service %s not found" , targetNN ),
458455 }
@@ -468,7 +465,7 @@ func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.Transla
468465 return err
469466 }
470467 if ! checkReferenceGrantBetweenHTTPRouteAndService (hrNN , targetNN , referenceGrantList .Items ) {
471- terr = & ReasonError {
468+ terr = ReasonError {
472469 Reason : string (v1beta1 .RouteReasonRefNotPermitted ),
473470 Message : fmt .Sprintf ("%s is in a different namespace than the HTTPRoute %s and no ReferenceGrant allowing reference is configured" , targetNN , hrNN ),
474471 }
0 commit comments