Skip to content

Commit

Permalink
Fix requeue on error of APIRule (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
barchw authored Dec 23, 2024
1 parent 3a859c3 commit 84ba1b7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ COPY manifests/ manifests/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGET_OS:-linux} GOARCH=${TARGET_ARCH:-amd64} go build -tags ${GO_BUILD_TAGS} -ldflags="-X 'github.com/kyma-project/api-gateway/internal/version.version=${VERSION:-}'" -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=${TARGET_OS:-linux} GOARCH=${TARGET_ARCH:-amd64} go build -tags ${GO_BUILD_TAGS} -ldflags="-s -w -X 'github.com/kyma-project/api-gateway/internal/version.version=${VERSION:-}'" -o manager main.go


# Use distroless as minimal base image to package the manager binary
Expand Down
8 changes: 4 additions & 4 deletions controllers/gateway/apirule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r *APIRuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
l.Error(err, "Error updating APIRule status")
return doneReconcileErrorRequeue(err, r.OnErrorReconcilePeriod)
}
return r.updateStatus(ctx, l, &apiRule)
return r.updateStatus(ctx, l, &apiRule, s.HasError())
}

l.Info("Validating APIRule config")
Expand All @@ -150,7 +150,7 @@ func (r *APIRuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
l.Error(err, "Error updating APIRule status")
return doneReconcileErrorRequeue(err, r.OnErrorReconcilePeriod)
}
return r.updateStatus(ctx, l, &apiRule)
return r.updateStatus(ctx, l, &apiRule, s.HasError())
}

l.Info("Reconciling APIRule sub-resources")
Expand All @@ -164,7 +164,7 @@ func (r *APIRuleReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
}
return doneReconcileErrorRequeue(err, r.OnErrorReconcilePeriod)
}
return r.updateStatus(ctx, l, &apiRule)
return r.updateStatus(ctx, l, &apiRule, s.HasError())
}

func (r *APIRuleReconciler) reconcileV2Alpha1APIRule(ctx context.Context, l logr.Logger, apiRule gatewayv1beta1.APIRule) (ctrl.Result, error) {
Expand Down Expand Up @@ -245,7 +245,7 @@ func (r *APIRuleReconciler) convertAndUpdateStatus(ctx context.Context, l logr.L
if err := rule.ConvertTo(&toUpdate); err != nil {
return doneReconcileErrorRequeue(err, r.OnErrorReconcilePeriod)
}
return r.updateStatus(ctx, l, &toUpdate)
return r.updateStatus(ctx, l, &toUpdate, false)
}

func (r *APIRuleReconciler) updateResourceRequeue(ctx context.Context,
Expand Down
6 changes: 5 additions & 1 deletion controllers/gateway/reconcile_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func doneReconcileMigrationRequeue(reconcilerPeriod time.Duration) (ctrl.Result,
}

func (r *APIRuleReconciler) updateStatus(ctx context.Context, l logr.Logger,
apiRule client.Object) (ctrl.Result, error) {
apiRule client.Object, reconcileError bool) (ctrl.Result, error) {
l.Info("Updating APIRule status")
if err := r.Status().Update(ctx, apiRule); err != nil {
l.Error(err, "Error updating APIRule status")
Expand All @@ -49,6 +49,10 @@ func (r *APIRuleReconciler) updateStatus(ctx context.Context, l logr.Logger,
l.Info("Finished reconciliation", "next", r.MigrationReconcilePeriod)
return doneReconcileMigrationRequeue(r.MigrationReconcilePeriod)
}
if reconcileError {
l.Info("Finished reconciliation with error", "next", r.OnErrorReconcilePeriod)
return doneReconcileErrorRequeue(nil, r.OnErrorReconcilePeriod)
}
l.Info("Finished reconciliation", "next", r.ReconcilePeriod)
return doneReconcileDefaultRequeue(r.ReconcilePeriod)
}

0 comments on commit 84ba1b7

Please sign in to comment.