← Back to Pull requests

fix: tolerate missing PersistentVolume in driverFromVolume to prevent cluster sync paralysis #3159

Open
omerd2 opened this pull request with 90 lines diff across 2 files
View on GitHub
omerd2 omerd2 commented on Jul 20, 2026 13:55 UTC
Author

Fixes #3169

Description

Fixes an issue where driverFromVolume returns a raw NotFound error when querying a missing PersistentVolume (e.g., when a PV is deleted out-of-band while a PVC remains in Lost phase).

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 pinning karpenter_cluster_state_synced at 0 indefinitely — halting all provisioning, consolidation, and disruption operations.

This PR adds apierrors.IsNotFound(err) handling to driverFromVolume (pkg/scheduling/volumeusage.go:170), aligning it with the existing tolerant behavior used for missing PVCs in GetVolumes() (line 88-94). That existing code already has a comment explaining why tolerance is needed:

"If the PVC is not found it was manually deleted and its finalizer removed. We should ignore this volume when computing limits, otherwise Karpenter may never be able to update its cluster state."

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 to Lost phase)
2. Karpenter logged "tracking volume usage, PersistentVolume not found" every ~30s but continued operating (because hasSynced was already true)
3. 13 days later, the Karpenter controller pod was manually restarted
4. After restart, hasSynced reset to false, the full superset check ran, the affected node couldn't complete reconciliation, and karpenter_cluster_state_synced pinned at 0 permanently
5. All provisioning, consolidation, and disruption halted until the Lost PVC was manually deleted

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • How Has This Been Tested?

  • Added unit tests in pkg/scheduling/volumeusage_test.go covering:

  • - 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.
    ``

    Diff: 90 lines (+90 / -0) across 2 files Reviewer: semx Review duration: 191887m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.38) × (1 − Review Confidence (0.88)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.38 · 90 lines diff across 2 files
    0.38
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    87%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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.270
    Real PR Conversation Timeline
    7 items
    kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 20, 2026 13:55 UTC
    Bot

    [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:

  • OWNERS
  • 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"]} -->

    linux-foundation-easycla[bot] linux-foundation-easycla[bot] commented on Jul 20, 2026 13:55 UTC
    Bot

    <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>

    kubernetes-prow[bot] kubernetes-prow[bot] commented on Jul 20, 2026 13:55 UTC
    Bot

    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:

    jigisha620 jigisha620 commented on Jul 27, 2026 06:05 UTC
    Contributor

    /assign

    omerd2 omerd2 commented on Sep 01, 2026 07:39 UTC
    Author

    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.

    semx semx commented on Sep 18, 2026 07:56 UTC
    Reviewer

    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.

  • The other 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.

  • New spec fails on main (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.

    Reviewers
    Assignees
    omerd2 omerd2
    Labels
    risk: low confidence: 87.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 38.4% (MEDIUM) · Higher = larger blast radius
    38.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 87.7% · Lower = rushed or shallow review
    87.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%