Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,20 @@ func (c *cloud) ResizeDisk(ctx context.Context, volumeID string, newSizeBytes in
return oldSizeGiB, nil
}

latestMod, err := c.getLatestVolumeModification(ctx, volumeID)
// if there are no errors fetching modifications
if err == nil && latestMod != nil {
state := aws.StringValue(latestMod.ModificationState)
targetSize := aws.Int64Value(latestMod.TargetSize)
if (state == ec2.VolumeModificationStateCompleted || state == ec2.VolumeModificationStateOptimizing) && targetSize >= newSizeGiB {
return targetSize, nil
}

if state == ec2.VolumeModificationStateModifying {
return oldSizeGiB, fmt.Errorf("volume %q is still being expanded to size %d", volumeID, targetSize)
}
}

req := &ec2.ModifyVolumeInput{
VolumeId: aws.String(volumeID),
Size: aws.Int64(newSizeGiB),
Expand Down Expand Up @@ -893,10 +907,11 @@ func (c *cloud) ResizeDisk(ctx context.Context, volumeID string, newSizeBytes in

// waitForVolumeSize waits for a volume modification to finish and return its size.
func (c *cloud) waitForVolumeSize(ctx context.Context, volumeID string) (int64, error) {
// the default context is 10s and hence we should reduce this to more reasonable value and let external-resizer retry
backoff := wait.Backoff{
Duration: 1 * time.Second,
Factor: 1.8,
Steps: 20,
Steps: 3,
}

var modVolSizeGiB int64
Expand Down
23 changes: 23 additions & 0 deletions pkg/cloud/cloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,26 @@ func TestResizeDisk(t *testing.T) {
reqSizeGiB: 2,
expErr: nil,
},
{
name: "success: with previous expansion",
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.VolumeModificationStateCompleted),
},
},
},
reqSizeGiB: 2,
expErr: nil,
},
{
name: "fail: volume doesn't exist",
volumeID: "vol-test",
Expand Down Expand Up @@ -707,6 +727,9 @@ func TestResizeDisk(t *testing.T) {
}
if tc.descModVolume != nil {
mockEC2.EXPECT().DescribeVolumesModificationsWithContext(gomock.Eq(ctx), gomock.Any()).Return(tc.descModVolume, nil).AnyTimes()
} else {
emptyOutput := &ec2.DescribeVolumesModificationsOutput{}
mockEC2.EXPECT().DescribeVolumesModificationsWithContext(gomock.Eq(ctx), gomock.Any()).Return(emptyOutput, nil).AnyTimes()
}

newSize, err := c.ResizeDisk(ctx, tc.volumeID, util.GiBToBytes(tc.reqSizeGiB))
Expand Down