AUTOSCALE-944: feat: migrate HostedControlPlane lifecycle controller from HyperShift #52
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #52"
general
weight: 0.35
LucasAndFlores
Related PR: https://github.com/openshift/hypershift/pull/9930
E2E test from the related PR passed, see this comment.
This PR migrates the karpenter_controller.go from the hypershift repo into the standalone karpenter operator.
I split the work in 3 commits:
1. migration with minimal changes (AI comparison against hypershift implementation below)
2. refactor to split controllers and align them with how we setup our controllers here
3. a fix for a very rare bug AI identified
- Reproduction requires slightly out of sync events for NodeClaim and the Node, as the Node seems to receive the NodePool label we use for filtering slightly after the NodeClaim was updated.
- I couldn't reproduce it but the code path seems to be possible, the fix is quite small, just watch Update events that add the label we expect
Summary
Port the remaining HostedControlPlane lifecycle logic from HyperShift's Karpenter controller: the Karpenter finalizer, NodePool and NodeClaim cleanup when the HostedControlPlane or CAPI Cluster is deleted, and the AutoNode node, NodeClaim and vCPU counts in HostedControlPlane status. The finalizer name and status field manager (as we use SSA for this) match HyperShift so clusters can switch from the HyperShift adapter.
The CAPI Cluster is read as metadata only, and the status is written with server-side apply on an unstructured object, avoiding dependencies on cluster-api and the HyperShift client module.
The Taint ConfigMap reconciliation isn't migrated as opposed to the requirement from AUTOSCALE-944, it rather belongs to the ignition handling IMO. See the related PR above how it was integrated.
Comparison against original karpenter_controller.go
AI generated but I read, verified and pruned it.
Scope and ownership
HyperShift’s
karpenter_controller.gocombines HCP lifecycle work with Karpenter deployment and resource reconciliation. This PR extracts HCP lifecycle and AutoNode status logic into separate controllers:| Responsibility | This branch |
|---|---|
| Add/remove HCP finalizer; detect HCP or CAPI Cluster deletion; clean up NodePools and NodeClaims |
pkg/controllers/hcp/deletion/controller.go|| Report Node, NodeClaim, and vCPU counts in HCP status |
pkg/controllers/hcp/autonodestatus/controller.go|| Read CAPI Cluster deletion metadata without a full Cluster API dependency |
pkg/hypershift/capicluster.go|| Register lifecycle controllers in management-cluster mode when a hosted-cluster client exists |
pkg/controllers/controllers.go|The PR does not move deployment, CRD, or default NodeClass responsibilities into these lifecycle controllers. Existing controllers remain their owners:
pkg/controllers/karpenter,pkg/controllers/crd, andpkg/controllers/nodeclass/default.Taint ConfigMap reconciliation is intentionally out of scope for this ticket.
Behavior preserved
hypershift.openshift.io/karpenter-finalizer.Refactor differences to review
autonodestatus;hcp/deletionwatches HCP and CAPI Cluster. If cleanup finds NodeClaims remaining, it requeues after 15 seconds. Their removal may therefore be noticed at next poll—roughly one interval later under normal scheduling—unless another HCP/CAPI event triggers reconciliation first.- 🚨🚨🚨 this is IMO OK as we also didn't watch the nodepool deletions, we just watched the nodeclaim deletions before as the same controller also handled autonode status updates.
Status().Apply, skips writes when status already matches, and keeps field managerkarpenter-operatorwith forced ownership.mainenqueues on Node create/delete. This branch also enqueues when the NodePool label is added or removed, preventing stale counts when a Node receives that label after creation. Label-value-only changes do not enqueue.When reconciliation returns an error, controller-runtime ignores returned
Resultand uses its rate limiter. So the oldRequeueAftervalues returned alongside errors did not create a retry-timing difference.