Skip to content

Comments

Harmonize BMCUser reconciler and improve finalizer deletion#627

Merged
afritzler merged 2 commits intomainfrom
chore/bmcuser
Jan 29, 2026
Merged

Harmonize BMCUser reconciler and improve finalizer deletion#627
afritzler merged 2 commits intomainfrom
chore/bmcuser

Conversation

@afritzler
Copy link
Member

@afritzler afritzler commented Jan 29, 2026

Summary by CodeRabbit

  • Refactor

    • Improved resource deletion and finalization flow for BMC user resources with more consistent result propagation and graceful handling when referenced systems are absent.
    • Streamlined logging to reduce verbosity and clarify lifecycle messages.
    • Simplified password rotation flow and consolidated requeue behavior for clearer operation timing and status updates.
  • Bug Fixes

    • More robust BMC connection and auth error handling (including 401/403/404 cases) to preserve status and reduce unnecessary retries.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

Warning

Rate limit exceeded

@afritzler has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 1 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

Walkthrough

Renamed BMCUser finalizer constant and changed the controller deletion path: delete() now returns (ctrl.Result, error). Reconciler logging and object lookups were simplified, some HTTP error handling switched to errors.As, and password-rotation requeue/status flows were adjusted.

Changes

Cohort / File(s) Summary
BMCUser Controller
internal/controller/bmcuser_controller.go
Finalizer constant value changed. delete() signature updated from error to (ctrl.Result, error). Deletion path now returns ctrl.Result directly and patches finalizer removal. Simplified client.Get usages to inline Name fields, standardized log messages (removed per-user context), switched several HTTP error checks to errors.As, and consolidated rotation requeue/status handling and secret/status patch return patterns.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

size/L, area/metal-automation

Suggested reviewers

  • hardikdr
  • Nuckal777
  • stefanhipfel
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is entirely missing; the author did not provide any content describing the proposed changes, despite the template requiring a 'Proposed Changes' section with bullet points and issue references. Add a pull request description following the template structure, listing key changes (finalizer constant update, delete method signature change, deletion flow refactoring) and any related issue numbers.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The PR title 'Harmonize BMCUser reconciler and improve finalizer deletion' directly aligns with the main changes: code harmonization and finalizer-related fixes in the BMCUser reconciler.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@afritzler
Copy link
Member Author

@coderabbitai review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@afritzler
Copy link
Member Author

@coderabbitai help

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

CodeRabbit commands

These commands are invoked using PR/Issue comments.

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai evaluate custom pre-merge check --instructions <custom-checks-instructions> --name <custom-checks-title> [--mode <error|warning>] to validate the custom pre-merge checks instructions. Defaults to error when --mode is omitted.
    • @coderabbitai ignore pre-merge checks to override pre-merge checks and get an approval on PR.
    • @coderabbitai run pre-merge checks to run pre-merge checks on the pull request.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai generate configuration to create a PR that adds the current resolved configuration as .coderabbit.yaml (or show it if already present).
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit configuration file (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, support, documentation and community

  • Visit our status page to check the current availability of CodeRabbit.
  • Create a ticket on our support page for assistance with any issues or questions.
  • Visit our documentation site for detailed information on how to use CodeRabbit.
  • Join our Discord community to connect with other users and get help from the community.
  • Follow us on X/Twitter for updates and announcements.

@afritzler
Copy link
Member Author

@coderabbitai summary

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

✅ Actions performed

Summary regeneration triggered.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions bot added size/L and removed size/M labels Jan 29, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@afritzler afritzler changed the title Harmonize BMCUser reconciler code Harmonize BMCUser reconciler and improve finalizer deletion Jan 29, 2026
@afritzler
Copy link
Member Author

@coderabbitai summary

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 29, 2026

✅ Actions performed

Summary regeneration triggered.

@afritzler afritzler added enhancement New feature or request and removed chore labels Jan 29, 2026
@afritzler afritzler merged commit f90c9e2 into main Jan 29, 2026
21 checks passed
@github-project-automation github-project-automation bot moved this to Done in Roadmap Jan 29, 2026
@afritzler afritzler deleted the chore/bmcuser branch January 29, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants