← Back to Pull requests

Retry VolumeSnapshot API discovery before starting the snapshot finalizer sweep #1609

Open
sebpalmerio opened this pull request with 152 lines diff across 3 files
View on GitHub
sebpalmerio sebpalmerio commented on Nov 03, 2026 21:41 UTC
Author

What type of PR is this?
/kind bug

What this PR does / why we need it:
The orphaned snapshot finalizer sweep (#1519) only starts if a single discovery call at startup succeeds. A transient error there (429, 5xx, timeout) silently turns the sweep off until the provisioner restarts. We hit this on EKS, where an orphaned finalizer blocked a namespace from being deleted for close to four days.

This PR moves the check into the controller's Run, which starts after the leader lease is acquired. It retries errors with backoff for about 17 minutes, then gives up with an error log. A cluster that does not serve the snapshot API disables the sweep with an info log, as before but no longer silently.

Which issue(s) this PR fixes:
N/A

Special notes for your reviewer:
Tested in kind and on EKS 1.36 with a proxy returning 503 for snapshot discovery at startup: v6.4.0 never started the sweep, and this change started it and removed the orphaned finalizer within one sweep interval.

Does this PR introduce a user-facing change?:
``release-note
Orphaned snapshot source-protection finalizers are now cleaned up even if the VolumeSnapshot API was temporarily unavailable when the provisioner started. If the sweep is disabled, the provisioner logs why.
``

Diff: 152 lines (+138 / -14) across 3 files Reviewer: sebpalmerio Review duration: 38457m
All Vouch review confidence checks passed
Residual risk 0.09 = Change Risk (0.55) × (1 − Review Confidence (0.85)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.55 · 152 lines diff across 3 files
0.55
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.93 · 5 substantive comment(s)
0.93
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
84%
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.301
Self Review self_review
0.140
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
12 items
kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 03, 2026 21:41 UTC
Bot

Welcome @sebpalmerio! <br><br>It looks like this is your first PR to <a href='https://github.com/kubernetes-csi/external-provisioner'>kubernetes-csi/external-provisioner</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-csi/external-provisioner 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:

kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 03, 2026 21:41 UTC
Bot

Hi @sebpalmerio. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

<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.
</details>

kubernetes-prow[bot] kubernetes-prow[bot] commented on Nov 03, 2026 21:43 UTC
Bot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: <a href="https://github.com/kubernetes-csi/external-provisioner/pull/1609#" title="Author self-approved">sebpalmerio</a>
Once this PR has been reviewed and has the lgtm label, please assign saad-ali 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":["saad-ali"]} -->

    xing-yang xing-yang commented on Nov 04, 2026 04:15 UTC
    Contributor

    /ok-to-test

    Copilot Copilot commented on code on Nov 04, 2026 04:18 UTC
    Code Review
    pkg/controller/snapshot_finalizer_controller.go:1
    @@ -74,17 +81,55 @@ func NewSnapshotFinalizerController(
     
     	return &SnapshotFinalizerController{
     		snapshotClient:   snapshotClient,
    +		discoveryClient:  discoveryClient,
     		snapshotInformer: snapshotInformer,
     		claimLister:      claimLister,
     		resyncInterval:   sweepInterval,
    +		// 11 attempts over about 17 minutes before giving up.
    +		apiCheckBackoff: wait.Backoff{
    +			Duration: time.Second,
    +			Factor:   2,
    +			Jitter:   0.1,
    +			Steps:    11,
    +		},
     	}
     }
     
    +// waitForSnapshotAPI reports whether the VolumeSnapshot v1 API is served,
    +// retrying discovery errors with backoff. It returns false when the API is not
    +// served, the retries are exhausted, or ctx is cancelled.
    +func (c *SnapshotFinalizerController) waitForSnapshotAPI(ctx context.Context) bool {
    +	var available bool
    +	var lastErr error
    +	err := wait.ExponentialBackoffWithContext(ctx, c.apiCheckBackoff, func(ctx context.Context) (bool, error) {
    +		available, lastErr = features.IsVolumeSnapshotV1Available(c.discoveryClient)

    IsVolumeSnapshotV1Available uses context.TODO() for discovery, and the shared HTTP client can have no timeout, so a stalled request can prevent both retries and cancellation. With ReleaseLeaderElectionOnExit enabled, this also blocks the shutdown wait group and graceful leader-lease release. Pass the controller context through to the actual discovery request, bound each attempt with a timeout, and test cancellation while a request is in flight.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 04, 2026 04:18 UTC
    Reviewer

    <!-- ccr-overview-v2 -->

    🟡 Changes recommended

    Discovery requests lack cancellation and may have no timeout, so a stalled request can block retries, controller shutdown, and graceful leader-lease release.

    <details open>
    <summary><strong>1 open issue</strong></summary>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Discovery request ignores cancellation and can block graceful shutdown · New

  • </details>

    <details>
    <summary><strong>What changed in this PR</strong></summary>

    This PR makes the orphaned snapshot finalizer sweep resilient to transient discovery errors by checking API availability when the controller runs, rather than once during startup.

    Changes:

  • Retry VolumeSnapshot API discovery with exponential backoff and log why the sweep is disabled.

  • Pass the discovery client into the controller and defer availability checks until Run.

  • Add tests for discovery success, missing APIs, retry recovery, and retry exhaustion.
  • | File | Description |
    | ---- | ----------- |
    | pkg/​controller/​snapshot_finalizer_controller.go | Adds discovery retries before starting the sweep. |
    | pkg/​controller/​snapshot_finalizer_controller_test.go | Tests discovery outcomes and early exit when the API is absent. |
    | cmd/​csi-provisioner/​csi-provisioner.go | Replaces the startup discovery check with discovery-client injection. |
    </details>

    <sub>Review effort: Balanced</sub>

    sebpalmerio sebpalmerio commented on code on Nov 04, 2026 17:20 UTC
    Code Review
    pkg/controller/snapshot_finalizer_controller.go:1
    @@ -74,17 +81,55 @@ func NewSnapshotFinalizerController(
     
     	return &SnapshotFinalizerController{
     		snapshotClient:   snapshotClient,
    +		discoveryClient:  discoveryClient,
     		snapshotInformer: snapshotInformer,
     		claimLister:      claimLister,
     		resyncInterval:   sweepInterval,
    +		// 11 attempts over about 17 minutes before giving up.
    +		apiCheckBackoff: wait.Backoff{
    +			Duration: time.Second,
    +			Factor:   2,
    +			Jitter:   0.1,
    +			Steps:    11,
    +		},
     	}
     }
     
    +// waitForSnapshotAPI reports whether the VolumeSnapshot v1 API is served,
    +// retrying discovery errors with backoff. It returns false when the API is not
    +// served, the retries are exhausted, or ctx is cancelled.
    +func (c *SnapshotFinalizerController) waitForSnapshotAPI(ctx context.Context) bool {
    +	var available bool
    +	var lastErr error
    +	err := wait.ExponentialBackoffWithContext(ctx, c.apiCheckBackoff, func(ctx context.Context) (bool, error) {
    +		available, lastErr = features.IsVolumeSnapshotV1Available(c.discoveryClient)

    nice try copilot, but that's in client-go and is currently in the main too :P

    a per-request discovery timeout might be worth an issue or separate PR though

    jsafrane jsafrane commented on code on Nov 18, 2026 15:08 UTC
    Code Review
    cmd/csi-provisioner/csi-provisioner.go:1
    @@ -611,14 +611,13 @@ func main() {
     
     	var csiSnapshotFinalizerController *ctrl.SnapshotFinalizerController
     	if *snapshotOrphanSweepInterval > 0 {
    -		if volumeSnapshotAvailable, err := features.IsVolumeSnapshotV1Available(clientset.Discovery()); err == nil && volumeSnapshotAvailable {
    -			csiSnapshotFinalizerController = ctrl.NewSnapshotFinalizerController(
    -				snapClient,
    -				claimLister,
    -				controllerCapabilities,
    -				*snapshotOrphanSweepInterval,
    -			)
    -		}
    +		csiSnapshotFinalizerController = ctrl.NewSnapshotFinalizerController(

    We have the same issue with IsVolumeAttributesClassV1Enabled.
    It does not start a controller, but it has similar consequences - an external-provisioner makes a wrong decision if it can't reach the API server at startup.

    I think having a loop inside IsVolumeSnapshotV1Available / IsVolumeAttributesClassV1Enabled would help. If the API server is there, it will return quickly. If it's missing, right now the factory.WaitForCacheSync is slow (waits for the API server). With a loop inside IsXYZV1Enabled, the slowness (wait for the API server) just moves there.

    sebpalmerio sebpalmerio commented on code on Nov 18, 2026 16:50 UTC
    Code Review
    cmd/csi-provisioner/csi-provisioner.go:1
    @@ -611,14 +611,13 @@ func main() {
     
     	var csiSnapshotFinalizerController *ctrl.SnapshotFinalizerController
     	if *snapshotOrphanSweepInterval > 0 {
    -		if volumeSnapshotAvailable, err := features.IsVolumeSnapshotV1Available(clientset.Discovery()); err == nil && volumeSnapshotAvailable {
    -			csiSnapshotFinalizerController = ctrl.NewSnapshotFinalizerController(
    -				snapClient,
    -				claimLister,
    -				controllerCapabilities,
    -				*snapshotOrphanSweepInterval,
    -			)
    -		}
    +		csiSnapshotFinalizerController = ctrl.NewSnapshotFinalizerController(

    true, good point. but wouldn't a loop at startup get the pod killed by the liveness probe since the healthz endpoint isn't up yet?

    what if both checks used a shared retry helper but ran after leader election instead?

    jsafrane jsafrane commented on code on Nov 19, 2026 09:34 UTC
    Code Review
    cmd/csi-provisioner/csi-provisioner.go:1
    @@ -611,14 +611,13 @@ func main() {
     
     	var csiSnapshotFinalizerController *ctrl.SnapshotFinalizerController
     	if *snapshotOrphanSweepInterval > 0 {
    -		if volumeSnapshotAvailable, err := features.IsVolumeSnapshotV1Available(clientset.Discovery()); err == nil && volumeSnapshotAvailable {
    -			csiSnapshotFinalizerController = ctrl.NewSnapshotFinalizerController(
    -				snapClient,
    -				claimLister,
    -				controllerCapabilities,
    -				*snapshotOrphanSweepInterval,
    -			)
    -		}
    +		csiSnapshotFinalizerController = ctrl.NewSnapshotFinalizerController(

    Yes, that would work too.

    imusmanmalik imusmanmalik commented on Nov 27, 2026 11:39 UTC
    Contributor

    @sebpalmerio this leaves one case open, csi-provisioner starting before the VolumeSnapshot CRDs are installed. Discovery then works but reports the API as not served, and the sweep stays off until a restart (#1627). I opened a PR on top of your branch that keeps checking every sweep interval instead of returning. Happy to fold it into this PR instead if you prefer.

    Reviewers
    Assignees
    sebpalmerio sebpalmerio
    Labels
    risk: low confidence: 84.5% 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: 55% (MEDIUM) · Higher = larger blast radius
    55%
    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: 84.5% · Lower = rushed or shallow review
    84.5%
    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: 8.5% · Safe to merge
    8.5%