Skip to content

Commit

Permalink
update logic to determine resized pv size
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavgaikwad committed May 17, 2021
1 parent 77f00f6 commit 7bfe3d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
5 changes: 3 additions & 2 deletions pkg/controller/miganalytic/volume_adjustment.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,14 @@ func (pva *PersistentVolumeAdjuster) calculateProposedVolumeSize(usagePercentage
reason = migapi.VolumeAdjustmentNoOp

if actualCapacity.Cmp(maxSize) == 1 {
maxSize = actualCapacity
reason = migapi.VolumeAdjustmentCapacityMismatch
}

if volumeSizeWithThreshold.Cmp(maxSize) == 1 {
maxSize = volumeSizeWithThreshold
reason = migapi.VolumeAdjustmentUsageExceeded
if usagePercentage+int64(pva.getVolumeUsagePercentageThreshold()) > 100 {
reason = migapi.VolumeAdjustmentUsageExceeded
}
}

proposedSize = maxSize
Expand Down
13 changes: 6 additions & 7 deletions pkg/controller/miganalytic/volume_adjustment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func TestPersistentVolumeAdjuster_calculateProposedVolumeSize(t *testing.T) {
wantReason string
}{
{
name: "Given values of usagePercentage, actualCapacity and requestedCapacity, appropriate volume size is returned, here proposed size = actual capacity",
name: "Given requested capacity < actual capacity, should return 103% of used capacity of the volume",
fields: fields{
Client: fake.NewFakeClient(),
},
Expand All @@ -270,11 +270,11 @@ func TestPersistentVolumeAdjuster_calculateProposedVolumeSize(t *testing.T) {
actualCapacity: resource.MustParse("200"),
requestedCapacity: resource.MustParse("20"),
},
wantProposedSize: resource.MustParse("200"),
wantProposedSize: resource.MustParse("106"),
wantReason: migapi.VolumeAdjustmentCapacityMismatch,
},
{
name: "Given values of usagePercentage, actualCapacity and requestedCapacity, appropriate proposed volume size is returned, here proposed size = volume with threshold size",
name: "Given volume usage close to 100%, should return 103% of original capacity",
fields: fields{
Client: fake.NewFakeClient(),
},
Expand All @@ -287,7 +287,7 @@ func TestPersistentVolumeAdjuster_calculateProposedVolumeSize(t *testing.T) {
wantReason: migapi.VolumeAdjustmentUsageExceeded,
},
{
name: "Given values of usagePercentage, actualCapacity and requestedCapacity, appropriate proposed volume size is returned, here proposed size = requested capacity",
name: "Given requested capacity > actual capacity, should return requested capacity",
fields: fields{
Client: fake.NewFakeClient(),
},
Expand All @@ -300,8 +300,7 @@ func TestPersistentVolumeAdjuster_calculateProposedVolumeSize(t *testing.T) {
wantReason: migapi.VolumeAdjustmentNoOp,
},
{
name: "Given values of usagePercentage, actualCapacity and requestedCapacity, appropriate volume size is returned, here volumeS size with threshold" +
"is greater than requested capacity and actual capacity is greater than requested capacity",
name: "Given requested capacity < actual capacity, should return actual capacity",
fields: fields{
Client: fake.NewFakeClient(),
},
Expand All @@ -310,7 +309,7 @@ func TestPersistentVolumeAdjuster_calculateProposedVolumeSize(t *testing.T) {
actualCapacity: resource.MustParse("200"),
requestedCapacity: resource.MustParse("150"),
},
wantProposedSize: resource.MustParse("200"),
wantProposedSize: resource.MustParse("150"),
wantReason: migapi.VolumeAdjustmentCapacityMismatch,
},
}
Expand Down

0 comments on commit 7bfe3d0

Please sign in to comment.