Skip to content

Commit 58f71be

Browse files
committed
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.
1 parent 6327ae5 commit 58f71be

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)