@@ -560,7 +560,9 @@ func (cloud *CloudProvider) insertRegionalDisk(
560560 if IsGCEError (err , "alreadyExists" ) {
561561 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
562562 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 ())
564566 }
565567 err = cloud .ValidateExistingDisk (ctx , disk , params ,
566568 int64 (capacityRange .GetRequiredBytes ()),
@@ -572,16 +574,19 @@ func (cloud *CloudProvider) insertRegionalDisk(
572574 klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
573575 return nil
574576 }
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 )
576579 }
577580 klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
578581
579582 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
580585 if err != nil {
581586 if IsGCEError (err , "alreadyExists" ) {
582587 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
583588 if err != nil {
584- return err
589+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
585590 }
586591 err = cloud .ValidateExistingDisk (ctx , disk , params ,
587592 int64 (capacityRange .GetRequiredBytes ()),
@@ -593,7 +598,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
593598 klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
594599 return nil
595600 }
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 () )
597602 }
598603 return nil
599604}
@@ -695,7 +700,9 @@ func (cloud *CloudProvider) insertZonalDisk(
695700 if IsGCEError (err , "alreadyExists" ) {
696701 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
697702 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 ())
699706 }
700707 err = cloud .ValidateExistingDisk (ctx , disk , params ,
701708 int64 (capacityRange .GetRequiredBytes ()),
@@ -707,17 +714,20 @@ func (cloud *CloudProvider) insertZonalDisk(
707714 klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
708715 return nil
709716 }
717+ // if the error code is considered "final", Disks.Insert might not be retried
710718 return fmt .Errorf ("unknown Insert disk error: %w" , err )
711719 }
712720 klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
713721
714722 err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
715723
716724 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
717727 if IsGCEError (err , "alreadyExists" ) {
718728 disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
719729 if err != nil {
720- return err
730+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
721731 }
722732 err = cloud .ValidateExistingDisk (ctx , disk , params ,
723733 int64 (capacityRange .GetRequiredBytes ()),
@@ -729,7 +739,7 @@ func (cloud *CloudProvider) insertZonalDisk(
729739 klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
730740 return nil
731741 }
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 () )
733743 }
734744 return nil
735745}
0 commit comments