@@ -257,16 +257,15 @@ func (ctrl *csiSnapshotController) syncUnreadySnapshot(snapshot *crdv1.VolumeSna
257257 if ! ok {
258258 return fmt .Errorf ("expected volume snapshot content, got %+v" , contentObj )
259259 }
260-
261- if err := ctrl . checkandBindSnapshotContent ( snapshot , content ); err != nil {
260+ contentBound , err := ctrl . checkandBindSnapshotContent ( snapshot , content )
261+ if err != nil {
262262 // snapshot is bound but content is not bound to snapshot correctly
263263 ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotBindFailed" , fmt .Sprintf ("Snapshot failed to bind VolumeSnapshotContent, %v" , err ))
264264 return fmt .Errorf ("snapshot %s is bound, but VolumeSnapshotContent %s is not bound to the VolumeSnapshot correctly, %v" , uniqueSnapshotName , content .Name , err )
265265 }
266-
267266 // snapshot is already bound correctly, check the status and update if it is ready.
268267 klog .V (5 ).Infof ("Check and update snapshot %s status" , uniqueSnapshotName )
269- if err = ctrl .checkandUpdateBoundSnapshotStatus (snapshot , content ); err != nil {
268+ if err = ctrl .checkandUpdateBoundSnapshotStatus (snapshot , contentBound ); err != nil {
270269 return err
271270 }
272271 return nil
@@ -493,13 +492,13 @@ func (ctrl *csiSnapshotController) isVolumeBeingCreatedFromSnapshot(snapshot *cr
493492}
494493
495494// The function checks whether the volumeSnapshotRef in snapshot content matches the given snapshot. If match, it binds the content with the snapshot
496- func (ctrl * csiSnapshotController ) checkandBindSnapshotContent (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) error {
495+ func (ctrl * csiSnapshotController ) checkandBindSnapshotContent (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) ( * crdv1. VolumeSnapshotContent , error ) {
497496 if content .Spec .VolumeSnapshotRef == nil || content .Spec .VolumeSnapshotRef .Name != snapshot .Name {
498- return fmt .Errorf ("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match" , snapshot .Name , content .Name )
497+ return nil , fmt .Errorf ("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match" , snapshot .Name , content .Name )
499498 } else if content .Spec .VolumeSnapshotRef .UID != "" && content .Spec .VolumeSnapshotRef .UID != snapshot .UID {
500- return fmt .Errorf ("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match" , snapshot .Name , content .Name )
499+ return nil , fmt .Errorf ("Could not bind snapshot %s and content %s, the VolumeSnapshotRef does not match" , snapshot .Name , content .Name )
501500 } else if content .Spec .VolumeSnapshotRef .UID != "" && content .Spec .VolumeSnapshotClassName != nil {
502- return nil
501+ return content , nil
503502 }
504503 contentClone := content .DeepCopy ()
505504 contentClone .Spec .VolumeSnapshotRef .UID = snapshot .UID
@@ -508,14 +507,14 @@ func (ctrl *csiSnapshotController) checkandBindSnapshotContent(snapshot *crdv1.V
508507 newContent , err := ctrl .clientset .VolumesnapshotV1alpha1 ().VolumeSnapshotContents ().Update (contentClone )
509508 if err != nil {
510509 klog .V (4 ).Infof ("updating VolumeSnapshotContent[%s] error status failed %v" , newContent .Name , err )
511- return err
510+ return nil , err
512511 }
513512 _ , err = ctrl .storeContentUpdate (newContent )
514513 if err != nil {
515514 klog .V (4 ).Infof ("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v" , newContent .Name , err )
516- return err
515+ return nil , err
517516 }
518- return nil
517+ return newContent , nil
519518}
520519
521520func (ctrl * csiSnapshotController ) getCreateSnapshotInput (snapshot * crdv1.VolumeSnapshot ) (* crdv1.VolumeSnapshotClass , * v1.PersistentVolume , string , map [string ]string , error ) {
0 commit comments