From 2039ad91014a69257bbf978c370cea6d20b99f19 Mon Sep 17 00:00:00 2001 From: Grant Griffiths Date: Fri, 24 Sep 2021 11:11:15 -0700 Subject: [PATCH] checkandBindSnapshotContent with patch tested Signed-off-by: Grant Griffiths --- pkg/common-controller/snapshot_controller.go | 32 +++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pkg/common-controller/snapshot_controller.go b/pkg/common-controller/snapshot_controller.go index de25512b..ee7d6a3d 100644 --- a/pkg/common-controller/snapshot_controller.go +++ b/pkg/common-controller/snapshot_controller.go @@ -987,15 +987,37 @@ func (ctrl *csiSnapshotCommonController) checkandBindSnapshotContent(snapshot *c } else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotClassName != nil { return content, nil } - contentClone := content.DeepCopy() - contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID + // contentClone := content.DeepCopy() + // contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID + // if snapshot.Spec.VolumeSnapshotClassName != nil { + // className := *(snapshot.Spec.VolumeSnapshotClassName) + // contentClone.Spec.VolumeSnapshotClassName = &className + // } + // newContent, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Update(context.TODO(), contentClone, metav1.UpdateOptions{}) + // if err != nil { + // klog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", contentClone.Name, err) + // return content, err + // } + + patches := []utils.PatchOp{ + { + Op: "replace", + Path: "/spec/volumeSnapshotRef/uid", + Value: string(snapshot.UID), + }, + } if snapshot.Spec.VolumeSnapshotClassName != nil { className := *(snapshot.Spec.VolumeSnapshotClassName) - contentClone.Spec.VolumeSnapshotClassName = &className + patches = append(patches, utils.PatchOp{ + Op: "replace", + Path: "/spec/volumeSnapshotClassName", + Value: className, + }) } - newContent, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Update(context.TODO(), contentClone, metav1.UpdateOptions{}) + + newContent, err := utils.PatchVolumeSnapshotContent(content, patches, ctrl.clientset) if err != nil { - klog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", contentClone.Name, err) + klog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", content.Name, err) return content, err }