Skip to content

Commit 37f5511

Browse files
committed
fix:
1 parent 0725fb5 commit 37f5511

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

internal/controller/httproute_controller.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

internal/controller/utils.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ func SetRouteConditionResolvedRefs(routeParentStatus *gatewayv1.RouteParentStatu
258258
condition.Status = metav1.ConditionFalse
259259
condition.Message = err.Error()
260260

261-
if re := new(ReasonError); errors.As(err, &re) {
261+
var re ReasonError
262+
if errors.As(err, &re) {
262263
condition.Reason = re.Reason
263264
}
264265
}
@@ -917,7 +918,7 @@ func IsSomeReasonError[Reason ~string](err error, reasons ...Reason) bool {
917918
if err == nil {
918919
return false
919920
}
920-
var re = new(ReasonError)
921+
var re ReasonError
921922
if !errors.As(err, &re) {
922923
return false
923924
}
@@ -927,8 +928,8 @@ func IsSomeReasonError[Reason ~string](err error, reasons ...Reason) bool {
927928
return slices.Contains(reasons, Reason(re.Reason))
928929
}
929930

930-
func newInvalidKindError[Kind ~string](kind Kind) *ReasonError {
931-
return &ReasonError{
931+
func newInvalidKindError[Kind ~string](kind Kind) ReasonError {
932+
return ReasonError{
932933
Reason: string(gatewayv1.RouteReasonInvalidKind),
933934
Message: fmt.Sprintf("Invalid kind %s, only Service is supported", kind),
934935
}

test/conformance/conformance_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ func TestGatewayAPIConformance(t *testing.T) {
6363
require.NoError(t, err)
6464

6565
t.Log("starting the gateway conformance test suite")
66+
tests.ConformanceTests = []suite.ConformanceTest{
67+
tests.HTTPRouteInvalidBackendRefUnknownKind,
68+
tests.HTTPRouteInvalidCrossNamespaceBackendRef,
69+
tests.HTTPRouteInvalidReferenceGrant,
70+
tests.HTTPRoutePartiallyInvalidViaInvalidReferenceGrant,
71+
tests.HTTPRouteReferenceGrant,
72+
}
6673
cSuite.Setup(t, tests.ConformanceTests)
6774

6875
if err := cSuite.Run(t, tests.ConformanceTests); err != nil {

0 commit comments

Comments
 (0)