@@ -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,26 @@ 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
+ if updateContent == nil {
517
+ updateContent = snapshotContent
518
+ }
519
+ break
502
520
}
521
+ // Save failed, try again after a while.
522
+ klog .V (3 ).Infof ("failed to save volume snapshot content %q for snapshot %q: %v" , snapshotContent .Name , utils .SnapshotKey (snapshot ), err )
523
+ time .Sleep (ctrl .createSnapshotContentInterval )
503
524
}
504
525
505
526
if err != nil {
@@ -849,14 +870,17 @@ func (ctrl *csiSnapshotCommonController) bindandUpdateVolumeSnapshot(snapshotCon
849
870
snapshotCopy := snapshotObj .DeepCopy ()
850
871
851
872
// 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
873
+ for i := 0 ; i < ctrl .createSnapshotContentRetryCount ; i ++ {
874
+ klog .V (5 ).Infof ("bindandUpdateVolumeSnapshot [%s]: trying to update snapshot status" , utils .SnapshotKey (snapshotCopy ))
875
+ updateSnapshot , err := ctrl .updateSnapshotStatus (snapshotCopy , snapshotContent )
876
+ if err == nil {
877
+ snapshotCopy = updateSnapshot
878
+ break
879
+ }
880
+ klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
856
881
}
857
882
858
883
if err != nil {
859
- klog .V (4 ).Infof ("failed to update snapshot %s status: %v" , utils .SnapshotKey (snapshot ), err )
860
884
// update snapshot status failed
861
885
ctrl .updateSnapshotErrorStatusWithEvent (snapshotCopy , v1 .EventTypeWarning , "SnapshotStatusUpdateFailed" , fmt .Sprintf ("Snapshot status update failed, %v" , err ))
862
886
return nil , err
0 commit comments