checkandBindSnapshotContent with patch tested

Signed-off-by: Grant Griffiths <ggriffiths@purestorage.com>
This commit is contained in:
Grant Griffiths
2021-09-24 11:11:15 -07:00
parent 36b6b879ba
commit 2039ad9101

View File

@@ -987,15 +987,37 @@ func (ctrl *csiSnapshotCommonController) checkandBindSnapshotContent(snapshot *c
} else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotClassName != nil { } else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotClassName != nil {
return content, nil return content, nil
} }
contentClone := content.DeepCopy() // contentClone := content.DeepCopy()
contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID // 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 { if snapshot.Spec.VolumeSnapshotClassName != nil {
className := *(snapshot.Spec.VolumeSnapshotClassName) 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 { 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 return content, err
} }