@@ -22,8 +22,6 @@ import (
2222 "strings"
2323 "time"
2424
25- crdv1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
26- "github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
2725 v1 "k8s.io/api/core/v1"
2826 storagev1 "k8s.io/api/storage/v1"
2927 apierrs "k8s.io/apimachinery/pkg/api/errors"
@@ -34,6 +32,9 @@ import (
3432 ref "k8s.io/client-go/tools/reference"
3533 "k8s.io/klog"
3634 "k8s.io/kubernetes/pkg/util/slice"
35+
36+ crdv1 "github.com/kubernetes-csi/external-snapshotter/v2/pkg/apis/volumesnapshot/v1beta1"
37+ "github.com/kubernetes-csi/external-snapshotter/v2/pkg/utils"
3738)
3839
3940// ==================================================================
@@ -334,8 +335,8 @@ func (ctrl *csiSnapshotCommonController) checkandRemoveSnapshotFinalizersAndChec
334335func (ctrl * csiSnapshotCommonController ) checkandAddSnapshotFinalizers (snapshot * crdv1.VolumeSnapshot ) error {
335336 // get the content for this Snapshot
336337 var (
337- content * crdv1.VolumeSnapshotContent = nil
338- err error = nil
338+ content * crdv1.VolumeSnapshotContent
339+ err error
339340 )
340341 if snapshot .Spec .Source .VolumeSnapshotContentName != nil {
341342 content , err = ctrl .getPreprovisionedContentFromStore (snapshot )
@@ -374,7 +375,7 @@ func (ctrl *csiSnapshotCommonController) checkandAddSnapshotFinalizers(snapshot
374375// If there is any problem with the binding (e.g., snapshot points to a non-existent snapshot content), update the snapshot status and emit event.
375376func (ctrl * csiSnapshotCommonController ) syncReadySnapshot (snapshot * crdv1.VolumeSnapshot ) error {
376377 if ! utils .IsBoundVolumeSnapshotContentNameSet (snapshot ) {
377- return fmt .Errorf ("snapshot %s is not bound to a content. " , utils .SnapshotKey (snapshot ))
378+ return fmt .Errorf ("snapshot %s is not bound to a content" , utils .SnapshotKey (snapshot ))
378379 }
379380 content , err := ctrl .getContentFromStore (* snapshot .Status .BoundVolumeSnapshotContentName )
380381 if err != nil {
@@ -464,30 +465,29 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
464465 if snapshot .Spec .Source .PersistentVolumeClaimName == nil {
465466 ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotPVCSourceMissing" , fmt .Sprintf ("PVC source for snapshot %s is missing" , uniqueSnapshotName ))
466467 return fmt .Errorf ("expected PVC source for snapshot %s but got nil" , uniqueSnapshotName )
467- } else {
468- var err error
469- var content * crdv1.VolumeSnapshotContent
470- if content , err = ctrl .createSnapshotContent (snapshot ); err != nil {
471- ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotContentCreationFailed" , fmt .Sprintf ("Failed to create snapshot content with error %v" , err ))
472- return err
473- }
468+ }
469+ var err error
470+ var content * crdv1.VolumeSnapshotContent
471+ if content , err = ctrl .createSnapshotContent (snapshot ); err != nil {
472+ ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotContentCreationFailed" , fmt .Sprintf ("Failed to create snapshot content with error %v" , err ))
473+ return err
474+ }
474475
475- // Update snapshot status with BoundVolumeSnapshotContentName
476- for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
477- klog .V (5 ).Infof ("syncUnreadySnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshot ))
478- _ , err = ctrl .updateSnapshotStatus (snapshot , content )
479- if err == nil {
480- break
481- }
482- klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
483- time .Sleep (ctrl .createSnapshotContentInterval )
476+ // Update snapshot status with BoundVolumeSnapshotContentName
477+ for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
478+ klog .V (5 ).Infof ("syncUnreadySnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshot ))
479+ _ , err = ctrl .updateSnapshotStatus (snapshot , content )
480+ if err == nil {
481+ break
484482 }
483+ klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
484+ time .Sleep (ctrl .createSnapshotContentInterval )
485+ }
485486
486- if err != nil {
487- // update snapshot status failed
488- ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotStatusUpdateFailed" , fmt .Sprintf ("Snapshot status update failed, %v" , err ))
489- return err
490- }
487+ if err != nil {
488+ // update snapshot status failed
489+ ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotStatusUpdateFailed" , fmt .Sprintf ("Snapshot status update failed, %v" , err ))
490+ return err
491491 }
492492 }
493493 return nil
@@ -1356,14 +1356,14 @@ func (ctrl *csiSnapshotCommonController) getSnapshotFromStore(snapshotName strin
13561356 klog .V (4 ).Infof ("getSnapshotFromStore: snapshot %s not found" , snapshotName )
13571357 // Fall through with snapshot = nil
13581358 return nil , nil
1359- } else {
1360- var ok bool
1361- snapshot , ok = obj .(* crdv1.VolumeSnapshot )
1362- if ! ok {
1363- return nil , fmt .Errorf ("cannot convert object from snapshot cache to snapshot %q!?: %#v" , snapshotName , obj )
1364- }
1365- klog .V (4 ).Infof ("getSnapshotFromStore: snapshot %s found" , snapshotName )
13661359 }
1360+ var ok bool
1361+ snapshot , ok = obj .(* crdv1.VolumeSnapshot )
1362+ if ! ok {
1363+ return nil , fmt .Errorf ("cannot convert object from snapshot cache to snapshot %q!?: %#v" , snapshotName , obj )
1364+ }
1365+ klog .V (4 ).Infof ("getSnapshotFromStore: snapshot %s found" , snapshotName )
1366+
13671367 return snapshot , nil
13681368}
13691369
0 commit comments