Conversation
The error was actually in result.Err, not err. So handle and return that one.
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
Comment Tip Migrating from UI to YAML configuration.Use the |
There was a problem hiding this comment.
Pull request overview
Fixes error handling in the traits update reconciliation flow so the actual Placement update error is surfaced instead of being overwritten by a subsequent status patch error.
Changes:
- Use
result.Errfromopenstack.UpdateTraits(...)as the primary error signal. - Preserve the original update error by
errors.Join(err, statusPatchErr)when attempting to patch status conditions on failure.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/controller/traits_controller.go (1)
105-111:⚠️ Potential issue | 🔴 CriticalGetTraits failure can still be swallowed when status patch succeeds.
On this path,
erris overwritten witherrors.Join(tc.Status().Patch(...)), so a successful patch can turn a realGetTraitserror intoniland report reconcile success.Suggested fix
if err != nil { base := hv.DeepCopy() if meta.SetStatusCondition(&hv.Status.Conditions, getTraitCondition(err, "Failed to get current traits from placement")) { - err = errors.Join(tc.Status().Patch(ctx, hv, k8sclient.MergeFromWithOptions(base, - k8sclient.MergeFromWithOptimisticLock{}), k8sclient.FieldOwner(TraitsControllerName))) + err = errors.Join(err, + tc.Status().Patch(ctx, hv, k8sclient.MergeFromWithOptions(base, + k8sclient.MergeFromWithOptimisticLock{}), k8sclient.FieldOwner(TraitsControllerName))) } return ctrl.Result{}, err }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/controller/traits_controller.go` around lines 105 - 111, The current code overwrites the original GetTraits error by assigning err = errors.Join(tc.Status().Patch(...)), which can turn a real GetTraits failure into nil when the patch succeeds; fix this in the block that handles hv/status patching by capturing the original error (e.g., getTraitsErr := err) before the patch call, call patchErr := tc.Status().Patch(ctx, hv, k8sclient.MergeFromWithOptions(base, k8sclient.MergeFromWithOptimisticLock{}), k8sclient.FieldOwner(TraitsControllerName)), and then set err = errors.Join(getTraitsErr, patchErr) (or err = getTraitsErr if you prefer explicit logic) so the original GetTraits error is preserved and combined with any patch error; adjust the code around hv, meta.SetStatusCondition, getTraitCondition and the tc.Status().Patch invocation accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@internal/controller/traits_controller.go`:
- Around line 105-111: The current code overwrites the original GetTraits error
by assigning err = errors.Join(tc.Status().Patch(...)), which can turn a real
GetTraits failure into nil when the patch succeeds; fix this in the block that
handles hv/status patching by capturing the original error (e.g., getTraitsErr
:= err) before the patch call, call patchErr := tc.Status().Patch(ctx, hv,
k8sclient.MergeFromWithOptions(base, k8sclient.MergeFromWithOptimisticLock{}),
k8sclient.FieldOwner(TraitsControllerName)), and then set err =
errors.Join(getTraitsErr, patchErr) (or err = getTraitsErr if you prefer
explicit logic) so the original GetTraits error is preserved and combined with
any patch error; adjust the code around hv, meta.SetStatusCondition,
getTraitCondition and the tc.Status().Patch invocation accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a7dd38d1-622f-43bc-827f-e1b7863c2ca1
📒 Files selected for processing (1)
internal/controller/traits_controller.go
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. |
The error was actually in result.Err, not err. So handle and return that one.
Summary by CodeRabbit
Release Notes