fix: nil guard SandboxConditionPaused in calculateStatus#572
fix: nil guard SandboxConditionPaused in calculateStatus#572ashnaaseth2325-oss wants to merge 1 commit into
Conversation
Signed-off-by: ashnaaseth2325-oss <ashnaaseth2325@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #572 +/- ##
=======================================
Coverage 79.78% 79.78%
=======================================
Files 202 202
Lines 14688 14688
=======================================
Hits 11719 11719
Misses 2544 2544
Partials 425 425
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
zmberg
left a comment
There was a problem hiding this comment.
Code Review
Thanks for the fix! The nil guard correctly prevents the panic. A couple of suggestions below:
- Issue: 1
- Suggestion: 1
| cond := utils.GetSandboxCondition(newStatus, string(agentsv1alpha1.SandboxConditionPaused)) | ||
| // sandbox will only enter the resuming state after successful paused | ||
| if cond.Status == metav1.ConditionTrue && !box.Spec.Paused { | ||
| if cond != nil && cond.Status == metav1.ConditionTrue && !box.Spec.Paused { |
There was a problem hiding this comment.
[Issue] The PR correctly adds cond != nil defensive checks to prevent nil pointer panics. However, when cond == nil, neither branch is entered and calculateStatus silently skips processing. This edge case lacks observability.
Suggest adding a cond == nil branch with a log message (e.g., klog.InfoS recording that the sandbox is in Paused phase but the paused condition is absent) to make this scenario traceable in production. The existing EnsureSandboxPaused mechanism will naturally handle condition initialization, so no control flow change is needed.
| } else if cond != nil && !box.Spec.Paused && cond.Status == metav1.ConditionFalse { | ||
| klog.InfoS("sandbox pause not completed, cannot enter resume state temporarily", "sandbox", klog.KObj(box)) | ||
| } | ||
|
|
There was a problem hiding this comment.
[Suggestion] Suggest adding test cases to cover the cond == nil scenario — verifying the controller's behavior when the SandboxPaused phase lacks the paused condition — to prevent regressions. Existing Paused-related test cases in TestCalculateStatus can serve as reference.
SUMMARY
This PR adds nil checks before accessing
SandboxConditionPausedin the Sandbox controller's status calculation logic. It prevents a potential nil pointer dereference when a Sandbox is in thePausedphase but the corresponding paused condition is absent.The change is limited to
pkg/controller/sandbox/sandbox_controller.go, specifically thecalculateStatus()logic for theSandboxPausedstate.FIX