Skip to content

Commit 4fa90a4

Browse files
authored
Merge pull request #33 from xing-yang/update_snapshotclass
Update snapshot class in the content spec
2 parents 6327ae5 + 58f71be commit 4fa90a4

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

pkg/controller/snapshot_controller.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,22 @@ func (ctrl *csiSnapshotController) checkandBindSnapshotContent(snapshot *crdv1.V
401401
return fmt.Errorf("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match", snapshot.Name, content.Name)
402402
} else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotRef.UID != snapshot.UID {
403403
return fmt.Errorf("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match", snapshot.Name, content.Name)
404-
} else if content.Spec.VolumeSnapshotRef.UID == "" {
405-
contentClone := content.DeepCopy()
406-
contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID
407-
className := *(snapshot.Spec.VolumeSnapshotClassName)
408-
contentClone.Spec.VolumeSnapshotClassName = &className
409-
newContent, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Update(contentClone)
410-
if err != nil {
411-
glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", newContent.Name, err)
412-
return err
413-
}
414-
_, err = ctrl.storeContentUpdate(newContent)
415-
if err != nil {
416-
glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v", newContent.Name, err)
417-
return err
418-
}
404+
} else if content.Spec.VolumeSnapshotRef.UID != "" && content.Spec.VolumeSnapshotClassName != nil {
405+
return nil
406+
}
407+
contentClone := content.DeepCopy()
408+
contentClone.Spec.VolumeSnapshotRef.UID = snapshot.UID
409+
className := *(snapshot.Spec.VolumeSnapshotClassName)
410+
contentClone.Spec.VolumeSnapshotClassName = &className
411+
newContent, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Update(contentClone)
412+
if err != nil {
413+
glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", newContent.Name, err)
414+
return err
415+
}
416+
_, err = ctrl.storeContentUpdate(newContent)
417+
if err != nil {
418+
glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v", newContent.Name, err)
419+
return err
419420
}
420421
return nil
421422
}

0 commit comments

Comments
 (0)