@@ -170,7 +170,7 @@ func (ctrl *csiSnapshotController) syncReadySnapshot(snapshot *crdv1.VolumeSnaps
170
170
return fmt .Errorf ("Cannot convert object from snapshot content store to VolumeSnapshotContent %q!?: %#v" , snapshot .Spec .SnapshotContentName , obj )
171
171
}
172
172
173
- glog .V (5 ).Infof ("syncCompleteSnapshot [%s]: VolumeSnapshotContent %q found" , snapshotKey (snapshot ), content .Name )
173
+ glog .V (5 ).Infof ("syncReadySnapshot [%s]: VolumeSnapshotContent %q found" , snapshotKey (snapshot ), content .Name )
174
174
if ! IsSnapshotBound (snapshot , content ) {
175
175
// snapshot is bound but content is not bound to snapshot correctly
176
176
if err = ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotMisbound" , "VolumeSnapshotContent is not bound to the VolumeSnapshot correctly" ); err != nil {
@@ -212,7 +212,7 @@ func (ctrl *csiSnapshotController) syncUnreadySnapshot(snapshot *crdv1.VolumeSna
212
212
213
213
// snapshot is already bound correctly, check the status and update if it is ready.
214
214
glog .V (5 ).Infof ("Check and update snapshot %s status" , uniqueSnapshotName )
215
- if err = ctrl .checkandUpdateSnapshotStatus (snapshot , content ); err != nil {
215
+ if err = ctrl .checkandUpdateBoundSnapshotStatus (snapshot , content ); err != nil {
216
216
return err
217
217
}
218
218
return nil
@@ -321,11 +321,11 @@ func (ctrl *csiSnapshotController) createSnapshot(snapshot *crdv1.VolumeSnapshot
321
321
return nil
322
322
}
323
323
324
- func (ctrl * csiSnapshotController ) checkandUpdateSnapshotStatus (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) error {
324
+ func (ctrl * csiSnapshotController ) checkandUpdateBoundSnapshotStatus (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) error {
325
325
glog .V (5 ).Infof ("checkandUpdateSnapshotStatus[%s] started" , snapshotKey (snapshot ))
326
326
opName := fmt .Sprintf ("check-%s[%s]" , snapshotKey (snapshot ), string (snapshot .UID ))
327
327
ctrl .scheduleOperation (opName , func () error {
328
- snapshotObj , err := ctrl .checkandUpdateSnapshotStatusOperation (snapshot , content )
328
+ snapshotObj , err := ctrl .checkandUpdateBoundSnapshotStatusOperation (snapshot , content )
329
329
if err != nil {
330
330
ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotCheckandUpdateFailed" , fmt .Sprintf ("Failed to check and update snapshot: %v" , err ))
331
331
glog .Errorf ("checkandUpdateSnapshotStatus [%s]: error occured %v" , snapshotKey (snapshot ), err )
@@ -420,7 +420,7 @@ func (ctrl *csiSnapshotController) checkandBindSnapshotContent(snapshot *crdv1.V
420
420
return nil
421
421
}
422
422
423
- func (ctrl * csiSnapshotController ) checkandUpdateSnapshotStatusOperation (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) (* crdv1.VolumeSnapshot , error ) {
423
+ func (ctrl * csiSnapshotController ) checkandUpdateBoundSnapshotStatusOperation (snapshot * crdv1.VolumeSnapshot , content * crdv1.VolumeSnapshotContent ) (* crdv1.VolumeSnapshot , error ) {
424
424
status , _ , size , err := ctrl .handler .GetSnapshotStatus (content )
425
425
if err != nil {
426
426
return nil , fmt .Errorf ("failed to check snapshot status %s with error %v" , snapshot .Name , err )
@@ -430,6 +430,10 @@ func (ctrl *csiSnapshotController) checkandUpdateSnapshotStatusOperation(snapsho
430
430
if err != nil {
431
431
return nil , err
432
432
}
433
+ err = ctrl .updateSnapshotContentSize (content , size )
434
+ if err != nil {
435
+ return nil , err
436
+ }
433
437
return newSnapshot , nil
434
438
}
435
439
@@ -521,7 +525,7 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum
521
525
Driver : driverName ,
522
526
SnapshotHandle : snapshotID ,
523
527
CreationTime : & timestamp ,
524
- RestoreSize : resource . NewQuantity ( size , resource . BinarySI ) ,
528
+ RestoreSize : & size ,
525
529
},
526
530
},
527
531
VolumeSnapshotClassName : & (class .Name ),
@@ -637,6 +641,28 @@ func (ctrl *csiSnapshotController) bindandUpdateVolumeSnapshot(snapshotContent *
637
641
return snapshotCopy , nil
638
642
}
639
643
644
+ // updateSnapshotContentSize update the restore size for snapshot content
645
+ func (ctrl * csiSnapshotController ) updateSnapshotContentSize (content * crdv1.VolumeSnapshotContent , size int64 ) error {
646
+ if content .Spec .VolumeSnapshotSource .CSI == nil || size == 0 {
647
+ return nil
648
+ }
649
+ if content .Spec .VolumeSnapshotSource .CSI .RestoreSize != nil && * content .Spec .VolumeSnapshotSource .CSI .RestoreSize > 0 {
650
+ return nil
651
+ }
652
+ contentClone := content .DeepCopy ()
653
+ contentClone .Spec .VolumeSnapshotSource .CSI .RestoreSize = & size
654
+ _ , err := ctrl .clientset .VolumesnapshotV1alpha1 ().VolumeSnapshotContents ().Update (contentClone )
655
+ if err != nil {
656
+ return newControllerUpdateError (content .Name , err .Error ())
657
+ }
658
+
659
+ _ , err = ctrl .storeContentUpdate (contentClone )
660
+ if err != nil {
661
+ glog .Errorf ("failed to update content store %v" , err )
662
+ }
663
+ return nil
664
+ }
665
+
640
666
// UpdateSnapshotStatus converts snapshot status to crdv1.VolumeSnapshotCondition
641
667
func (ctrl * csiSnapshotController ) updateSnapshotStatus (snapshot * crdv1.VolumeSnapshot , csistatus * csi.SnapshotStatus , createdAt , size int64 , bound bool ) (* crdv1.VolumeSnapshot , error ) {
642
668
glog .V (5 ).Infof ("updating VolumeSnapshot[]%s, set status %v, timestamp %v" , snapshotKey (snapshot ), csistatus , createdAt )
0 commit comments