@@ -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
}
@@ -630,7 +635,9 @@ func (cloud *CloudProvider) insertZonalDisk(
630
635
if IsGCEError (err , "alreadyExists" ) {
631
636
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
632
637
if err != nil {
633
- return err
638
+ // failed to GetDisk, however the Disk may already exist
639
+ // the error code should be non-Final
640
+ return status .Error (codes .Unavailable , err .Error ())
634
641
}
635
642
err = cloud .ValidateExistingDisk (ctx , disk , params ,
636
643
int64 (capacityRange .GetRequiredBytes ()),
@@ -642,17 +649,20 @@ func (cloud *CloudProvider) insertZonalDisk(
642
649
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
643
650
return nil
644
651
}
652
+ // if the error code is considered "final", Disks.Insert might not be retried
645
653
return fmt .Errorf ("unknown Insert disk error: %w" , err )
646
654
}
647
655
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
648
656
649
657
err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
650
658
651
659
if err != nil {
660
+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
661
+ // the error code returned should be non-final
652
662
if IsGCEError (err , "alreadyExists" ) {
653
663
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
654
664
if err != nil {
655
- return err
665
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
656
666
}
657
667
err = cloud .ValidateExistingDisk (ctx , disk , params ,
658
668
int64 (capacityRange .GetRequiredBytes ()),
@@ -664,7 +674,7 @@ func (cloud *CloudProvider) insertZonalDisk(
664
674
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
665
675
return nil
666
676
}
667
- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
677
+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
668
678
}
669
679
return nil
670
680
}
0 commit comments