Skip to content

CNTRLPLANE-3532: migrate HO karpenter status patch to statuspatching helper - #8968

Open
vsolanki12 wants to merge 1 commit into
openshift:mainfrom
vsolanki12:vsolanki/cntrlplane-3532-ho-statuspatching
Open

CNTRLPLANE-3532: migrate HO karpenter status patch to statuspatching helper#8968
vsolanki12 wants to merge 1 commit into
openshift:mainfrom
vsolanki12:vsolanki/cntrlplane-3532-ho-statuspatching

Conversation

@vsolanki12

@vsolanki12 vsolanki12 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Migrates the manual MergeFrom status patch in reconcileKarpenterOperator to use statuspatching.PatchStatus, adding optimistic locking and retry-on-conflict for the AutoNode status clearing path.

This was a Tier 2 site — it used MergeFrom without optimistic lock and without retry. The migration adds both.

Part of the broader CNTRLPLANE-3532 migration. Depends on PR #8782 (merged).

Which issue(s) this PR fixes:

Fixes CNTRLPLANE-3532

Special notes for your reviewer:

  • This is a single-site migration in the HO. Route status patches will be added in a follow-up.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of cluster autoscaling status when Karpenter is disabled, ensuring stale node autoscaling state is cleared reliably.
    • Enhanced status updates so failures are detected and reported cleanly, improving operational visibility and ensuring status accurately reflects the current configuration.
  • Tests

    • Added coverage for clearing stale autoscaling status when Karpenter is disabled and verifying the updated state persists correctly.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jul 9, 2026
@openshift-ci-robot

openshift-ci-robot commented Jul 9, 2026

Copy link
Copy Markdown

@vsolanki12: This pull request references CNTRLPLANE-3532 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 story to target the "5.0.0" version, but no target version was set.

Details

In response to this:

What this PR does / why we need it:

Migrates the manual MergeFrom status patch in reconcileKarpenterOperator to use statuspatching.PatchStatus, adding optimistic locking and retry-on-conflict for the AutoNode status clearing path.

This was a Tier 2 site — it used MergeFrom without optimistic lock and without retry. The migration adds both.

Part of the broader CNTRLPLANE-3532 migration. Depends on PR #8782 (merged).

Which issue(s) this PR fixes:

Fixes CNTRLPLANE-3532

Special notes for your reviewer:

  • This is a single-site migration in the HO. Route status patches will be added in a follow-up.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

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.

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 9, 2026
@openshift-ci

openshift-ci Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 5915346d-a5a9-4516-8fb2-009c1879cdd2

📥 Commits

Reviewing files that changed from the base of the PR and between 488ab43 and a5212ca.

📒 Files selected for processing (2)
  • hypershift-operator/controllers/hostedcluster/karpenter.go
  • hypershift-operator/controllers/hostedcluster/karpenter_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • hypershift-operator/controllers/hostedcluster/karpenter_test.go
  • hypershift-operator/controllers/hostedcluster/karpenter.go

📝 Walkthrough

Walkthrough

When Karpenter is disabled, the hostedcluster reconciler clears stale HCP.Status.AutoNode through statuspatching.PatchStatus. The callback resets the status, and patch errors propagate. A test verifies that the cleared status persists after re-fetching the HostedControlPlane.

Possibly related PRs

Suggested reviewers: muraee

🚥 Pre-merge checks | ✅ 10 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Test Structure And Quality ⚠️ Warning The added test has five Gomega assertions without diagnostic messages; only the final equality assertion supplies one, violating the assertion-message requirement. Add meaningful, operation-specific messages to each Gomega assertion, including status update, fetch, stale-status, and PatchStatus failures.
✅ Passed checks (10 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the migration of the Karpenter status patch to the statuspatching helper.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed The PR adds only a static Go test function name; no Ginkgo title call contains dynamic data, and test-hcp/test-ns remain in the test body.
Topology-Aware Scheduling Compatibility ✅ Passed The committed diff only changes HCP AutoNode status patching and adds a status test; it adds no manifests or scheduling constraints such as affinity, selectors, tolerations, replicas, or PDBs.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The added test is a standard Go Test using a fake client, not a Ginkgo e2e test. It uses no IPv4 literals, network parsing, URLs, or external services.
No-Weak-Crypto ✅ Passed The diff adds only statuspatching-based status mutation and tests; changed files contain no weak crypto, custom crypto, or secret/token comparisons.
Container-Privileges ✅ Passed The commit changes only two Go files. It adds no YAML/JSON manifests and no privilege-related additions such as privileged, hostPID, hostNetwork, hostIPC, SYS_ADMIN, or allowPrivilegeEscalation.
No-Sensitive-Data-In-Logs ✅ Passed The diff adds no production or test logging. It only clears AutoNode status and calls the existing PatchStatus helper; no sensitive values are formatted or emitted.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@openshift-ci openshift-ci Bot added area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Jul 9, 2026
@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch from 541d030 to 82ccf32 Compare July 9, 2026 13:57
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 45.77%. Comparing base (559cd56) to head (a67a776).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...ft-operator/controllers/hostedcluster/karpenter.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8968   +/-   ##
=======================================
  Coverage   45.77%   45.77%           
=======================================
  Files         781      781           
  Lines       97864    97864           
=======================================
+ Hits        44794    44797    +3     
+ Misses      50003    50000    -3     
  Partials     3067     3067           
Files with missing lines Coverage Δ
...ft-operator/controllers/hostedcluster/karpenter.go 77.33% <50.00%> (+2.00%) ⬆️
Flag Coverage Δ
cmd-support 38.89% <ø> (ø)
cpo-hostedcontrolplane 48.03% <ø> (ø)
cpo-other 46.02% <ø> (ø)
hypershift-operator 57.01% <50.00%> (+0.01%) ⬆️
other 34.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vsolanki12
vsolanki12 marked this pull request as ready for review July 13, 2026 09:27
@openshift-ci openshift-ci Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 13, 2026
@openshift-ci
openshift-ci Bot requested review from jparrill and muraee July 13, 2026 09:28
@hypershift-jira-solve-ci

hypershift-jira-solve-ci Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

The analysis is confirmed. Here is the final report:

Test Failure Analysis Complete

Job Information

  • Prow Job: codecov/patch
  • Build ID: 86784934108 (GitHub check run)
  • PR: #8968CNTRLPLANE-3532: migrate HO karpenter status patch to statuspatching helper
  • Target File: hypershift-operator/controllers/hostedcluster/karpenter.go

Test Failure Analysis

Error

codecov/patch: 0.00% of diff hit (target 43.53%)
Patch coverage is 0% with 4 lines in your changes missing coverage.

Summary

The codecov/patch check failed because none of the 4 new/modified lines introduced by the PR are exercised by any unit test. The PR refactors reconcileKarpenterOperator in karpenter.go to replace a direct client.MergeFrom + Status().Patch() call with the statuspatching.PatchStatus() helper. The old code at those same lines was already uncovered on main, but Codecov treats rewritten lines as new diff and now flags them. No test exists for reconcileKarpenterOperator — only TestResolveKarpenterFinalizer is covered in karpenter_test.go. The codecov/project check passed (43.53%), so only the stricter patch-level gate failed.

Root Cause

The reconcileKarpenterOperator function has zero unit test coverage — neither on main nor in this PR. The existing test file karpenter_test.go only covers TestResolveKarpenterFinalizer, not reconcileKarpenterOperator.

On the main branch, lines 56–58 (the MergeFrom/Status().Patch() block) were already uncovered, tracked as existing misses in the project baseline (51,192 misses). Because they weren't part of any recent diff, they never triggered the patch coverage check.

This PR replaces those 3 uncovered lines with 4 new lines (the statuspatching.PatchStatus() call with its closure). Codecov treats all modified/added lines as "new diff" and requires them to be covered by tests. Since reconcileKarpenterOperator is never called in any unit test, all 4 diff lines show 0% coverage, failing the patch coverage check.

The specific uncovered lines (57–61 in the new file) are:

if err := statuspatching.PatchStatus(cpContext, cpContext.Client, cpContext.HCP, func() error {
    cpContext.HCP.Status.AutoNode = hyperv1.AutoNodeStatus{}
    return nil
}); err != nil {

This is a pre-existing coverage gap exposed by the refactor, not a new regression introduced by the PR.

Recommendations
  1. Add a unit test for reconcileKarpenterOperator in karpenter_test.go that covers the "karpenter disabled + stale AutoNode status" code path. The test should:

    • Create a fake ControlPlaneContext with a non-empty HCP.Status.AutoNode
    • Ensure karpenterutil.IsKarpenterEnabled() returns false
    • Call reconcileKarpenterOperator and verify AutoNode status is cleared via the statuspatching.PatchStatus() helper
  2. Alternatively, if the team considers this a trivial mechanical refactor not warranting new tests, a maintainer can override the codecov/patch check — it is typically advisory in the hypershift repo (codecov/project already passed at 43.53%). However, adding the test is preferred since it closes a pre-existing gap.

  3. Long-term: Consider adding broader test coverage for reconcileKarpenterOperator, since the function contains multiple untested branches (karpenter enabled/disabled, finalizer resolution, deployment reconciliation) — the file is at 74.66% overall but 0% on this specific reconciliation path.

Evidence
Evidence Detail
Codecov patch result 0.00% patch coverage — 4 lines in diff, 0 lines hit
Codecov project result 43.53% (−0.01%) — passed (project check is green)
File coverage delta karpenter.go: 74.66% → 74.66% (−0.51%)
Changed file hypershift-operator/controllers/hostedcluster/karpenter.go (+5 −3), lines 57–61
Diff content Replaced client.MergeFrom + Status().Patch() with statuspatching.PatchStatus() helper
Test file karpenter_test.go — contains only TestResolveKarpenterFinalizer, no test for reconcileKarpenterOperator
Old code coverage Lines 56–58 on main were already uncovered (part of 51,192 project misses)
Coverage diff Files: 771 (unchanged), Lines: 95,798 → 95,799 (+1), Misses: 51,192 → 51,193 (+1)
Codecov flag impacted hypershift-operator: 53.65% (−0.01%)
Base commit 1f2811f
Head commit 82ccf32

@jparrill

Copy link
Copy Markdown
Contributor

Dropped some comments. Thanks


The "This change includes unit tests" checkbox is checked, but the PR doesn't add any test code. reconcileKarpenterOperator doesn't have a unit test — neither before nor after this change. The statuspatching.PatchStatus helper itself is well-tested from #8782, so this isn't blocking, but the checkbox is misleading. Either uncheck it or consider adding a small test that verifies the AutoNode status is cleared through the helper. Something like:

{
    name: "When karpenter is disabled and AutoNode status is stale it should clear it",
    // setup HCP with non-empty AutoNode status, karpenter disabled
    // verify HCP.Status.AutoNode == AutoNodeStatus{} after reconcile
}

@@ -53,9 +54,10 @@ func (r *HostedClusterReconciler) reconcileKarpenterOperator(cpContext controlpl
// while it was running. Since the karpenter-operator only runs when enabled, it cannot
// clear this itself.
if cpContext.HCP.Status.AutoNode != (hyperv1.AutoNodeStatus{}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The pre-check cpContext.HCP.Status.AutoNode != (hyperv1.AutoNodeStatus{}) runs before PatchStatus, so it evaluates the potentially stale in-memory version. That's fine — if another controller cleared AutoNode between the check and the PatchStatus call, the helper's no-op detection (DeepEqual after re-fetch) catches it and skips the API call. Just confirming the race is handled correctly. 👍

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct — the pre-check is a cheap guard to skip the PatchStatus call entirely when there's nothing to clear. If another controller races and clears it between the check and the re-fetch inside PatchStatus, the DeepEqual no-op detection handles it gracefully.

Added a unit test (TestClearAutoNodeStatusViaPatchStatus) that verifies the AutoNode status is correctly cleared through the helper.


AI-assisted response via Claude Code

@vsolanki12

vsolanki12 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @jparrill! Added TestClearAutoNodeStatusViaPatchStatus to cover the AutoNode status clearing path through the PatchStatus helper. Also unchecking the unit test checkbox since the test covers the migration, not the broader reconcileKarpenterOperator flow.

@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch from 82ccf32 to fe313ad Compare July 22, 2026 12:47

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/hostedcluster/karpenter_test.go`:
- Line 464: Rename the test function TestClearAutoNodeStatusViaPatchStatus to
follow the required “When ... it should ...” naming format while preserving its
existing test behavior and coverage.
🪄 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: ca7e73bf-a3f4-4307-944e-7f0d60039b24

📥 Commits

Reviewing files that changed from the base of the PR and between 82ccf32 and fe313ad.

📒 Files selected for processing (2)
  • hypershift-operator/controllers/hostedcluster/karpenter.go
  • hypershift-operator/controllers/hostedcluster/karpenter_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • hypershift-operator/controllers/hostedcluster/karpenter.go

Comment thread hypershift-operator/controllers/hostedcluster/karpenter_test.go Outdated
@vsolanki12

Copy link
Copy Markdown
Contributor Author

/retest

@muraee

muraee commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 5, 2026
@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch from fe313ad to a9a7d0f Compare August 12, 2026 06:02
@vsolanki12

Copy link
Copy Markdown
Contributor Author

/test security

@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch from a9a7d0f to a5212ca Compare August 12, 2026 07:08
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@csrwng csrwng added the lgtm Indicates that a PR is ready to be merged. label Aug 12, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks-4-22
/test e2e-aws-4-22
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-azure-self-managed
/test e2e-v2-gke

@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch 2 times, most recently from 011d91c to e373a25 Compare August 13, 2026 02:21

@mehabhalodiya mehabhalodiya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 13, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks-4-22
/test e2e-aws-4-22
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-azure-self-managed
/test e2e-v2-gke

@vsolanki12

Copy link
Copy Markdown
Contributor Author

/retest

2 similar comments
@vsolanki12

Copy link
Copy Markdown
Contributor Author

/retest

@vsolanki12

Copy link
Copy Markdown
Contributor Author

/retest

@vsolanki12

Copy link
Copy Markdown
Contributor Author

/retest-required

@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch from e373a25 to 34a5853 Compare August 18, 2026 11:36
@openshift-ci openshift-ci Bot removed lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 18, 2026
@muraee

muraee commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci

openshift-ci Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@muraee: changing LGTM is restricted to collaborators

Details

In 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 kubernetes-sigs/prow repository.

@muraee

muraee commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci

openshift-ci Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

@muraee: changing LGTM is restricted to collaborators

Details

In response to this:

/lgtm

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 kubernetes-sigs/prow repository.

@mehabhalodiya

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Aug 18, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks-4-22
/test e2e-aws-4-22
/test e2e-aks
/test e2e-aws
/test e2e-aws-upgrade-hypershift-operator
/test e2e-kubevirt-aws-ovn-reduced
/test e2e-v2-aws
/test e2e-v2-azure-self-managed
/test e2e-v2-gke

@bryan-cox bryan-cox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Late pass — migration looks right, PatchStatus is the correct target here. Three nits, none blocking.

Commit subject carries a Jira ID. DEVELOPMENT.md:127: "Do NOT put Jira IDs in commit messages — they belong only in PR titles."

Other two inline.

}
}

func TestWhenKarpenterDisabledAndStaleAutoNodeStatusItShouldClearStatus(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TESTING.md:34 — test functions are named after the function under test, 1:1. This tests reconcileKarpenterOperator, so: TestReconcileKarpenterOperator.

Flagging that the earlier thread resolved this the wrong way: CodeRabbit cited the "When … it should …" rule, but that's TESTING.md:9, which governs table-case names (the name: field), not function names. The rename moved this away from the rule. @mehabhalodiya's TestReconcileKarpenterOperator_When... satisfied both.

Conforming shape is the scenario as a table case under TestReconcileKarpenterOperator:

name: "When karpenter is disabled and AutoNode status is stale, it should clear the status",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Renamed to TestReconcileKarpenterOperator with the scenario as a table case: "When karpenter is disabled and AutoNode status is stale, it should clear the status".

@@ -53,9 +54,10 @@ func (r *HostedClusterReconciler) reconcileKarpenterOperator(cpContext controlpl
// while it was running. Since the karpenter-operator only runs when enabled, it cannot
// clear this itself.
if cpContext.HCP.Status.AutoNode != (hyperv1.AutoNodeStatus{}) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Following up on @jparrill's thread rather than opening a new one — I think the resolution covers only one direction.

Agreed reasoning: cached non-empty → live empty → PatchStatus re-fetches, DeepEqual skips. Correct.

Not covered: cached empty → live non-empty. The guard reads cpContext.HCP, populated by createOrUpdate at hostedcluster_controller.go:1600, many API calls earlier. If the karpenter-operator wrote AutoNode in that window, the if is false, we never enter PatchStatus, the re-fetch never happens, and stale status survives. The optimistic lock can't help — we never reach it.

Self-heals next reconcile, so low severity. Either drop the guard (the helper's DeepEqual already makes the no-op path cost one Get) or comment that it's best-effort and correctness relies on requeue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Dropped the guard entirely — PatchStatus re-fetches and no-ops via DeepEqual when there's nothing to clear, so it wasn't saving real work, only introducing the staleness risk. Added a comment explaining why and a no-op test case.

…atching helper

Replace the manual MergeFrom status patch in reconcileKarpenterOperator
with statuspatching.PatchStatus, adding optimistic locking and
retry-on-conflict for the AutoNode status clearing path.

Signed-off-by: Vimal Solanki <vsolanki@redhat.com>
@vsolanki12
vsolanki12 force-pushed the vsolanki/cntrlplane-3532-ho-statuspatching branch from 34a5853 to a67a776 Compare August 19, 2026 04:48
@openshift-ci

openshift-ci Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 19, 2026
@vsolanki12

Copy link
Copy Markdown
Contributor Author

@bryan-cox Done — reworded commit subject to refactor(hostedcluster): migrate karpenter HO status patch to statuspatching helper, dropped the Jira ID per DEVELOPMENT.md:127.

@openshift-ci

openshift-ci Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mehabhalodiya, muraee, vsolanki12

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 19, 2026
@openshift-ci

openshift-ci Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

@vsolanki12: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aks 34a5853 link true /test e2e-aks
ci/prow/e2e-aws-4-22 34a5853 link true /test e2e-aws-4-22
ci/prow/e2e-v2-azure-self-managed 34a5853 link true /test e2e-v2-azure-self-managed
ci/prow/e2e-aws 34a5853 link true /test e2e-aws
ci/prow/e2e-kubevirt-aws-ovn-reduced 34a5853 link true /test e2e-kubevirt-aws-ovn-reduced
ci/prow/e2e-aks-4-22 34a5853 link true /test e2e-aks-4-22

Full PR test history. Your PR dashboard.

Details

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 kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants