@@ -1421,23 +1421,16 @@ func (ctrl *csiSnapshotCommonController) addSnapshotFinalizer(snapshot *crdv1.Vo
14211421	var  updatedSnapshot  * crdv1.VolumeSnapshot 
14221422	var  err  error 
14231423
1424- 	// Must perform an update if no finalizers exist 
1424+ 	var   patches  []utils. PatchOp 
14251425	if  len (snapshot .ObjectMeta .Finalizers ) ==  0  {
1426- 		snapshotClone  :=  snapshot .DeepCopy ()
1427- 		if  addSourceFinalizer  {
1428- 			snapshotClone .ObjectMeta .Finalizers  =  append (snapshotClone .ObjectMeta .Finalizers , utils .VolumeSnapshotAsSourceFinalizer )
1429- 		}
1430- 		if  addBoundFinalizer  {
1431- 			snapshotClone .ObjectMeta .Finalizers  =  append (snapshotClone .ObjectMeta .Finalizers , utils .VolumeSnapshotBoundFinalizer )
1432- 		}
1433- 		updatedSnapshot , err  =  ctrl .clientset .SnapshotV1 ().VolumeSnapshots (snapshotClone .Namespace ).Update (context .TODO (), snapshotClone , metav1.UpdateOptions {})
1434- 		if  err  !=  nil  {
1435- 			return  newControllerUpdateError (utils .SnapshotKey (snapshot ), err .Error ())
1436- 		}
1426+ 		// Replace finalizers with new array if there are no other finalizers 
1427+ 		patches  =  append (patches , utils.PatchOp {
1428+ 			Op :    "add" ,
1429+ 			Path :  "/metadata/finalizers" ,
1430+ 			Value : []string {utils .VolumeSnapshotContentFinalizer },
1431+ 		})
14371432	} else  {
14381433		// Otherwise, perform a patch 
1439- 		var  patches  []utils.PatchOp 
1440- 
14411434		if  addSourceFinalizer  {
14421435			patches  =  append (patches , utils.PatchOp {
14431436				Op :    "add" ,
@@ -1452,11 +1445,10 @@ func (ctrl *csiSnapshotCommonController) addSnapshotFinalizer(snapshot *crdv1.Vo
14521445				Value : utils .VolumeSnapshotBoundFinalizer ,
14531446			})
14541447		}
1455- 
1456- 		updatedSnapshot , err  =  utils .PatchVolumeSnapshot (snapshot , patches , ctrl .clientset )
1457- 		if  err  !=  nil  {
1458- 			return  newControllerUpdateError (utils .SnapshotKey (snapshot ), err .Error ())
1459- 		}
1448+ 	}
1449+ 	updatedSnapshot , err  =  utils .PatchVolumeSnapshot (snapshot , patches , ctrl .clientset )
1450+ 	if  err  !=  nil  {
1451+ 		return  newControllerUpdateError (utils .SnapshotKey (snapshot ), err .Error ())
14601452	}
14611453
14621454	_ , err  =  ctrl .storeSnapshotUpdate (updatedSnapshot )
0 commit comments