Skip to content

Commit caf2f5b

Browse files
committed
fix: backendRefUnknownKind
Signed-off-by: ashing <[email protected]>
1 parent d89df03 commit caf2f5b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

internal/controller/httproute_controller.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,14 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
170170
}
171171
}
172172

173+
var httpRouteErr error
173174
if err := r.processHTTPRoute(tctx, hr); err != nil {
174-
acceptStatus.status = false
175-
acceptStatus.msg = err.Error()
175+
httpRouteErr = err
176+
// When encountering a backend reference error, it should not affect the acceptance status
177+
if !strings.Contains(err.Error(), string(gatewayv1.RouteReasonInvalidKind)) {
178+
acceptStatus.status = false
179+
acceptStatus.msg = err.Error()
180+
}
176181
}
177182

178183
if err := r.processHTTPRoutePolicies(tctx, hr); err != nil {
@@ -187,6 +192,13 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
187192
}
188193
}
189194

195+
// If the backend reference error is because of an invalid kind, use this error first
196+
if httpRouteErr != nil && strings.Contains(httpRouteErr.Error(), string(gatewayv1.RouteReasonInvalidKind)) {
197+
resolveRefStatus = status{
198+
status: false,
199+
msg: httpRouteErr.Error(),
200+
}
201+
}
190202
ProcessBackendTrafficPolicy(r.Client, r.Log, tctx)
191203

192204
if err := r.Provider.Update(ctx, tctx, hr); err != nil {
@@ -492,7 +504,7 @@ func (r *HTTPRouteReconciler) processHTTPRoute(tctx *provider.TranslateContext,
492504
kind = strings.ToLower(string(*backend.Kind))
493505
}
494506
if kind != "service" {
495-
terror = fmt.Errorf("kind %s is not supported", kind)
507+
terror = fmt.Errorf("%s %s", string(gatewayv1.RouteReasonInvalidKind), kind)
496508
continue
497509
}
498510

internal/controller/utils.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,16 @@ func SetRouteConditionResolvedRefs(routeParentStatus *gatewayv1.RouteParentStatu
249249
conditionStatus = metav1.ConditionFalse
250250
}
251251

252+
reason := string(gatewayv1.RouteReasonResolvedRefs)
253+
// check if the error message contains InvalidKind
254+
if !status && strings.Contains(message, string(gatewayv1.RouteReasonInvalidKind)) {
255+
reason = string(gatewayv1.RouteReasonInvalidKind)
256+
}
257+
252258
condition := metav1.Condition{
253259
Type: string(gatewayv1.RouteConditionResolvedRefs),
254260
Status: conditionStatus,
255-
Reason: string(gatewayv1.RouteReasonResolvedRefs),
261+
Reason: reason,
256262
ObservedGeneration: generation,
257263
Message: message,
258264
LastTransitionTime: metav1.Now(),

0 commit comments

Comments
 (0)