@@ -560,7 +560,9 @@ func (cloud *CloudProvider) insertRegionalDisk(
560
560
if IsGCEError (err , "alreadyExists" ) {
561
561
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
562
562
if err != nil {
563
- return err
563
+ // failed to GetDisk, however the Disk may already exist
564
+ // the error code should be non-Final
565
+ return status .Error (codes .Unavailable , err .Error ())
564
566
}
565
567
err = cloud .ValidateExistingDisk (ctx , disk , params ,
566
568
int64 (capacityRange .GetRequiredBytes ()),
@@ -572,16 +574,19 @@ func (cloud *CloudProvider) insertRegionalDisk(
572
574
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
573
575
return nil
574
576
}
575
- return status .Error (codes .Internal , fmt .Sprintf ("unknown Insert disk error: %v" , err .Error ()))
577
+ // if the error code is considered "final", RegionDisks.Insert might not be retried
578
+ return fmt .Errorf ("unknown Insert Regional disk error: %w" , err )
576
579
}
577
580
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
578
581
579
582
err = cloud .waitForRegionalOp (ctx , project , opName , volKey .Region )
583
+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
584
+ // the error code returned should be non-final
580
585
if err != nil {
581
586
if IsGCEError (err , "alreadyExists" ) {
582
587
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
583
588
if err != nil {
584
- return err
589
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
585
590
}
586
591
err = cloud .ValidateExistingDisk (ctx , disk , params ,
587
592
int64 (capacityRange .GetRequiredBytes ()),
@@ -593,7 +598,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
593
598
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
594
599
return nil
595
600
}
596
- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
601
+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
597
602
}
598
603
return nil
599
604
}
@@ -695,7 +700,9 @@ func (cloud *CloudProvider) insertZonalDisk(
695
700
if IsGCEError (err , "alreadyExists" ) {
696
701
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
697
702
if err != nil {
698
- return err
703
+ // failed to GetDisk, however the Disk may already exist
704
+ // the error code should be non-Final
705
+ return status .Error (codes .Unavailable , err .Error ())
699
706
}
700
707
err = cloud .ValidateExistingDisk (ctx , disk , params ,
701
708
int64 (capacityRange .GetRequiredBytes ()),
@@ -707,17 +714,20 @@ func (cloud *CloudProvider) insertZonalDisk(
707
714
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
708
715
return nil
709
716
}
717
+ // if the error code is considered "final", Disks.Insert might not be retried
710
718
return fmt .Errorf ("unknown Insert disk error: %w" , err )
711
719
}
712
720
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
713
721
714
722
err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
715
723
716
724
if err != nil {
725
+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
726
+ // the error code returned should be non-final
717
727
if IsGCEError (err , "alreadyExists" ) {
718
728
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
719
729
if err != nil {
720
- return err
730
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
721
731
}
722
732
err = cloud .ValidateExistingDisk (ctx , disk , params ,
723
733
int64 (capacityRange .GetRequiredBytes ()),
@@ -729,7 +739,7 @@ func (cloud *CloudProvider) insertZonalDisk(
729
739
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
730
740
return nil
731
741
}
732
- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
742
+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
733
743
}
734
744
return nil
735
745
}
0 commit comments