-
Notifications
You must be signed in to change notification settings - Fork 10
Improve watch setup in BIOSSettingsReconciler
#568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
b28b5b9 to
e032eb0
Compare
2cdc398 to
d9b698d
Compare
WalkthroughRename local variables (host→server, biosSettings→settings), add per-entity logging contexts ( Changes
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. ✨ Finishing touches
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used🧬 Code graph analysis (1)internal/controller/biossettings_controller.go (4)
🔇 Additional comments (4)
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/controller/biossettings_controller.go (1)
1357-1367: Consider separating error and condition checks for improved clarity.The new reset condition logic adds intelligent filtering to avoid unnecessary reconciliations. However, the condition check on line 1362 could be more explicit for defensive programming:
♻️ Suggested refactor for clarity
- if settings.Status.State != metalv1alpha1.BIOSSettingsStateInProgress { - continue - } - - resetCond, err := GetCondition(r.Conditions, settings.Status.Conditions, BMCConditionReset) - if err != nil || resetCond.Status == metav1.ConditionTrue { - continue - } - if resetCond.Reason == BMCReasonReset { - reqs = append(reqs, ctrl.Request{NamespacedName: types.NamespacedName{Name: settings.Name}}) - } + if settings.Status.State != metalv1alpha1.BIOSSettingsStateInProgress { + continue + } + + resetCond, err := GetCondition(r.Conditions, settings.Status.Conditions, BMCConditionReset) + if err != nil { + continue + } + if resetCond.Status == metav1.ConditionTrue { + continue + } + if resetCond.Reason == BMCReasonReset { + reqs = append(reqs, ctrl.Request{NamespacedName: types.NamespacedName{Name: settings.Name}}) + }This separates error handling from condition checking, making the logic flow more explicit and maintainable.
Additionally, verify that this reset condition filtering integrates correctly with the BMC reset flow in
handleBMCReset(lines 491-540) to ensure settings are reconciled at the appropriate time after BMC reset completion.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/controller/biossettings_controller.go
🧰 Additional context used
🧬 Code graph analysis (1)
internal/controller/biossettings_controller.go (5)
api/v1alpha1/server_types.go (4)
Server(428-434)ServerStateDiscovery(150-150)ServerStateError(159-159)ServerStateInitial(147-147)api/v1alpha1/biossettings_types.go (5)
BIOSSettingsList(151-155)BIOSSettingsStateApplied(67-67)BIOSSettingsStateFailed(69-69)BIOSSettings(140-146)BIOSSettingsStateInProgress(65-65)api/v1alpha1/bmc_types.go (1)
BMC(248-254)internal/controller/helper.go (1)
GetCondition(48-66)api/v1alpha1/biosversion_types.go (2)
BIOSVersion(130-136)BIOSVersionStateCompleted(21-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Run linter
- GitHub Check: Run test chart
- GitHub Check: Run tests
- GitHub Check: Run test e2e
🔇 Additional comments (2)
internal/controller/biossettings_controller.go (2)
1307-1333: LGTM! Variable renaming and logging improvements enhance code clarity.The refactoring from
hosttoserverandbiosSettingsListtosettingsListimproves naming consistency across the codebase. The enhanced logging with contextual values will aid in debugging watch events.The simplified logic at lines 1325-1327 now gates enqueue based solely on the presence of
settings.Spec.ServerMaintenanceRefalong with state checks, which streamlines the filtering logic.
1372-1395: LGTM! Consistent refactoring with clear intent.The variable renaming from
biosVersiontoversionandbiosSettingsListtosettingsListmaintains consistency with the other watch functions. The enhanced logging and filtering logic correctly enqueues BIOSSettings that require reconciliation when a BIOS version update completes.
d9b698d to
e5e6c94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/controller/biossettings_controller.go (1)
1335-1373: Approve with optional refactor for clarity.The logging context and variable renaming improvements are good. The new gating logic correctly enqueues BIOSSettings only when a BMC reset was issued but not yet completed, triggering reconciliation when the BMC becomes available again after reset.
♻️ Optional: Simplify nested conditions for clarity
The nested condition checks on lines 1357-1369 are functionally correct but could be clearer:
for _, server := range serverList.Items { if server.Spec.BIOSSettingsRef == nil { continue } settings := &metalv1alpha1.BIOSSettings{} if err := r.Get(ctx, types.NamespacedName{Name: server.Spec.BIOSSettingsRef.Name}, settings); err != nil { log.Error(err, "failed to get BIOSSettings, skipping", "name", server.Spec.BIOSSettingsRef.Name) continue } - if settings.Status.State != metalv1alpha1.BIOSSettingsStateInProgress { - continue - } - - resetCond, err := GetCondition(r.Conditions, settings.Status.Conditions, BMCConditionReset) - if err != nil { - continue - } - if resetCond.Status == metav1.ConditionTrue { - continue - } - if resetCond.Reason == BMCReasonReset { - reqs = append(reqs, ctrl.Request{NamespacedName: types.NamespacedName{Name: settings.Name}}) - } + // Only enqueue if BMC reset was issued but not yet completed + if settings.Status.State == metalv1alpha1.BIOSSettingsStateInProgress { + resetCond, err := GetCondition(r.Conditions, settings.Status.Conditions, BMCConditionReset) + if err == nil && resetCond.Status != metav1.ConditionTrue && resetCond.Reason == BMCReasonReset { + reqs = append(reqs, ctrl.Request{NamespacedName: types.NamespacedName{Name: settings.Name}}) + } + } }This consolidates the conditions and adds a clarifying comment.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/controller/biossettings_controller.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Run test e2e
- GitHub Check: Run test chart
- GitHub Check: Run tests
🔇 Additional comments (2)
internal/controller/biossettings_controller.go (2)
1307-1333: LGTM! Clean refactoring with improved logging context.The variable renaming (
host→server,BIOSSettingsList→settingsList,biosSettings→settings) and the addition of server-scoped logging improve code clarity. The filtering logic correctly enqueues only settings that have an active ServerMaintenanceRef and are not in a terminal state (Applied/Failed).
1375-1398: LGTM! Consistent refactoring with improved logging.The variable renaming and addition of BIOSVersion-scoped logging maintain consistency with the other enqueue functions. The logic correctly triggers reconciliation when a BIOSVersion update completes, enqueuing only non-terminal BIOSSettings.
e5e6c94 to
5991394
Compare
There was a problem hiding this 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/biossettings_controller.go:
- Around line 1376-1380: version.Spec.ServerRef is optional and may be nil;
before calling r.List with client.MatchingFields{serverRefField:
version.Spec.ServerRef.Name} add a nil check for version.Spec.ServerRef (in the
reconcile method where r.List is called) and handle the nil case (either skip
listing, use an empty string, or return an appropriate error) so you never
dereference .Name; update the code around the r.List call that references
serverRefField and version.Spec.ServerRef.Name to first branch on
version.Spec.ServerRef == nil and act accordingly.
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/controller/biossettings_controller.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Run test chart
- GitHub Check: Run tests
- GitHub Check: Run test e2e
🔇 Additional comments (2)
internal/controller/biossettings_controller.go (2)
1307-1333: LGTM!The renaming improves consistency (
server,settings,settingsList) and the per-entity logging context enhances traceability. The filtering logic correctly gates enqueueing to BIOSSettings that have an active maintenance reference and are not in terminal states.
1335-1366: LGTM!The refined gating logic at lines 1358-1361 precisely targets the BMC reset pending scenario, avoiding unnecessary reconciliations. The added logging context improves debuggability.
5991394 to
453ad88
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
internal/controller/biossettings_controller.go (1)
1325-1330: Verify removal of ServerMaintenanceRef equality check is intentional.The enqueue logic now includes all BIOSSettings with a non-nil
ServerMaintenanceRef, regardless of whether it matches the Server's currentServerMaintenanceRef. This could trigger reconciliations for BIOSSettings that are associated with a different ServerMaintenance.While the
isServerInMaintenancefunction (line 1059) does verify the UID match during reconciliation, this approach may cause unnecessary reconciliations when multiple BIOSSettings reference the same Server.Consider adding back the ServerMaintenanceRef equality check to avoid unnecessary work:
🔍 Suggested refinement
reqs := make([]ctrl.Request, 0, len(settingsList.Items)) for _, settings := range settingsList.Items { if settings.Spec.ServerMaintenanceRef == nil || + (server.Spec.ServerMaintenanceRef != nil && + server.Spec.ServerMaintenanceRef.UID != settings.Spec.ServerMaintenanceRef.UID) || settings.Status.State == metalv1alpha1.BIOSSettingsStateApplied || settings.Status.State == metalv1alpha1.BIOSSettingsStateFailed { continue } reqs = append(reqs, ctrl.Request{NamespacedName: types.NamespacedName{Name: settings.Name}}) }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
internal/controller/biossettings_controller.go
🔇 Additional comments (2)
internal/controller/biossettings_controller.go (2)
1357-1362: LGTM! BMC reset enqueue logic is precise.The enqueue condition correctly identifies BIOSSettings where a BMC reset has been issued but not yet completed, matching the intent described in the comment. The logic properly checks both the condition status and reason to avoid spurious reconciliations.
1368-1391: LGTM! BIOSVersion enqueue logic is sound.The function correctly enqueues BIOSSettings for reconciliation after a BIOS version update completes. The filtering logic appropriately skips settings in terminal states (Applied/Failed) and focuses on active settings that may need to respond to the version change.
The addition of per-entity logging context improves observability.
453ad88 to
f8a5003
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Proposed Changes
Improve watch setup in
BIOSSettingsReconciler.Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.