@@ -337,10 +337,16 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
337
337
}
338
338
339
339
// update snapshot status
340
- klog .V (5 ).Infof ("syncUnreadySnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshot ))
341
- _ , err = ctrl .updateSnapshotStatus (snapshot , newContent )
342
- if err != nil {
340
+ for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
341
+ klog .V (5 ).Infof ("syncUnreadySnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshot ))
342
+ _ , err = ctrl .updateSnapshotStatus (snapshot , newContent )
343
+ if err == nil {
344
+ break
345
+ }
343
346
klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
347
+ }
348
+
349
+ if err != nil {
344
350
// update snapshot status failed
345
351
ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotStatusUpdateFailed" , fmt .Sprintf ("Snapshot status update failed, %v" , err ))
346
352
return err
@@ -393,10 +399,16 @@ func (ctrl *csiSnapshotCommonController) syncUnreadySnapshot(snapshot *crdv1.Vol
393
399
}
394
400
395
401
// Update snapshot status with BoundVolumeSnapshotContentName
396
- klog .V (5 ).Infof ("syncUnreadySnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshot ))
397
- _ , err = ctrl .updateSnapshotStatus (snapshot , content )
398
- if err != nil {
402
+ for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
403
+ klog .V (5 ).Infof ("syncUnreadySnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshot ))
404
+ _ , err = ctrl .updateSnapshotStatus (snapshot , content )
405
+ if err == nil {
406
+ break
407
+ }
399
408
klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
409
+ }
410
+
411
+ if err != nil {
400
412
// update snapshot status failed
401
413
ctrl .updateSnapshotErrorStatusWithEvent (snapshot , v1 .EventTypeWarning , "SnapshotStatusUpdateFailed" , fmt .Sprintf ("Snapshot status update failed, %v" , err ))
402
414
return err
@@ -489,17 +501,23 @@ func (ctrl *csiSnapshotCommonController) createSnapshotContent(snapshot *crdv1.V
489
501
490
502
var updateContent * crdv1.VolumeSnapshotContent
491
503
klog .V (3 ).Infof ("volume snapshot content %#v" , snapshotContent )
492
- // Try to create the VolumeSnapshotContent object
493
- klog .V (5 ).Infof ("createSnapshotContent [%s]: trying to save volume snapshot content %s" , utils .SnapshotKey (snapshot ), snapshotContent .Name )
494
- if updateContent , err = ctrl .clientset .SnapshotV1beta1 ().VolumeSnapshotContents ().Create (snapshotContent ); err == nil || apierrs .IsAlreadyExists (err ) {
495
- // Save succeeded.
496
- if err != nil {
497
- klog .V (3 ).Infof ("volume snapshot content %q for snapshot %q already exists, reusing" , snapshotContent .Name , utils .SnapshotKey (snapshot ))
498
- err = nil
499
- updateContent = snapshotContent
500
- } else {
501
- klog .V (3 ).Infof ("volume snapshot content %q for snapshot %q saved, %v" , snapshotContent .Name , utils .SnapshotKey (snapshot ), snapshotContent )
504
+ // Try to create the VolumeSnapshotContent object several times
505
+ for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
506
+ klog .V (5 ).Infof ("createSnapshotContent [%s]: trying to save volume snapshot content %s" , utils .SnapshotKey (snapshot ), snapshotContent .Name )
507
+ if updateContent , err = ctrl .clientset .SnapshotV1beta1 ().VolumeSnapshotContents ().Create (snapshotContent ); err == nil || apierrs .IsAlreadyExists (err ) {
508
+ // Save succeeded.
509
+ if err != nil {
510
+ klog .V (3 ).Infof ("volume snapshot content %q for snapshot %q already exists, reusing" , snapshotContent .Name , utils .SnapshotKey (snapshot ))
511
+ err = nil
512
+ updateContent = snapshotContent
513
+ } else {
514
+ klog .V (3 ).Infof ("volume snapshot content %q for snapshot %q saved, %v" , snapshotContent .Name , utils .SnapshotKey (snapshot ), snapshotContent )
515
+ }
516
+ break
502
517
}
518
+ // Save failed, try again after a while.
519
+ klog .V (3 ).Infof ("failed to save volume snapshot content %q for snapshot %q: %v" , snapshotContent .Name , utils .SnapshotKey (snapshot ), err )
520
+ time .Sleep (ctrl .createSnapshotContentInterval )
503
521
}
504
522
505
523
if err != nil {
@@ -849,14 +867,17 @@ func (ctrl *csiSnapshotCommonController) bindandUpdateVolumeSnapshot(snapshotCon
849
867
snapshotCopy := snapshotObj .DeepCopy ()
850
868
851
869
// update snapshot status
852
- klog .V (5 ).Infof ("bindandUpdateVolumeSnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshotCopy ))
853
- updateSnapshot , err := ctrl .updateSnapshotStatus (snapshotCopy , snapshotContent )
854
- if err == nil {
855
- snapshotCopy = updateSnapshot
870
+ for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
871
+ klog .V (5 ).Infof ("bindandUpdateVolumeSnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshotCopy ))
872
+ updateSnapshot , err := ctrl .updateSnapshotStatus (snapshotCopy , snapshotContent )
873
+ if err == nil {
874
+ snapshotCopy = updateSnapshot
875
+ break
876
+ }
877
+ klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
856
878
}
857
879
858
880
if err != nil {
859
- klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
860
881
// update snapshot status failed
861
882
ctrl .updateSnapshotErrorStatusWithEvent (snapshotCopy , v1 .EventTypeWarning , "SnapshotStatusUpdateFailed" , fmt .Sprintf ("Snapshot status update failed, %v" , err ))
862
883
return nil , err
0 commit comments