Skip to content

Commit

Permalink
skip resize less than 1MB
Browse files Browse the repository at this point in the history
  • Loading branch information
divyenpatel committed Jan 28, 2022
1 parent 184a7ae commit 8b6df23
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
19 changes: 19 additions & 0 deletions integrationtests/volume_v2alpha1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ func v2alpha1VolumeTests(t *testing.T) {
t.Fatalf("VolumeSize reported should be greater than the old size, it is %v", volumeStatsResponse.TotalBytes)
}

// extending volume less than 10 MB should be skipped
resizeVolumeRequest = &v2alpha1.ResizeVolumeRequest{
VolumeId: volumeID,
// set new size less than 10 MB
SizeBytes: newVolumeSize + (1024 * 512),
}
_, err = volumeClient.ResizeVolume(context.TODO(), resizeVolumeRequest)
if err != nil {
t.Fatalf("Volume resize request failed. Error: %v", err)
}
volumeStatsResponseAfterResize, err := volumeClient.GetVolumeStats(context.TODO(), volumeStatsRequest)
if err != nil {
t.Fatalf("VolumeStats request after resize error: %v", err)
}
if volumeStatsResponseAfterResize.TotalBytes != volumeStatsResponse.TotalBytes {
t.Fatalf("VolumeSize should not be extended from %d to %d", volumeStatsResponse.TotalBytes,
volumeStatsResponseAfterResize.TotalBytes)
}

volumeDiskNumberRequest := &v2alpha1.GetDiskNumberFromVolumeIDRequest{
VolumeId: volumeID,
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/os/volume/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type VolumeAPI struct{}
// verifies that the API is implemented
var _ API = &VolumeAPI{}

// MinimumExpandSize is the minimum size required to
// expanding the partition
const MinimumExpandSize = 1024 * 1024

// New - Construct a new Volume API Implementation.
func New() VolumeAPI {
return VolumeAPI{}
Expand Down Expand Up @@ -170,18 +174,24 @@ func (VolumeAPI) ResizeVolume(volumeID string, size int64) error {
} else {
finalSize = size
}
klog.V(4).Infof("finalSize for resize of the volume: %s is %d ", volumeID, finalSize)

currentSize, err := getVolumeSize(volumeID)
if err != nil {
return fmt.Errorf("error getting the current size of volume (%s) with error (%v)", volumeID, err)
}

klog.V(4).Infof("currentSize of the volume: %s is %d ", volumeID, currentSize)
//if the partition's size is already the size we want this is a noop, just return
if currentSize >= finalSize {
klog.V(2).Infof("Attempted to resize volume %s to a lower size, from currentBytes=%d wantedBytes=%d", volumeID, currentSize, finalSize)
return nil
}

// Resize-Partition requires minimum extent size 1 MB
// if extent size for resize partition is less than 1 MB, skip expanding volume
if finalSize-currentSize < MinimumExpandSize {
klog.V(2).Infof("minimum extent size is 1 MB. Skip resize for volume %s from currentBytes=%d to wantedBytes=%d ", volumeID, currentSize, finalSize)
return nil
}
cmd = fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-Partition | Resize-Partition -Size %d", volumeID, finalSize)
out, err = runExec(cmd)
if err != nil {
Expand Down

0 comments on commit 8b6df23

Please sign in to comment.