@@ -987,15 +987,37 @@ func (ctrl *csiSnapshotCommonController) checkandBindSnapshotContent(snapshot *c
987987 } else if content .Spec .VolumeSnapshotRef .UID != "" && content .Spec .VolumeSnapshotClassName != nil {
988988 return content , nil
989989 }
990- contentClone := content .DeepCopy ()
991- contentClone .Spec .VolumeSnapshotRef .UID = snapshot .UID
990+ // contentClone := content.DeepCopy()
991+ // contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID
992+ // if snapshot.Spec.VolumeSnapshotClassName != nil {
993+ // className := *(snapshot.Spec.VolumeSnapshotClassName)
994+ // contentClone.Spec.VolumeSnapshotClassName = &className
995+ // }
996+ // newContent, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Update(context.TODO(), contentClone, metav1.UpdateOptions{})
997+ // if err != nil {
998+ // klog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", contentClone.Name, err)
999+ // return content, err
1000+ // }
1001+
1002+ patches := []utils.PatchOp {
1003+ {
1004+ Op : "replace" ,
1005+ Path : "/spec/volumeSnapshotRef/uid" ,
1006+ Value : string (snapshot .UID ),
1007+ },
1008+ }
9921009 if snapshot .Spec .VolumeSnapshotClassName != nil {
9931010 className := * (snapshot .Spec .VolumeSnapshotClassName )
994- contentClone .Spec .VolumeSnapshotClassName = & className
1011+ patches = append (patches , utils.PatchOp {
1012+ Op : "replace" ,
1013+ Path : "/spec/volumeSnapshotClassName" ,
1014+ Value : className ,
1015+ })
9951016 }
996- newContent , err := ctrl .clientset .SnapshotV1 ().VolumeSnapshotContents ().Update (context .TODO (), contentClone , metav1.UpdateOptions {})
1017+
1018+ newContent , err := utils .PatchVolumeSnapshotContent (content , patches , ctrl .clientset )
9971019 if err != nil {
998- klog .V (4 ).Infof ("updating VolumeSnapshotContent[%s] error status failed %v" , contentClone .Name , err )
1020+ klog .V (4 ).Infof ("updating VolumeSnapshotContent[%s] error status failed %v" , content .Name , err )
9991021 return content , err
10001022 }
10011023
0 commit comments