@@ -504,7 +504,9 @@ func (cloud *CloudProvider) insertRegionalDisk(
504
504
if IsGCEError (err , "alreadyExists" ) {
505
505
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
506
506
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 ())
508
510
}
509
511
err = cloud .ValidateExistingDisk (ctx , disk , params ,
510
512
int64 (capacityRange .GetRequiredBytes ()),
@@ -516,16 +518,19 @@ func (cloud *CloudProvider) insertRegionalDisk(
516
518
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
517
519
return nil
518
520
}
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 )
520
523
}
521
524
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
522
525
523
526
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
524
529
if err != nil {
525
530
if IsGCEError (err , "alreadyExists" ) {
526
531
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
527
532
if err != nil {
528
- return err
533
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
529
534
}
530
535
err = cloud .ValidateExistingDisk (ctx , disk , params ,
531
536
int64 (capacityRange .GetRequiredBytes ()),
@@ -537,7 +542,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
537
542
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
538
543
return nil
539
544
}
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 () )
541
546
}
542
547
return nil
543
548
}
@@ -616,7 +621,9 @@ func (cloud *CloudProvider) insertZonalDisk(
616
621
if IsGCEError (err , "alreadyExists" ) {
617
622
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
618
623
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 ())
620
627
}
621
628
err = cloud .ValidateExistingDisk (ctx , disk , params ,
622
629
int64 (capacityRange .GetRequiredBytes ()),
@@ -628,17 +635,20 @@ func (cloud *CloudProvider) insertZonalDisk(
628
635
klog .Warningf ("GCE PD %s already exists, reusing" , volKey .Name )
629
636
return nil
630
637
}
638
+ // if the error code is considered "final", Disks.Insert might not be retried
631
639
return fmt .Errorf ("unknown Insert disk error: %w" , err )
632
640
}
633
641
klog .V (5 ).Infof ("InsertDisk operation %s for disk %s" , opName , diskToCreate .Name )
634
642
635
643
err = cloud .waitForZonalOp (ctx , project , opName , volKey .Zone )
636
644
637
645
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
638
648
if IsGCEError (err , "alreadyExists" ) {
639
649
disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
640
650
if err != nil {
641
- return err
651
+ return status . Errorf ( codes . Unavailable , "error when getting disk: %v" , err . Error ())
642
652
}
643
653
err = cloud .ValidateExistingDisk (ctx , disk , params ,
644
654
int64 (capacityRange .GetRequiredBytes ()),
@@ -650,7 +660,7 @@ func (cloud *CloudProvider) insertZonalDisk(
650
660
klog .Warningf ("GCE PD %s already exists after wait, reusing" , volKey .Name )
651
661
return nil
652
662
}
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 () )
654
664
}
655
665
return nil
656
666
}
0 commit comments