@@ -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}
@@ -627,7 +632,9 @@ func (cloud *CloudProvider) insertZonalDisk(
627632		if  IsGCEError (err , "alreadyExists" ) {
628633			disk , err  :=  cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
629634			if  err  !=  nil  {
630- 				return  err 
635+ 				// failed to GetDisk, however the Disk may already exist 
636+ 				// the error code should be non-Final 
637+ 				return  status .Error (codes .Unavailable , err .Error ())
631638			}
632639			err  =  cloud .ValidateExistingDisk (ctx , disk , params ,
633640				int64 (capacityRange .GetRequiredBytes ()),
@@ -639,17 +646,20 @@ func (cloud *CloudProvider) insertZonalDisk(
639646			klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
640647			return  nil 
641648		}
649+ 		// if the error code is considered "final", Disks.Insert might not be retried 
642650		return  fmt .Errorf ("unknown Insert disk error: %w" , err )
643651	}
644652	klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
645653
646654	err  =  cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
647655
648656	if  err  !=  nil  {
657+ 		// failed to wait for Op to finish, however, the Op possibly is still running as expected 
658+ 		// the error code returned should be non-final 
649659		if  IsGCEError (err , "alreadyExists" ) {
650660			disk , err  :=  cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
651661			if  err  !=  nil  {
652- 				return  err 
662+ 				return  status . Errorf ( codes . Unavailable ,  "error when getting disk: %v" ,  err . Error ()) 
653663			}
654664			err  =  cloud .ValidateExistingDisk (ctx , disk , params ,
655665				int64 (capacityRange .GetRequiredBytes ()),
@@ -661,7 +671,7 @@ func (cloud *CloudProvider) insertZonalDisk(
661671			klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
662672			return  nil 
663673		}
664- 		return  fmt .Errorf ("unknown Insert disk operation error : %w " , err )
674+ 		return  status .Errorf (codes . Unavailable ,  "unknown error when polling the operation : %v " , err . Error () )
665675	}
666676	return  nil 
667677}
0 commit comments