Skip to content

Commit

Permalink
Do not return an error if volume is optimizing in validateModifyVolume
Browse files Browse the repository at this point in the history
Signed-off-by: Eddie Torres <[email protected]>
  • Loading branch information
torredil committed Nov 8, 2023
1 parent d071db8 commit 71ec102
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
27 changes: 1 addition & 26 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 71ec102

Please sign in to comment.