Skip to content

[snapshot-controller] Retry PVC finalizer removal on conflict #1133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Fricounet
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

The previous removePVCFinalizer function was using the PVC stored in the informer which, in cases where the PVC had been modified since, lead to conflict errors when trying to remove the PVC finalizer through an update.
Example error:

E0807 13:09:20.573657       1 snapshot_controller.go:183] error check and remove PVC finalizer for snapshot [snapshot]: snapshot controller failed to update pvc-sts-0 on API server: Operation cannot be fulfilled on persistentvolumeclaims "pvc-sts-0": the object has been modified; please apply your changes to the latest version and try again

Unfortunately, the error was not retried so the PVC ends up stuck.

Now the removePVCFinalizer function uses the RetryOnConflict helper to make sure the update goes through.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

Fixes a race condition where the PVC finalizer could end up not being removed by the snapshot-controller if the update had a conflict.

The previous `removePVCFinalizer` function was using the PVC stored in the informer which, in cases where the PVC had been modified since, lead to conflict errors when trying to remove the PVC finalizer through an update. Now the `removePVCFinalizer` function uses the `RetryOnConflict` helper to make sure the update goes through.
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 7, 2024
@k8s-ci-robot
Copy link
Contributor

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

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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 7, 2024
@carlory
Copy link
Member

carlory commented Aug 8, 2024

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 8, 2024
}
newPvc = newPvc.DeepCopy()
newPvc.ObjectMeta.Finalizers = utils.RemoveString(newPvc.ObjectMeta.Finalizers, utils.PVCFinalizer)
_, err = ctrl.client.CoreV1().PersistentVolumeClaims(newPvc.Namespace).Update(context.TODO(), newPvc, metav1.UpdateOptions{})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a "patch" instead of an "update" can reduce the conflicts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree that a using a "patch" would get rid of all the conflicts however since the finalizers are stored in a list, using a patch seems dangerous to me because if the finalizer list changes between the get and update calls (because another controller removed its finalizer for instance), it means that we would end up removing the wrong finalizer (since we need the index to remove an element from a list using a patch).

Is there something I'm missing that could let us use a patch instead without the drawback above?

@xing-yang
Copy link
Collaborator

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 28, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Fricounet, xing-yang

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

The pull request process is described here

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 28, 2024
@k8s-ci-robot k8s-ci-robot merged commit 00123b8 into kubernetes-csi:master Aug 28, 2024
8 checks passed
@Fricounet Fricounet deleted the fricounet/retry-finalizer-removal branch September 2, 2024 08:27
newPvc.ObjectMeta.Finalizers = utils.RemoveString(newPvc.ObjectMeta.Finalizers, utils.PVCFinalizer)
_, err = ctrl.client.CoreV1().PersistentVolumeClaims(newPvc.Namespace).Update(context.TODO(), newPvc, metav1.UpdateOptions{})
if err != nil {
return newControllerUpdateError(newPvc.Name, err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

folks, I suspect generating a new error here (newControllerUpdateError) results in IsConflict never evaluating to true, and thus the original problem still existing. I hit this on an environment with 8.2.0 which contains this commit.

I can open a PR to tackle

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @akalenyu sorry about this! I actually did notice it a while back and made a PR in our fork to make sure this fixed the behavior for good (which it did) but I forgot to upstream it :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that 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.

5 participants