From 71ec102185886cb001b24db44e4d6048ecd28b7a Mon Sep 17 00:00:00 2001 From: Eddie Torres Date: Wed, 8 Nov 2023 15:43:11 +0000 Subject: [PATCH] Do not return an error if volume is optimizing in validateModifyVolume Signed-off-by: Eddie Torres --- pkg/cloud/cloud.go | 27 +-------------------------- pkg/cloud/cloud_test.go | 20 -------------------- 2 files changed, 1 insertion(+), 46 deletions(-) diff --git a/pkg/cloud/cloud.go b/pkg/cloud/cloud.go index 56905f587e..b16620c824 100644 --- a/pkg/cloud/cloud.go +++ b/pkg/cloud/cloud.go @@ -1276,38 +1276,13 @@ func (c *cloud) validateModifyVolume(ctx context.Context, volumeID string, newSi return true, 0, err } - oldSizeGiB := aws.Int64Value(volume.Size) - - latestMod, err := c.getLatestVolumeModification(ctx, volumeID) - if err != nil && !errors.Is(err, VolumeNotBeingModified) { - return true, oldSizeGiB, fmt.Errorf("error fetching volume modifications for %q: %w", volumeID, err) - } - - // latestMod can be nil if the volume has never been modified - if latestMod != nil { - state := aws.StringValue(latestMod.ModificationState) - if state == ec2.VolumeModificationStateModifying { - // If volume is already modifying, detour to waiting for it to modify - klog.V(5).InfoS("[Debug] Watching ongoing modification", "volumeID", volumeID) - err = c.waitForVolumeModification(ctx, volumeID) - if err != nil { - return true, oldSizeGiB, err - } - returnGiB, returnErr := c.checkDesiredState(ctx, volumeID, newSizeGiB, options) - return false, returnGiB, returnErr - } else if state == ec2.VolumeModificationStateOptimizing { - return true, 0, fmt.Errorf("volume %q in OPTIMIZING state, cannot currently modify", volumeID) - } - } - - // At this point, we know we are starting a new volume modification - // If we're asked to modify a volume to its current state, ignore the request and immediately return a success if !needsVolumeModification(volume, newSizeGiB, options) { klog.V(5).InfoS("[Debug] Skipping modification for volume due to matching stats", "volumeID", volumeID) // Wait for any existing modifications to prevent race conditions where DescribeVolume(s) returns the new // state before the volume is actually finished modifying err = c.waitForVolumeModification(ctx, volumeID) if err != nil { + oldSizeGiB := aws.Int64Value(volume.Size) return true, oldSizeGiB, err } returnGiB, returnErr := c.checkDesiredState(ctx, volumeID, newSizeGiB, options) diff --git a/pkg/cloud/cloud_test.go b/pkg/cloud/cloud_test.go index 3a2c7ad6e0..298a4838c5 100644 --- a/pkg/cloud/cloud_test.go +++ b/pkg/cloud/cloud_test.go @@ -1564,26 +1564,6 @@ func TestResizeOrModifyDisk(t *testing.T) { reqSizeGiB: 2, expErr: fmt.Errorf("ResizeDisk generic error"), }, - { - name: "failure: volume in modifying state", - volumeID: "vol-test", - existingVolume: &ec2.Volume{ - VolumeId: aws.String("vol-test"), - Size: aws.Int64(1), - AvailabilityZone: aws.String(defaultZone), - }, - descModVolume: &ec2.DescribeVolumesModificationsOutput{ - VolumesModifications: []*ec2.VolumeModification{ - { - VolumeId: aws.String("vol-test"), - TargetSize: aws.Int64(2), - ModificationState: aws.String(ec2.VolumeModificationStateModifying), - }, - }, - }, - reqSizeGiB: 2, - expErr: fmt.Errorf("ResizeDisk generic error"), - }, { name: "failure: ModifyVolume returned generic error", volumeID: "vol-test",