Skip to content

Commit c1b73b0

Browse files
committed
Change behavior of repair disks to return not found when disk is not found in any zone, other error when its found itn multiple zones or error getting disk
1 parent f7d55f5 commit c1b73b0

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (cloud *FakeCloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Contex
7575
return volumeKey, nil
7676
}
7777
}
78-
return nil, fmt.Errorf("Couldn't repair unspecified volume information")
78+
return nil, notFoundError()
7979
case meta.Regional:
8080
if volumeKey.Region != common.UnspecifiedValue {
8181
return volumeKey, nil

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func (cloud *CloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Context, v
7272
}
7373
switch volumeKey.Type() {
7474
case meta.Zonal:
75+
foundZone := ""
7576
if volumeKey.Zone == common.UnspecifiedValue {
7677
// list all zones, try to get disk in each zone
7778
zones, err := cloud.ListZones(ctx, region)
@@ -80,13 +81,27 @@ func (cloud *CloudProvider) RepairUnderspecifiedVolumeKey(ctx context.Context, v
8081
}
8182
for _, zone := range zones {
8283
_, err := cloud.getZonalDiskOrError(ctx, zone, volumeKey.Name)
83-
if err == nil {
84-
// If there is no error we have found a disk
85-
volumeKey.Zone = zone
86-
return volumeKey, nil
84+
if err != nil {
85+
if IsGCENotFoundError(err) {
86+
// Couldn't find the disk in this zone so we keep
87+
// looking
88+
continue
89+
}
90+
// There is some miscellaneous error getting disk from zone
91+
// so we return error immediately
92+
return nil, err
8793
}
94+
if len(foundZone) > 0 {
95+
return nil, fmt.Errorf("found disk %s in more than one zone: %s and %s", volumeKey.Name, foundZone, zone)
96+
}
97+
foundZone = zone
98+
}
99+
100+
if len(foundZone) == 0 {
101+
return nil, notFoundError()
88102
}
89-
return nil, fmt.Errorf("volume zone unspecified and unable to find in any of these zones %v", zones)
103+
volumeKey.Zone = foundZone
104+
return volumeKey, nil
90105
}
91106
return volumeKey, nil
92107
case meta.Regional:

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,17 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
226226
if err != nil {
227227
// Cannot find volume associated with this ID because VolumeID is not in
228228
// correct format, this is a success according to the Spec
229-
klog.Warningf("Treating volume as deleted because volume id %s is invalid: %v", volumeID, err)
229+
klog.Warningf("DeleteVolume treating volume as deleted because volume id %s is invalid: %v", volumeID, err)
230230
return &csi.DeleteVolumeResponse{}, nil
231231
}
232232

233233
volKey, err = gceCS.CloudProvider.RepairUnderspecifiedVolumeKey(ctx, volKey)
234234
if err != nil {
235-
klog.Warningf("Treating volume as deleted because cannot find volume %v: %v", volumeID, err)
236-
return &csi.DeleteVolumeResponse{}, nil
235+
if gce.IsGCENotFoundError(err) {
236+
klog.Warningf("DeleteVolume treating volume as deleted because cannot find volume %v: %v", volumeID, err)
237+
return &csi.DeleteVolumeResponse{}, nil
238+
}
239+
return nil, status.Errorf(codes.Internal, "DeleteVolume error repairing underspecified volume key: %v", err)
237240
}
238241

239242
if acquired := gceCS.volumeLocks.TryAcquire(volumeID); !acquired {
@@ -274,7 +277,10 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
274277

275278
volKey, err = gceCS.CloudProvider.RepairUnderspecifiedVolumeKey(ctx, volKey)
276279
if err != nil {
277-
return nil, status.Error(codes.NotFound, fmt.Sprintf("Could not find volume with ID %v: %v", volumeID, err))
280+
if gce.IsGCENotFoundError(err) {
281+
return nil, status.Errorf(codes.NotFound, "ControllerPublishVolume could not find volume with ID %v: %v", volumeID, err)
282+
}
283+
return nil, status.Errorf(codes.Internal, "ControllerPublishVolume error repairing underspecified volume key: %v", err)
278284
}
279285

280286
// Acquires the lock for the volume on that node only, because we need to support the ability

0 commit comments

Comments
 (0)