@@ -504,7 +504,9 @@ func (cloud *CloudProvider) insertRegionalDisk(
504504 if IsGCEError (err , "alreadyExists" ) {
505505 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
506506 if err != nil {
507- return err
507+ // failed to GetDisk, however the Disk may already exist
508+ // the error code should be non-Final
509+ return status .Error (codes .Unavailable , err .Error ())
508510 }
509511 err = cloud .ValidateExistingDisk (ctx , disk , params ,
510512 int64 (capacityRange .GetRequiredBytes ()),
@@ -516,16 +518,19 @@ func (cloud *CloudProvider) insertRegionalDisk(
516518 klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
517519 return nil
518520 }
519- return status .Error (codes .Internal , fmt .Sprintf ("unknown Insert disk error: %v" , err .Error ()))
521+ // if the error code is considered "final", RegionDisks.Insert might not be retried
522+ return fmt .Errorf ("unknown Insert Regional disk error: %w" , err )
520523 }
521524 klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
522525
523526 err = cloud .waitForRegionalOp (ctx , project , opName , volKey .Region )
527+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
528+ // the error code returned should be non-final
524529 if err != nil {
525530 if IsGCEError (err , "alreadyExists" ) {
526531 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
527532 if err != nil {
528- return err
533+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
529534 }
530535 err = cloud .ValidateExistingDisk (ctx , disk , params ,
531536 int64 (capacityRange .GetRequiredBytes ()),
@@ -537,7 +542,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
537542 klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
538543 return nil
539544 }
540- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
545+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
541546 }
542547 return nil
543548}
@@ -616,7 +621,9 @@ func (cloud *CloudProvider) insertZonalDisk(
616621 if IsGCEError (err , "alreadyExists" ) {
617622 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
618623 if err != nil {
619- return err
624+ // failed to GetDisk, however the Disk may already exist
625+ // the error code should be non-Final
626+ return status .Error (codes .Unavailable , err .Error ())
620627 }
621628 err = cloud .ValidateExistingDisk (ctx , disk , params ,
622629 int64 (capacityRange .GetRequiredBytes ()),
@@ -628,17 +635,20 @@ func (cloud *CloudProvider) insertZonalDisk(
628635 klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
629636 return nil
630637 }
638+ // if the error code is considered "final", Disks.Insert might not be retried
631639 return fmt .Errorf ("unknown Insert disk error: %w" , err )
632640 }
633641 klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
634642
635643 err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
636644
637645 if err != nil {
646+ // failed to wait for Op to finish, however, the Op possibly is still running as expected
647+ // the error code returned should be non-final
638648 if IsGCEError (err , "alreadyExists" ) {
639649 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
640650 if err != nil {
641- return err
651+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
642652 }
643653 err = cloud .ValidateExistingDisk (ctx , disk , params ,
644654 int64 (capacityRange .GetRequiredBytes ()),
@@ -650,7 +660,7 @@ func (cloud *CloudProvider) insertZonalDisk(
650660 klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
651661 return nil
652662 }
653- return fmt .Errorf ("unknown Insert disk operation error : %w " , err )
663+ return status .Errorf (codes . Unavailable , "unknown error when polling the operation : %v " , err . Error () )
654664 }
655665 return nil
656666}
0 commit comments