Skip to content

Commit f370391

Browse files
authored
Merge pull request #1600 from k8s-infra-cherrypick-robot/cherry-pick-1558-to-release-1.12
[release-1.12] change GetDisk error reporting to temporary in CreateVolume codepath
2 parents 689eda4 + 97feff3 commit f370391

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

pkg/gce-cloud-provider/compute/gce-compute.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -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
}

pkg/gce-pd-csi-driver/controller.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
317317
existingDisk, err := gceCS.CloudProvider.GetDisk(ctx, gceCS.CloudProvider.GetDefaultProject(), volKey, gceAPIVersion)
318318
if err != nil {
319319
if !gce.IsGCEError(err, "notFound") {
320-
return nil, common.LoggedError("CreateVolume, failed to getDisk when validating: ", err)
320+
// failed to GetDisk, however the Disk may already be created, the error code should be non-Final
321+
return nil, common.LoggedError("CreateVolume, failed to getDisk when validating: ", status.Error(codes.Unavailable, err.Error()))
321322
}
322323
}
323324
if err == nil {
@@ -332,10 +333,10 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
332333

333334
ready, err := isDiskReady(existingDisk)
334335
if err != nil {
335-
return nil, common.LoggedError("CreateVolume disk "+volKey.String()+" had error checking ready status: ", err)
336+
return nil, status.Errorf(codes.Aborted, "CreateVolume disk %q had error checking ready status: %v", volKey.String(), err.Error())
336337
}
337338
if !ready {
338-
return nil, status.Errorf(codes.Internal, "CreateVolume existing disk %v is not ready", volKey)
339+
return nil, status.Errorf(codes.Aborted, "CreateVolume existing disk %v is not ready", volKey)
339340
}
340341

341342
// If there is no validation error, immediately return success
@@ -410,10 +411,10 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
410411
// Verify the source disk is ready.
411412
ready, err := isDiskReady(diskFromSourceVolume)
412413
if err != nil {
413-
return nil, common.LoggedError("CreateVolume disk from source volume "+sourceVolKey.String()+" had error checking ready status: ", err)
414+
return nil, status.Errorf(codes.Aborted, "CreateVolume disk from source volume %q had error checking ready status: %v", sourceVolKey.String(), err.Error())
414415
}
415416
if !ready {
416-
return nil, status.Errorf(codes.Internal, "CreateVolume disk from source volume %v is not ready", sourceVolKey)
417+
return nil, status.Errorf(codes.Aborted, "CreateVolume disk from source volume %v is not ready", sourceVolKey)
417418
}
418419
}
419420
} else { // if VolumeContentSource is nil, validate access mode is not read only
@@ -1861,9 +1862,10 @@ func createRegionalDisk(ctx context.Context, cloudProvider gce.GCECompute, name
18611862
if multiWriter {
18621863
gceAPIVersion = gce.GCEAPIVersionBeta
18631864
}
1865+
// failed to GetDisk, however the Disk may already be created, the error code should be non-Final
18641866
disk, err := cloudProvider.GetDisk(ctx, project, meta.RegionalKey(name, region), gceAPIVersion)
18651867
if err != nil {
1866-
return nil, fmt.Errorf("failed to get disk after creating regional disk: %w", err)
1868+
return nil, status.Errorf(codes.Unavailable, "failed to get disk after creating regional disk: %v", err.Error())
18671869
}
18681870
return disk, nil
18691871
}
@@ -1883,9 +1885,10 @@ func createSingleZoneDisk(ctx context.Context, cloudProvider gce.GCECompute, nam
18831885
if multiWriter {
18841886
gceAPIVersion = gce.GCEAPIVersionBeta
18851887
}
1888+
// failed to GetDisk, however the Disk may already be created, the error code should be non-Final
18861889
disk, err := cloudProvider.GetDisk(ctx, project, meta.ZonalKey(name, diskZone), gceAPIVersion)
18871890
if err != nil {
1888-
return nil, err
1891+
return nil, status.Errorf(codes.Unavailable, "failed to get disk after creating zonal disk: %v", err.Error())
18891892
}
18901893
return disk, nil
18911894
}

0 commit comments

Comments
 (0)