Skip to content

Commit 35ed119

Browse files
Normalize GCNV create requests below minimum size
1 parent 75592aa commit 35ed119

4 files changed

Lines changed: 59 additions & 10 deletions

File tree

storage_drivers/gcp/gcp_gcnv.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -779,9 +779,6 @@ func (d *NASStorageDriver) Create(
779779
defaultSize, _ := capacity.ToBytes(pool.InternalAttributes()[Size])
780780
sizeBytes, _ = strconv.ParseUint(defaultSize, 10, 64)
781781
}
782-
if err = drivers.CheckMinVolumeSize(sizeBytes, MinimumVolumeSizeBytes); err != nil {
783-
return err
784-
}
785782

786783
if sizeBytes < minimumGCNVVolumeSizeBytes {
787784

storage_drivers/gcp/gcp_gcnv_san.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,14 @@ func (d *SANStorageDriver) Create(
636636
}
637637

638638
// Ensure the volume size meets minimum requirements
639-
if err = drivers.CheckMinVolumeSize(sizeBytes, MinimumVolumeSizeBytes); err != nil {
640-
return err
639+
if sizeBytes < MinimumVolumeSizeBytes {
640+
Logc(ctx).WithFields(LogFields{
641+
"name": name,
642+
"requestedSize": sizeBytes,
643+
"minimumSize": MinimumVolumeSizeBytes,
644+
}).Warningf("Requested size is too small. Setting volume size to the minimum allowable.")
645+
646+
sizeBytes = MinimumVolumeSizeBytes
641647
}
642648

643649
// NOTE: Snapshot reserve is applied later after parsing; the size checks below use the base size.

storage_drivers/gcp/gcp_gcnv_san_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,41 @@ func TestSANDriver_Create_InvalidSize(t *testing.T) {
16331633
assert.Contains(t, err.Error(), "invalid volume size")
16341634
}
16351635

1636+
func TestSANDriver_Create_BelowMinimumSize(t *testing.T) {
1637+
mockAPI, driver := newMockSANDriver(t)
1638+
1639+
// Request half of MinimumVolumeSizeBytes (512 MiB) — should normalize up, not fail.
1640+
belowMinSize := strconv.FormatUint(MinimumVolumeSizeBytes/2, 10)
1641+
1642+
volConfig := &storage.VolumeConfig{
1643+
Name: testVolumeName,
1644+
InternalName: testVolumeInternalName,
1645+
Size: belowMinSize,
1646+
FileSystem: "ext4",
1647+
}
1648+
1649+
pool := driver.pools["test-pool"]
1650+
1651+
mockAPI.EXPECT().RefreshGCNVResources(ctx).Return(nil).Times(1)
1652+
mockAPI.EXPECT().VolumeExists(ctx, volConfig).Return(false, nil, nil).Times(1)
1653+
mockAPI.EXPECT().CapacityPoolsForStoragePool(ctx, pool, "", drivers.TieringPolicyNone).Return([]*api.CapacityPool{{Name: "test-pool"}}).Times(1)
1654+
mockAPI.EXPECT().FilterCapacityPoolsOnTopology(ctx, gomock.Any(), gomock.Any(), gomock.Any()).Return([]*api.CapacityPool{{Name: "test-pool"}}).Times(1)
1655+
mockAPI.EXPECT().CreateVolume(ctx, gomock.Any()).DoAndReturn(
1656+
func(_ context.Context, req *api.VolumeCreateRequest) (*api.Volume, error) {
1657+
// Size must be >= MinimumVolumeSizeBytes after normalization
1658+
assert.GreaterOrEqual(t, req.SizeBytes, int64(MinimumVolumeSizeBytes), "create request size must be at least minimum")
1659+
v := getTestVolume()
1660+
v.Name = testVolumeName
1661+
v.CreationToken = testVolumeInternalName
1662+
return v, nil
1663+
},
1664+
)
1665+
mockAPI.EXPECT().WaitForVolumeState(ctx, gomock.Any(), api.VolumeStateReady, gomock.Any(), gomock.Any()).Return(api.VolumeStateReady, nil).Times(1)
1666+
1667+
err := driver.Create(ctx, volConfig, pool, nil)
1668+
assert.NoError(t, err, "Create should succeed for sub-minimum size by normalizing up")
1669+
}
1670+
16361671
func TestSANDriver_Create_RefreshError(t *testing.T) {
16371672
mockAPI, driver := newMockSANDriver(t)
16381673

storage_drivers/gcp/gcp_gcnv_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,17 +2255,28 @@ func TestCreate_BelowAbsoluteMinimumSize(t *testing.T) {
22552255

22562256
storagePool := driver.pools["gcnv_pool"]
22572257

2258-
volConfig, _, _, _ := getStructsForCreateNFSVolume(ctx, driver, storagePool)
2259-
volConfig.Size = "1k"
2258+
volConfig, capacityPool, volume, createRequest := getStructsForCreateNFSVolume(ctx, driver, storagePool)
2259+
volConfig.Size = "1024"
2260+
createRequest.UnixPermissions = "0777"
2261+
createRequest.SizeBytes = int64(capacity.OneGiB * 100)
2262+
volume.SizeBytes = int64(capacity.OneGiB * 100)
22602263

22612264
mockAPI.EXPECT().RefreshGCNVResources(ctx).Return(nil).Times(1)
22622265
mockAPI.EXPECT().VolumeExists(ctx, volConfig).Return(false, nil, nil).Times(1)
2266+
mockAPI.EXPECT().CapacityPoolsForStoragePool(ctx, storagePool,
2267+
api.ServiceLevelPremium, gomock.Any()).Return([]*api.CapacityPool{capacityPool}).Times(1)
2268+
mockAPI.EXPECT().FilterCapacityPoolsOnTopology(ctx, []*api.CapacityPool{capacityPool},
2269+
volConfig.RequisiteTopologies, volConfig.PreferredTopologies).Return([]*api.CapacityPool{capacityPool}).Times(1)
2270+
mockAPI.EXPECT().CreateVolume(ctx, createRequest).Return(volume, nil).Times(1)
2271+
mockAPI.EXPECT().WaitForVolumeState(ctx, volume, api.VolumeStateReady, []string{api.VolumeStateError},
2272+
driver.volumeCreateTimeout).Return(api.VolumeStateReady, nil).Times(1)
22632273

22642274
result := driver.Create(ctx, volConfig, storagePool, nil)
2265-
fmt.Println("------", result)
22662275

2267-
assert.Error(t, result, "create failed")
2268-
assert.Equal(t, "", volConfig.InternalID, "internal ID set on volConfig")
2276+
assert.NoError(t, result, "create failed")
2277+
assert.Equal(t, int64(capacity.OneGiB*100), createRequest.SizeBytes, "request size mismatch")
2278+
assert.Equal(t, defaultVolumeSizeStr, volConfig.Size, "config size mismatch")
2279+
assert.Equal(t, volume.FullName, volConfig.InternalID, "internal ID not set on volConfig")
22692280
}
22702281

22712282
func TestCreate_AboveMaximumSize(t *testing.T) {

0 commit comments

Comments
 (0)