@@ -515,7 +515,9 @@ func (cloud *CloudProvider) insertRegionalDisk(
515515 if IsGCEError (err , "alreadyExists" ) {
516516 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
517517 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 ())
519521 }
520522 err = cloud .ValidateExistingDisk (ctx , disk , params ,
521523 int64 (capacityRange .GetRequiredBytes ()),
@@ -527,16 +529,19 @@ func (cloud *CloudProvider) insertRegionalDisk(
527529 klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
528530 return nil
529531 }
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 )
531534 }
532535 klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
533536
534537 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
535540 if err != nil {
536541 if IsGCEError (err , "alreadyExists" ) {
537542 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
538543 if err != nil {
539- return err
544+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
540545 }
541546 err = cloud .ValidateExistingDisk (ctx , disk , params ,
542547 int64 (capacityRange .GetRequiredBytes ()),
@@ -548,7 +553,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
548553 klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
549554 return nil
550555 }
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 () )
552557 }
553558 return nil
554559}
@@ -630,7 +635,9 @@ func (cloud *CloudProvider) insertZonalDisk(
630635 if IsGCEError (err , "alreadyExists" ) {
631636 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
632637 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 ())
634641 }
635642 err = cloud .ValidateExistingDisk (ctx , disk , params ,
636643 int64 (capacityRange .GetRequiredBytes ()),
@@ -642,17 +649,20 @@ func (cloud *CloudProvider) insertZonalDisk(
642649 klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
643650 return nil
644651 }
652+ // if the error code is considered "final", Disks.Insert might not be retried
645653 return fmt .Errorf ("unknown Insert disk error: %w" , err )
646654 }
647655 klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
648656
649657 err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
650658
651659 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
652662 if IsGCEError (err , "alreadyExists" ) {
653663 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
654664 if err != nil {
655- return err
665+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
656666 }
657667 err = cloud .ValidateExistingDisk (ctx , disk , params ,
658668 int64 (capacityRange .GetRequiredBytes ()),
@@ -664,7 +674,7 @@ func (cloud *CloudProvider) insertZonalDisk(
664674 klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
665675 return nil
666676 }
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 () )
668678 }
669679 return nil
670680}
0 commit comments