CNTRLPLANE-3691: Decouple NodePool condition handling from CAPI reconciliation#9032
Conversation
CAPI.Reconcile() was setting NodePool conditions inline, mixing CAPI resource reconciliation with NodePool status management. This made capi.go harder to reason about and violated separation of concerns. Introduce a CAPIResult struct returned by CAPI.Reconcile() that carries condition information back to the caller. The caller in nodepool_controller.go now sets conditions on the NodePool after the CAPI reconciliation completes, centralizing condition management in the controller layer. Conditions moved: - NodePoolUpdatingPlatformMachineTemplateConditionType - NodePoolAutorepairEnabledConditionType - NodePoolReadyConditionType (from both MachineDeployment and MachineSet) No behavioral change — the same conditions are set under the same circumstances. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Capture and validate the CAPIResult returned by capi.Reconcile() in TestCAPIReconcile, TestCAPIReconcile_machineset, and fix a pre-existing test bug in TestReconcileMachineDeploymentStatus where conditions accumulated on capi.conditions were not applied to the NodePool. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@hypershift-jira-solve-ci[bot]: This pull request references CNTRLPLANE-3691 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the task to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
📝 WalkthroughWalkthrough
Sequence Diagram(s)sequenceDiagram
participant NodePoolReconciler
participant CAPI
participant MachineResources
NodePoolReconciler->>CAPI: Reconcile(ctx)
CAPI->>MachineResources: Reconcile machines and health checks
MachineResources-->>CAPI: Status and errors
CAPI-->>NodePoolReconciler: CAPIResult with conditions
NodePoolReconciler->>NodePoolReconciler: Apply conditions to NodePool status
Possibly related PRs
🚥 Pre-merge checks | ✅ 10 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (10 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hypershift-jira-solve-ci[bot] 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
hypershift-operator/controllers/nodepool/capi_test.go (1)
1884-1890: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the expected condition contract, not merely a non-empty result.
These assertions pass if only an unrelated condition is returned. Add expected condition type/status assertions per fixture, particularly for autorepair and ready-condition paths.
hypershift-operator/controllers/nodepool/capi_test.go#L1884-L1890: assert the conditions expected from the initial reconciliation.hypershift-operator/controllers/nodepool/capi_test.go#L2000-L2003: assert the expected condition after rollout completion.hypershift-operator/controllers/nodepool/capi_test.go#L2172-L2182: assert the in-place reconciliation condition set.As per coding guidelines, “Unit test any code changes and additions.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@hypershift-operator/controllers/nodepool/capi_test.go` around lines 1884 - 1890, Strengthen the condition assertions in hypershift-operator/controllers/nodepool/capi_test.go at lines 1884-1890, 2000-2003, and 2172-2182: use each fixture’s expected condition type and status, including autorepair, ready-condition, rollout-completion, and in-place reconciliation paths, rather than only checking that conditions are non-empty. Update the tests around the capi.Reconcile calls and add or adjust unit-test expectations for every affected scenario.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@hypershift-operator/controllers/nodepool/capi.go`:
- Around line 150-151: Preserve accumulated conditions after CAPI reconciliation
begins: in CAPI.Reconcile, return the accumulated CAPIResult alongside errors on
every subsequent error path, including the MachineSet failure near
hypershift-operator/controllers/nodepool/capi.go:150-151. In
hypershift-operator/controllers/nodepool/nodepool_controller.go:429-440, apply
any non-nil CAPIResult before handling and returning the reconciliation error.
---
Nitpick comments:
In `@hypershift-operator/controllers/nodepool/capi_test.go`:
- Around line 1884-1890: Strengthen the condition assertions in
hypershift-operator/controllers/nodepool/capi_test.go at lines 1884-1890,
2000-2003, and 2172-2182: use each fixture’s expected condition type and status,
including autorepair, ready-condition, rollout-completion, and in-place
reconciliation paths, rather than only checking that conditions are non-empty.
Update the tests around the capi.Reconcile calls and add or adjust unit-test
expectations for every affected scenario.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 1b60cd96-8142-43b2-8179-b7be4e59fd53
📒 Files selected for processing (3)
hypershift-operator/controllers/nodepool/capi.gohypershift-operator/controllers/nodepool/capi_test.gohypershift-operator/controllers/nodepool/nodepool_controller.go
| return nil, fmt.Errorf("failed to reconcile MachineSet %q: %w", | ||
| client.ObjectKeyFromObject(ms).String(), err) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve accumulated conditions when CAPI reconciliation fails.
A condition is appended before these later failures, but CAPI.Reconcile returns nil, err; the controller therefore returns before applying it. Previously, the inline status mutation was patched even on reconcile errors, so this loses status updates such as the platform-template condition.
hypershift-operator/controllers/nodepool/capi.go#L150-L151: return the accumulatedCAPIResulton every error path reached after condition collection begins.hypershift-operator/controllers/nodepool/nodepool_controller.go#L429-L440: apply a non-nil result before handling and returning the error.
📍 Affects 2 files
hypershift-operator/controllers/nodepool/capi.go#L150-L151(this comment)hypershift-operator/controllers/nodepool/nodepool_controller.go#L429-L440
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@hypershift-operator/controllers/nodepool/capi.go` around lines 150 - 151,
Preserve accumulated conditions after CAPI reconciliation begins: in
CAPI.Reconcile, return the accumulated CAPIResult alongside errors on every
subsequent error path, including the MachineSet failure near
hypershift-operator/controllers/nodepool/capi.go:150-151. In
hypershift-operator/controllers/nodepool/nodepool_controller.go:429-440, apply
any non-nil CAPIResult before handling and returning the reconciliation error.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9032 +/- ##
=========================================
Coverage 44.11% 44.11%
=========================================
Files 772 779 +7
Lines 96227 98065 +1838
=========================================
+ Hits 42449 43262 +813
- Misses 50832 51769 +937
- Partials 2946 3034 +88
... and 25 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
@hypershift-jira-solve-ci[bot]: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
What this PR does / why we need it:
Decouples NodePool condition management from
CAPI.Reconcile()by introducing aCAPIResultstruct that carries condition information back to the caller. Previously,CAPI.Reconcile()was setting NodePool conditions inline, mixing CAPI resource reconciliation with NodePool status management. This madecapi.goharder to reason about and violated separation of concerns.The caller in
nodepool_controller.gonow sets conditions on the NodePool after the CAPI reconciliation completes, centralizing condition management in the controller layer.Conditions moved:
NodePoolUpdatingPlatformMachineTemplateConditionTypeNodePoolAutorepairEnabledConditionTypeNodePoolReadyConditionType(from both MachineDeployment and MachineSet)No behavioral change — the same conditions are set under the same circumstances.
Tests are updated to capture and validate the
CAPIResultreturned bycapi.Reconcile(), and a pre-existing test bug is fixed where conditions accumulated oncapi.conditionswere not applied to the NodePool.Which issue(s) this PR fixes:
Fixes https://redhat.atlassian.net/browse/CNTRLPLANE-3691
Special notes for your reviewer:
This is a pure refactor with no behavioral change. The diff is large because condition-setting logic moves from
capi.gotonodepool_controller.go, but the conditions themselves and when they are set remain identical.Checklist:
Always review AI generated responses prior to use.
Generated with Claude Code via openshift-developer plugin
Summary by CodeRabbit
Bug Fixes
Tests