Retry VolumeSnapshot API discovery before starting the snapshot finalizer sweep #1609
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:
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>
[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:
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"]} -->
/ok-to-test
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.
<!-- 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>
</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:
Run.| 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>
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
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.
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?
Yes, that would work too.
@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.
sebpalmerio
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.