@@ -515,7 +515,9 @@ func (cloud *CloudProvider) insertRegionalDisk(
515
515
if IsGCEError (err , "alreadyExists" ) {
516
516
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
517
517
if err != nil {
518
- return err
518
+ // failed to GetDisk, however the Disk may already exist
519
+ // the error code should be non-Final
520
+ return status .Error (codes .Unavailable , err .Error ())
519
521
}
520
522
err = cloud .ValidateExistingDisk (ctx , disk , params ,
521
523
int64 (capacityRange .GetRequiredBytes ()),
@@ -527,16 +529,19 @@ func (cloud *CloudProvider) insertRegionalDisk(
527
529
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
528
530
return nil
529
531
}
530
- return status .Error (codes .Internal , fmt .Sprintf ("unknown Insert disk error: %v" , err .Error ()))
532
+ // if the error code is considered "final", RegionDisks.Insert might not be retried
533
+ return fmt .Errorf ("unknown Insert Regional disk error: %w" , err )
531
534
}
532
535
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
533
536
534
537
err = cloud .waitForRegionalOp (ctx , project , opName , volKey .Region )
538
+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
539
+ // the error code returned should be non-final
535
540
if err != nil {
536
541
if IsGCEError (err , "alreadyExists" ) {
537
542
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
538
543
if err != nil {
539
- return err
544
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
540
545
}
541
546
err = cloud .ValidateExistingDisk (ctx , disk , params ,
542
547
int64 (capacityRange .GetRequiredBytes ()),
@@ -548,7 +553,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
548
553
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
549
554
return nil
550
555
}
551
- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
556
+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
552
557
}
553
558
return nil
554
559
}
@@ -627,7 +632,9 @@ func (cloud *CloudProvider) insertZonalDisk(
627
632
if IsGCEError (err , "alreadyExists" ) {
628
633
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
629
634
if err != nil {
630
- return err
635
+ // failed to GetDisk, however the Disk may already exist
636
+ // the error code should be non-Final
637
+ return status .Error (codes .Unavailable , err .Error ())
631
638
}
632
639
err = cloud .ValidateExistingDisk (ctx , disk , params ,
633
640
int64 (capacityRange .GetRequiredBytes ()),
@@ -639,17 +646,20 @@ func (cloud *CloudProvider) insertZonalDisk(
639
646
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
640
647
return nil
641
648
}
649
+ // if the error code is considered "final", Disks.Insert might not be retried
642
650
return fmt .Errorf ("unknown Insert disk error: %w" , err )
643
651
}
644
652
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
645
653
646
654
err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
647
655
648
656
if err != nil {
657
+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
658
+ // the error code returned should be non-final
649
659
if IsGCEError (err , "alreadyExists" ) {
650
660
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
651
661
if err != nil {
652
- return err
662
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
653
663
}
654
664
err = cloud .ValidateExistingDisk (ctx , disk , params ,
655
665
int64 (capacityRange .GetRequiredBytes ()),
@@ -661,7 +671,7 @@ func (cloud *CloudProvider) insertZonalDisk(
661
671
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
662
672
return nil
663
673
}
664
- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
674
+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
665
675
}
666
676
return nil
667
677
}
0 commit comments