fix: tolerate missing PersistentVolume in driverFromVolume to prevent cluster sync paralysis #3159
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: <a href="https://github.com/kubernetes-sigs/karpenter/pull/3159#" title="Author self-approved">omerd2</a>
Once this PR has been reviewed and has the lgtm label, please assign jonathan-innis for approval. For more information see the Code Review Process.
The full list of commands accepted by this bot can be found here.
<details open>
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
</details>
<!-- META={"approvers":["jonathan-innis"]} -->
<a href="https://easycla.lfx.linuxfoundation.org/#/?version=2"><img src="https://s3.amazonaws.com/cla-project-logo-prod/cla-signed.svg?v=2" alt="CLA Signed" align="left" height="28" width="328" ></a><br >The committers listed above are authorized under a signed CLA.<ul><li>:white_check_mark: login: omerd2 / name: omerd2 (2516c173cc58d5495c687786483790e4d9f5a2b9)</li></ul>
Welcome @omerd2! <br><br>It looks like this is your first PR to <a href='https://github.com/kubernetes-sigs/karpenter'>kubernetes-sigs/karpenter</a> 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval. <br><br>You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation. <br><br>You can also check if kubernetes-sigs/karpenter has its own contribution guidelines. <br><br>You may want to refer to our testing guide if you run into trouble with your tests not passing. <br><br>If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs! <br><br>Thank you, and welcome to Kubernetes. :smiley:
/assign
Rebased onto latest main (11c782f) — the conflict is resolved and CI is green.
The conflict was an add/add on pkg/scheduling/volumeusage_test.go: #3202 added a file of the same name after this PR was opened. I merged both test sets into one file — the fallback-limit spec from #3202 and the three GetVolumes specs here — and switched a local strPtr helper to lo.ToPtr to match the rest of the repo. The fix itself in volumeusage.go is unchanged (4 lines) and merged cleanly.
@jigisha620 you reproduced this in #3169 and confirmed karpenter_cluster_state_synced pins at 0 with all operations halted. This is ready for review whenever you have a chance. The issue is also still labeled needs-priority if you're able to set one.
Verified the chain on main and the scope of the change.
driverFromVolume returns the raw NotFound (volumeusage.go:176-180); ResolveDriver (:126) and GetVolumes (:107) propagate it; StateNode.updateForPod wraps it as "tracking volume usage" (statenode.go:466); newStateFromNode returns nil, err (cluster.go:770-775), so the node is never inserted and the first-sync superset check in Synced() cannot pass. Matches the report.ResolveDriver caller is unaffected: ValidatePersistentVolumeClaims rejects ClaimLost (volumetopology.go:243) and a missing PV via validateVolume (:247, :294-297) before reaching ResolveDriver (:280). So this only changes volume-count tracking, and a volume whose PV is gone cannot be attached anyway.persistentvolumes "test-pv" not found) and passes here; pkg/scheduling and pkg/controllers/state are green with -race.Two nits:
1. Log key: the file uses Kind keys with klog helpers (klog.KObj(pvc), klog.KRef("", storageClassName) at :143, :154), and AGENTS.md asks for the same. "PersistentVolume", volumeName should be "PersistentVolume", klog.KRef("", volumeName).
2. The PVC-not-found sibling at :98 logs at Error while this logs at V(1) like the StorageClass path at :154. Either is defensible; a sentence in the description saying which sibling you followed and why would pre-empt the question.
semx
omerd2
Fixes #3169
Description
Fixes an issue where
driverFromVolumereturns a rawNotFounderror when querying a missingPersistentVolume(e.g., when a PV is deleted out-of-band while a PVC remains inLostphase).Without this fix, a missing PV causes node state reconciliation to fail repeatedly. Upon a Karpenter controller restart, nodes failing reconciliation are excluded from the internal cluster map, preventing
Cluster.Synced()from succeeding and pinningkarpenter_cluster_state_syncedat0indefinitely — halting all provisioning, consolidation, and disruption operations.This PR adds
apierrors.IsNotFound(err)handling todriverFromVolume(pkg/scheduling/volumeusage.go:170), aligning it with the existing tolerant behavior used for missing PVCs inGetVolumes()(line 88-94). That existing code already has a comment explaining why tolerance is needed:The same logic applies to missing PVs — a deleted PV should not permanently block cluster state synchronization.
Real-world incident
This exact scenario caused a 22-hour outage in a production-grade EKS cluster:
1. An SRE deleted a PV while its PVC was still
Bound(PVC went toLostphase)2. Karpenter logged
"tracking volume usage, PersistentVolume not found"every ~30s but continued operating (becausehasSyncedwas alreadytrue)3. 13 days later, the Karpenter controller pod was manually restarted
4. After restart,
hasSyncedreset tofalse, the full superset check ran, the affected node couldn't complete reconciliation, andkarpenter_cluster_state_syncedpinned at0permanently5. All provisioning, consolidation, and disruption halted until the Lost PVC was manually deleted
Type of Change
How Has This Been Tested?
pkg/scheduling/volumeusage_test.gocovering:- Pod → PVC → missing PV scenario (should return no error, empty volumes)
- Pod → PVC → existing PV scenario (should return the CSI driver correctly)
- Pod → missing PVC scenario (existing tolerance, regression test)
Does this PR introduce a user-facing change?
``
release-note
``Fixed an issue where a missing PersistentVolume (e.g., manually deleted while PVC was Bound) could permanently prevent Karpenter cluster state from syncing after a controller restart, halting all provisioning operations.