@@ -30,6 +30,7 @@ import (
30
30
"k8s.io/apimachinery/pkg/labels"
31
31
"k8s.io/client-go/kubernetes/scheme"
32
32
ref "k8s.io/client-go/tools/reference"
33
+ "k8s.io/client-go/util/retry"
33
34
corev1helpers "k8s.io/component-helpers/scheduling/corev1"
34
35
klog "k8s.io/klog/v2"
35
36
@@ -930,19 +931,22 @@ func (ctrl *csiSnapshotCommonController) ensurePVCFinalizer(snapshot *crdv1.Volu
930
931
931
932
// removePVCFinalizer removes a Finalizer for VolumeSnapshot Source PVC.
932
933
func (ctrl * csiSnapshotCommonController ) removePVCFinalizer (pvc * v1.PersistentVolumeClaim ) error {
933
- // Get snapshot source which is a PVC
934
- // TODO(xyang): We get PVC from informer but it may be outdated
935
- // Should get it from API server directly before removing finalizer
936
- pvcClone := pvc .DeepCopy ()
937
- pvcClone .ObjectMeta .Finalizers = utils .RemoveString (pvcClone .ObjectMeta .Finalizers , utils .PVCFinalizer )
938
-
939
- _ , err := ctrl .client .CoreV1 ().PersistentVolumeClaims (pvcClone .Namespace ).Update (context .TODO (), pvcClone , metav1.UpdateOptions {})
940
- if err != nil {
941
- return newControllerUpdateError (pvcClone .Name , err .Error ())
942
- }
934
+ return retry .RetryOnConflict (retry .DefaultRetry , func () error {
935
+ // Get snapshot source which is a PVC
936
+ newPvc , err := ctrl .client .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Get (context .TODO (), pvc .Name , metav1.GetOptions {})
937
+ if err != nil {
938
+ return err
939
+ }
940
+ newPvc = newPvc .DeepCopy ()
941
+ newPvc .ObjectMeta .Finalizers = utils .RemoveString (newPvc .ObjectMeta .Finalizers , utils .PVCFinalizer )
942
+ _ , err = ctrl .client .CoreV1 ().PersistentVolumeClaims (newPvc .Namespace ).Update (context .TODO (), newPvc , metav1.UpdateOptions {})
943
+ if err != nil {
944
+ return newControllerUpdateError (newPvc .Name , err .Error ())
945
+ }
943
946
944
- klog .V (5 ).Infof ("Removed protection finalizer from persistent volume claim %s" , pvc .Name )
945
- return nil
947
+ klog .V (5 ).Infof ("Removed protection finalizer from persistent volume claim %s" , pvc .Name )
948
+ return nil
949
+ })
946
950
}
947
951
948
952
// isPVCBeingUsed checks if a PVC is being used as a source to create a snapshot.
0 commit comments