Skip to content

chore: add retry logic to finalizer operations to prevent update conflicts#1374

Open
rafatio wants to merge 1 commit intokubernetes-csi:masterfrom
rafatio:master
Open

chore: add retry logic to finalizer operations to prevent update conflicts#1374
rafatio wants to merge 1 commit intokubernetes-csi:masterfrom
rafatio:master

Conversation

@rafatio
Copy link

@rafatio rafatio commented Feb 3, 2026

What type of PR is this?
/kind bug

What this PR does / why we need it:
This PR adds retry logic to finalizer operations in the snapshot controller to handle concurrent resource updates gracefully and prevent "object has been modified" errors.

In environments with high concurrency the snapshot controller frequently encounters update conflicts when adding finalizers to VolumeSnapshots and PersistentVolumeClaims. This results in warning events during snapshot creation:

Warning SnapshotFinalizerError VolumeSnapshot/snapshot-example-pvc Failed to check and update snapshot: snapshot controller failed to update namespace/snapshot-example-pvc on API server: Operation cannot be fulfilled on volumesnapshots.snapshot.storage.k8s.io "snapshot-example-pvc": the object has been modified; please apply your changes to the latest version and try again

Warning SnapshotContentCreationFailed VolumeSnapshot/snapshot-example-pvc Failed to create snapshot content with error snapshot controller failed to update example-pvc on API server: Operation cannot be fulfilled on persistentvolumeclaims "example-pvc": the object has been modified; please apply your changes to the latest version and try again

While snapshots eventually succeed after retries at the reconciliation loop level, these errors cause unnecessary event noise and delays.

Solution:

  • Wrap finalizer add operations in retry.RetryOnConflict to automatically retry on update conflicts
  • Refetch resources from the API server on each retry attempt to ensure updates are based on the latest resource version
  • Add checks to detect if finalizers already exist before attempting to add them
  • This aligns with Kubernetes best practices for handling concurrent updates

Which issue(s) this PR fixes:

Does this PR introduce a user-facing change?:

Fixed warning events during VolumeSnapshot creation caused by concurrent updates when adding finalizers to PersistentVolumeClaims and VolumeSnapshots.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Feb 3, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rafatio
Once this PR has been reviewed and has the lgtm label, please assign msau42 for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details 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

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 3, 2026
@k8s-ci-robot
Copy link
Contributor

Welcome @rafatio!

It looks like this is your first PR to kubernetes-csi/external-snapshotter 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

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.

You can also check if kubernetes-csi/external-snapshotter has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

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!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @rafatio. 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.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants