From 58f71bef8c7d0ab8e219025b1ca50bab14410719 Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Mon, 24 Sep 2018 12:40:01 -0700 Subject: [PATCH] Update snapshot class in the content spec This PR sets the snapshot class and UID in the volume snapshot content spec if one of them is not set. This is to make sure that snapshot class is set in the content in the case of static binding. --- pkg/controller/snapshot_controller.go | 31 ++++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pkg/controller/snapshot_controller.go b/pkg/controller/snapshot_controller.go index 1efb4eb8..ef4fe358 100644 --- a/pkg/controller/snapshot_controller.go +++ b/pkg/controller/snapshot_controller.go @@ -401,21 +401,22 @@ func (ctrl *csiSnapshotController) checkandBindSnapshotContent(snapshot *crdv1.V return fmt.Errorf("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match", snapshot.Name, content.Name) } else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotRef.UID != snapshot.UID { return fmt.Errorf("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match", snapshot.Name, content.Name) - } else if content.Spec.VolumeSnapshotRef.UID == "" { - contentClone := content.DeepCopy() - contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID - className := *(snapshot.Spec.VolumeSnapshotClassName) - contentClone.Spec.VolumeSnapshotClassName = &className - newContent, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Update(contentClone) - if err != nil { - glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", newContent.Name, err) - return err - } - _, err = ctrl.storeContentUpdate(newContent) - if err != nil { - glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v", newContent.Name, err) - return err - } + } else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotClassName != nil { + return nil + } + contentClone := content.DeepCopy() + contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID + className := *(snapshot.Spec.VolumeSnapshotClassName) + contentClone.Spec.VolumeSnapshotClassName = &className + newContent, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Update(contentClone) + if err != nil { + glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", newContent.Name, err) + return err + } + _, err = ctrl.storeContentUpdate(newContent) + if err != nil { + glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v", newContent.Name, err) + return err } return nil }