@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
25
+ "github.com/kubernetes-csi/external-snapshotter/pkg/snapshotter"
25
26
"k8s.io/api/core/v1"
26
27
storagev1 "k8s.io/api/storage/v1"
27
28
storage "k8s.io/api/storage/v1beta1"
@@ -364,8 +365,8 @@ func (ctrl *csiSnapshotController) createSnapshot(snapshot *crdv1.VolumeSnapshot
364
365
klog .V (5 ).Infof ("createSnapshot[%s]: started" , snapshotKey (snapshot ))
365
366
opName := fmt .Sprintf ("create-%s[%s]" , snapshotKey (snapshot ), string (snapshot .UID ))
366
367
ctrl .scheduleOperation (opName , func () error {
367
- snapshotObj , err := ctrl .createSnapshotOperation (snapshot )
368
- if err != nil {
368
+ snapshotObj , state , err := ctrl .createSnapshotOperation (snapshot )
369
+ if err != nil && state == snapshotter . SnapshottingFinished {
369
370
ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotCreationFailed" , fmt .Sprintf ("Failed to create snapshot: %v" , err ))
370
371
klog .Errorf ("createSnapshot [%s]: error occurred in createSnapshotOperation: %v" , opName , err )
371
372
return err
@@ -375,7 +376,19 @@ func (ctrl *csiSnapshotController) createSnapshot(snapshot *crdv1.VolumeSnapshot
375
376
// We will get an "snapshot update" event soon, this is not a big error
376
377
klog .V (4 ).Infof ("createSnapshot [%s]: cannot update internal cache: %v" , snapshotKey (snapshotObj ), updateErr )
377
378
}
378
- return nil
379
+ if state == snapshotter .SnapshottingFinished {
380
+ // Snapshotting finished, remove obj from the queue.
381
+ ctrl .snapshotQueue .Done (snapshotObj )
382
+ return nil
383
+
384
+ } else if state == snapshotter .SnapshottingInBackground {
385
+ klog .V (4 ).Infof ("createSnapshot [%s]: Temporary error received, adding Snapshot back in queue: %v" , snapshotKey (snapshotObj ), updateErr )
386
+ // Snapshotting still in progress.
387
+ return nil
388
+ } else {
389
+ // State is SnapshottingNoChange. Don't change the snapshot queue.
390
+ return nil
391
+ }
379
392
})
380
393
return nil
381
394
}
@@ -584,7 +597,7 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn
584
597
if err != nil {
585
598
return nil , fmt .Errorf ("failed to get input parameters to create snapshot %s: %q" , snapshot .Name , err )
586
599
}
587
- driverName , snapshotID , creationTime , size , readyToUse , err = ctrl .handler .CreateSnapshot (snapshot , volume , class .Parameters , snapshotterCredentials )
600
+ driverName , snapshotID , creationTime , size , readyToUse , _ , err = ctrl .handler .CreateSnapshot (snapshot , volume , class .Parameters , snapshotterCredentials )
588
601
if err != nil {
589
602
klog .Errorf ("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q" , err )
590
603
return nil , err
@@ -611,30 +624,30 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn
611
624
// 2. Update VolumeSnapshot status with creationtimestamp information
612
625
// 3. Create the VolumeSnapshotContent object with the snapshot id information.
613
626
// 4. Bind the VolumeSnapshot and VolumeSnapshotContent object
614
- func (ctrl * csiSnapshotController ) createSnapshotOperation (snapshot * crdv1.VolumeSnapshot ) (* crdv1.VolumeSnapshot , error ) {
627
+ func (ctrl * csiSnapshotController ) createSnapshotOperation (snapshot * crdv1.VolumeSnapshot ) (* crdv1.VolumeSnapshot , snapshotter. SnapshottingState , error ) {
615
628
klog .Infof ("createSnapshot: Creating snapshot %s through the plugin ..." , snapshotKey (snapshot ))
616
629
617
630
if snapshot .Status .Error != nil && ! isControllerUpdateFailError (snapshot .Status .Error ) {
618
631
klog .V (4 ).Infof ("error is already set in snapshot, do not retry to create: %s" , snapshot .Status .Error .Message )
619
- return snapshot , nil
632
+ return snapshot , snapshotter . SnapshottingFinished , nil
620
633
}
621
634
622
635
// If PVC is not being deleted and finalizer is not added yet, a finalizer should be added.
623
636
klog .V (5 ).Infof ("createSnapshotOperation: Check if PVC is not being deleted and add Finalizer for source of snapshot [%s] if needed" , snapshot .Name )
624
637
err := ctrl .ensureSnapshotSourceFinalizer (snapshot )
625
638
if err != nil {
626
639
klog .Errorf ("createSnapshotOperation failed to add finalizer for source of snapshot %s" , err )
627
- return nil , err
640
+ return nil , snapshotter . SnapshottingFinished , err
628
641
}
629
642
630
643
class , volume , contentName , snapshotterCredentials , err := ctrl .getCreateSnapshotInput (snapshot )
631
644
if err != nil {
632
- return nil , fmt .Errorf ("failed to get input parameters to create snapshot %s: %q" , snapshot .Name , err )
645
+ return nil , snapshotter . SnapshottingFinished , fmt .Errorf ("failed to get input parameters to create snapshot %s: %q" , snapshot .Name , err )
633
646
}
634
647
635
- driverName , snapshotID , creationTime , size , readyToUse , err := ctrl .handler .CreateSnapshot (snapshot , volume , class .Parameters , snapshotterCredentials )
648
+ driverName , snapshotID , creationTime , size , readyToUse , state , err := ctrl .handler .CreateSnapshot (snapshot , volume , class .Parameters , snapshotterCredentials )
636
649
if err != nil {
637
- return nil , fmt .Errorf ("failed to take snapshot of the volume, %s: %q" , volume .Name , err )
650
+ return nil , state , fmt .Errorf ("failed to take snapshot of the volume, %s: %q" , volume .Name , err )
638
651
}
639
652
640
653
klog .V (5 ).Infof ("Created snapshot: driver %s, snapshotId %s, creationTime %v, size %d, readyToUse %t" , driverName , snapshotID , creationTime , size , readyToUse )
@@ -651,16 +664,16 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum
651
664
}
652
665
653
666
if err != nil {
654
- return nil , err
667
+ return nil , snapshotter . SnapshottingFinished , err
655
668
}
656
669
// Create VolumeSnapshotContent in the database
657
670
volumeRef , err := ref .GetReference (scheme .Scheme , volume )
658
671
if err != nil {
659
- return nil , err
672
+ return nil , snapshotter . SnapshottingFinished , err
660
673
}
661
674
snapshotRef , err := ref .GetReference (scheme .Scheme , snapshot )
662
675
if err != nil {
663
- return nil , err
676
+ return nil , snapshotter . SnapshottingFinished , err
664
677
}
665
678
666
679
if class .DeletionPolicy == nil {
@@ -713,15 +726,15 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum
713
726
strerr := fmt .Sprintf ("Error creating volume snapshot content object for snapshot %s: %v." , snapshotKey (snapshot ), err )
714
727
klog .Error (strerr )
715
728
ctrl .eventRecorder .Event (newSnapshot , v1 .EventTypeWarning , "CreateSnapshotContentFailed" , strerr )
716
- return nil , newControllerUpdateError (snapshotKey (snapshot ), err .Error ())
729
+ return nil , snapshotter . SnapshottingInBackground , newControllerUpdateError (snapshotKey (snapshot ), err .Error ())
717
730
}
718
731
719
732
// save succeeded, bind and update status for snapshot.
720
733
result , err := ctrl .bindandUpdateVolumeSnapshot (snapshotContent , newSnapshot )
721
734
if err != nil {
722
- return nil , err
735
+ return nil , snapshotter . SnapshottingFinished , err
723
736
}
724
- return result , nil
737
+ return result , snapshotter . SnapshottingFinished , nil
725
738
}
726
739
727
740
// Delete a snapshot
0 commit comments