Harmonize BMCUser reconciler and improve finalizer deletion#627
Harmonize BMCUser reconciler and improve finalizer deletion#627
BMCUser reconciler and improve finalizer deletion#627Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughRenamed BMCUser finalizer constant and changed the controller deletion path: Changes
Sequence Diagram(s)sequenceDiagram
participant Reconciler
participant API_Server as "K8s API Server"
participant BMC as "BMC (external)"
Reconciler->>API_Server: Get BMCUser
alt DeletionTimestamp set
Reconciler->>Reconciler: call delete(ctx, log, user)
Reconciler->>BMC: DeleteAccount (if BMCRef present)
alt 404 from BMC
BMC-->>Reconciler: 404 (treat as gone)
else other response
BMC-->>Reconciler: response/error
end
Reconciler->>API_Server: Patch remove finalizer / update status
API_Server-->>Reconciler: ack (ctrl.Result)
else Normal reconcile
Reconciler->>API_Server: Ensure finalizer present
Reconciler->>API_Server: Get referenced BMC (Name: user.Spec.BMCRef.Name)
Reconciler->>BMC: Auth check / connection test
alt Rotation required
Reconciler->>BMC: Rotate password / Update account
BMC-->>Reconciler: response/status (may be 401/403/404)
Reconciler->>API_Server: Patch status / set RequeueAfter
else No rotation
Reconciler->>API_Server: Patch status and exit
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
839a0fc to
c1be85d
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
@coderabbitai help |
ChatThere are 3 ways to chat with CodeRabbit:
CodeRabbit commands
Other keywords and placeholders
CodeRabbit configuration file (
|
|
@coderabbitai summary |
✅ Actions performedSummary regeneration triggered. |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/controller/bmcuser_controller.go (1)
167-173: RequeueAfter should use remaining time until rotation is due.Returning the full rotation period can push rotation later than intended; consider requeueing for the remaining duration instead.
🔧 Suggested adjustment
- return ctrl.Result{RequeueAfter: user.Spec.RotationPeriod.Duration}, nil + next := user.Status.LastRotation.Time.Add(user.Spec.RotationPeriod.Duration) + remaining := time.Until(next) + if remaining < 0 { + remaining = 0 + } + return ctrl.Result{RequeueAfter: remaining}, nil
🤖 Fix all issues with AI agents
In `@internal/controller/bmcuser_controller.go`:
- Around line 28-30: Existing BMCUserFinalizer changes can leave older BMCUser
objects stuck with the old finalizer; add a new constant like
LegacyBMCUserFinalizer for the previous finalizer string and update all
finalizer handling code (the reconcile path that ensures finalizers and the
deletion/finalize handlers such as your
ensureFinalizer/removeFinalizer/finalizeBMCUser functions) to treat either
BMCUserFinalizer or LegacyBMCUserFinalizer as valid: when reconciling, if the
legacy finalizer exists add the new one (and persist the update); when deleting,
accept either finalizer as a signal to run cleanup and remove both finalizers
(persisting the object via client.Update or client.Status().Update) so
legacy-finalizered objects can be cleaned up and unblocked during the migration
window.
- Around line 365-369: The delete method in BMCUserReconciler currently returns
early when user.Spec.BMCRef is nil or when the referenced BMC is not found,
leaving the object's finalizer in place; update the delete(ctx, log, user
*metalv1alpha1.BMCUser) function to remove the finalizer in those early-exit
paths (use controllerutil.RemoveFinalizer or remove the finalizer string from
user.Finalizers and call r.Update(ctx, user) or r.Client.Update) before
returning so deletion is idempotent. Also change the DeleteAccount error
handling in the same delete function to treat an HTTP 404 (account already
absent) as success — detect the 404 from the error returned by DeleteAccount and
proceed to remove the finalizer and return nil error instead of propagating the
error. Ensure you reference the BMCUserReconciler.delete function, the
DeleteAccount call, and the finalizer removal logic when making the change.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@internal/controller/bmcuser_controller.go`:
- Around line 401-404: The log "Successfully deleted BMC account and removed
finalizer for User" is emitted before the finalizer removal is attempted; move
or emit that log only after clientutils.PatchEnsureNoFinalizer(ctx, r.Client,
user, BMCUserFinalizer) returns with no error and modified==false (i.e.,
success). Specifically, call clientutils.PatchEnsureNoFinalizer first, check err
and modified, handle/return on error, and then call log.Info to report
successful finalizer removal; reference functions/vars:
clientutils.PatchEnsureNoFinalizer, BMCUserFinalizer, user, r.Client, ctx, and
log.Info.
aae33ab to
b67499f
Compare
BMCUser reconciler codeBMCUser reconciler and improve finalizer deletion
|
@coderabbitai summary |
✅ Actions performedSummary regeneration triggered. |
Summary by CodeRabbit
Refactor
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.