Skip to content

Commit

Permalink
allow resizing to min required size for performance plus disks
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBednar committed Aug 30, 2023
1 parent 2b1b55e commit 2ed798d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 72 deletions.
145 changes: 73 additions & 72 deletions pkg/azureconstants/azure_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,78 +21,79 @@ import (
)

const (
AzureDiskCSIDriverName = "azuredisk_csi_driver"
CachingModeField = "cachingmode"
DefaultAzureCredentialFileEnv = "AZURE_CREDENTIAL_FILE"
DefaultCredFilePathLinux = "/etc/kubernetes/azure.json"
DefaultCredFilePathWindows = "C:\\k\\azure.json"
DefaultDriverName = "disk.csi.azure.com"
DesIDField = "diskencryptionsetid"
DiskEncryptionTypeField = "diskencryptiontype"
DiskAccessIDField = "diskaccessid"
DiskIOPSReadWriteField = "diskiopsreadwrite"
DiskMBPSReadWriteField = "diskmbpsreadwrite"
DiskNameField = "diskname"
EnableBurstingField = "enablebursting"
ErrDiskNotFound = "not found"
FsTypeField = "fstype"
IncrementalField = "incremental"
KindField = "kind"
LocationField = "location"
LogicalSectorSizeField = "logicalsectorsize"
LUN = "LUN"
MaxSharesField = "maxshares"
MinimumDiskSizeGiB = 1
NetworkAccessPolicyField = "networkaccesspolicy"
PublicNetworkAccessField = "publicnetworkaccess"
NotFound = "NotFound"
PerfProfileBasic = "basic"
PerfProfileAdvanced = "advanced"
PerfProfileField = "perfprofile"
PerfProfileNone = "none"
PremiumAccountPrefix = "premium"
PvcNameKey = "csi.storage.k8s.io/pvc/name"
PvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
PvcNamespaceTag = "kubernetes.io-created-for-pvc-namespace"
PvcNameTag = "kubernetes.io-created-for-pvc-name"
PvNameKey = "csi.storage.k8s.io/pv/name"
PvNameTag = "kubernetes.io-created-for-pv-name"
RateLimited = "rate limited"
RequestedSizeGib = "requestedsizegib"
ResizeRequired = "resizeRequired"
SubscriptionIDField = "subscriptionid"
ResourceGroupField = "resourcegroup"
DataAccessAuthModeField = "dataaccessauthmode"
ResourceNotFound = "ResourceNotFound"
SkuNameField = "skuname"
SourceDiskSearchMaxDepth = 10
SourceSnapshot = "snapshot"
SourceVolume = "volume"
StandardSsdAccountPrefix = "standardssd"
StorageAccountTypeField = "storageaccounttype"
TagsField = "tags"
ThrottlingKey = "throttlingKey"
TrueValue = "true"
FalseValue = "false"
UserAgentField = "useragent"
VolumeAttributePartition = "partition"
WellKnownTopologyKey = "topology.kubernetes.io/zone"
InstanceTypeKey = "node.kubernetes.io/instance-type"
WriteAcceleratorEnabled = "writeacceleratorenabled"
ZonedField = "zoned"
EnableAsyncAttachField = "enableasyncattach"
PerformancePlusField = "enableperformanceplus"
AttachDiskInitialDelayField = "attachdiskinitialdelay"
TooManyRequests = "TooManyRequests"
ClientThrottled = "client throttled"
VolumeID = "volumeid"
Node = "node"
SourceResourceID = "source_resource_id"
SnapshotName = "snapshot_name"
SnapshotID = "snapshot_id"
DeviceSettingsKeyPrefix = "device-setting/"
BlockDeviceRootPathLinux = "/sys/block"
DummyBlockDevicePathLinux = "/sys/block/sda"
AzureDiskCSIDriverName = "azuredisk_csi_driver"
CachingModeField = "cachingmode"
DefaultAzureCredentialFileEnv = "AZURE_CREDENTIAL_FILE"
DefaultCredFilePathLinux = "/etc/kubernetes/azure.json"
DefaultCredFilePathWindows = "C:\\k\\azure.json"
DefaultDriverName = "disk.csi.azure.com"
DesIDField = "diskencryptionsetid"
DiskEncryptionTypeField = "diskencryptiontype"
DiskAccessIDField = "diskaccessid"
DiskIOPSReadWriteField = "diskiopsreadwrite"
DiskMBPSReadWriteField = "diskmbpsreadwrite"
DiskNameField = "diskname"
EnableBurstingField = "enablebursting"
ErrDiskNotFound = "not found"
FsTypeField = "fstype"
IncrementalField = "incremental"
KindField = "kind"
LocationField = "location"
LogicalSectorSizeField = "logicalsectorsize"
LUN = "LUN"
MaxSharesField = "maxshares"
MinimumDiskSizeGiB = 1
NetworkAccessPolicyField = "networkaccesspolicy"
PublicNetworkAccessField = "publicnetworkaccess"
NotFound = "NotFound"
PerfProfileBasic = "basic"
PerfProfileAdvanced = "advanced"
PerfProfileField = "perfprofile"
PerfProfileNone = "none"
PremiumAccountPrefix = "premium"
PvcNameKey = "csi.storage.k8s.io/pvc/name"
PvcNamespaceKey = "csi.storage.k8s.io/pvc/namespace"
PvcNamespaceTag = "kubernetes.io-created-for-pvc-namespace"
PvcNameTag = "kubernetes.io-created-for-pvc-name"
PvNameKey = "csi.storage.k8s.io/pv/name"
PvNameTag = "kubernetes.io-created-for-pv-name"
RateLimited = "rate limited"
RequestedSizeGib = "requestedsizegib"
ResizeRequired = "resizeRequired"
SubscriptionIDField = "subscriptionid"
ResourceGroupField = "resourcegroup"
DataAccessAuthModeField = "dataaccessauthmode"
ResourceNotFound = "ResourceNotFound"
SkuNameField = "skuname"
SourceDiskSearchMaxDepth = 10
SourceSnapshot = "snapshot"
SourceVolume = "volume"
StandardSsdAccountPrefix = "standardssd"
StorageAccountTypeField = "storageaccounttype"
TagsField = "tags"
ThrottlingKey = "throttlingKey"
TrueValue = "true"
FalseValue = "false"
UserAgentField = "useragent"
VolumeAttributePartition = "partition"
WellKnownTopologyKey = "topology.kubernetes.io/zone"
InstanceTypeKey = "node.kubernetes.io/instance-type"
WriteAcceleratorEnabled = "writeacceleratorenabled"
ZonedField = "zoned"
EnableAsyncAttachField = "enableasyncattach"
PerformancePlusField = "enableperformanceplus"
PerformancePlusMinimumDiskSizeGiB = 513
AttachDiskInitialDelayField = "attachdiskinitialdelay"
TooManyRequests = "TooManyRequests"
ClientThrottled = "client throttled"
VolumeID = "volumeid"
Node = "node"
SourceResourceID = "source_resource_id"
SnapshotName = "snapshot_name"
SnapshotID = "snapshot_id"
DeviceSettingsKeyPrefix = "device-setting/"
BlockDeviceRootPathLinux = "/sys/block"
DummyBlockDevicePathLinux = "/sys/block/sda"
// define different sleep time when hit throttling
SnapshotOpThrottlingSleepSec = 50
)
Expand Down
6 changes: 6 additions & 0 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
capacityBytes := req.GetCapacityRange().GetRequiredBytes()
volSizeBytes := int64(capacityBytes)
requestGiB := int(volumehelper.RoundUpGiB(volSizeBytes))

if diskParams.PerformancePlus != nil && *diskParams.PerformancePlus {
klog.Warningf("using PerformancePlus, increasing requested disk size from %vGiB to %vGiB (minimal size for PerformancePlus feature)", requestGiB, consts.PerformancePlusMinimumDiskSizeGiB)
requestGiB = consts.PerformancePlusMinimumDiskSizeGiB
}
if requestGiB < consts.MinimumDiskSizeGiB {
klog.Infof("increasing requested disk size from %vGiB to %vGiB (minimal disk size)")
requestGiB = consts.MinimumDiskSizeGiB
}

Expand Down
35 changes: 35 additions & 0 deletions pkg/azuredisk/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,41 @@ func TestCreateVolume(t *testing.T) {
}
},
},
{
name: "valid PerformancePlus request, disk resizes to min required size",
testFunc: func(t *testing.T) {
d, _ := NewFakeDriver(t)
stdCapacityRangetest := &csi.CapacityRange{
RequiredBytes: volumehelper.GiBToBytes(10),
LimitBytes: volumehelper.GiBToBytes(514),
}
req := &csi.CreateVolumeRequest{
Name: testVolumeName,
VolumeCapabilities: stdVolumeCapabilities,
CapacityRange: stdCapacityRangetest,
Parameters: map[string]string{consts.PerformancePlusField: "true"},
}
size := int32(volumehelper.BytesToGiB(req.CapacityRange.RequiredBytes))
id := fmt.Sprintf(consts.ManagedDiskPath, "subs", "rg", testVolumeName)
state := "Succeeded"
disk := compute.Disk{
ID: &id,
Name: &testVolumeName,
DiskProperties: &compute.DiskProperties{
DiskSizeGB: &size,
ProvisioningState: &state,
},
}
d.getCloud().DisksClient.(*mockdiskclient.MockInterface).EXPECT().Get(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(disk, nil).AnyTimes()
d.getCloud().DisksClient.(*mockdiskclient.MockInterface).EXPECT().CreateOrUpdate(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
res, err := d.CreateVolume(context.Background(), req)
assert.Equal(t, res.Volume.CapacityBytes, volumehelper.GiBToBytes(consts.PerformancePlusMinimumDiskSizeGiB))
expectedErr := error(nil)
if !reflect.DeepEqual(err, expectedErr) {
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
}
},
},
}
for _, tc := range testCases {
t.Run(tc.name, tc.testFunc)
Expand Down
6 changes: 6 additions & 0 deletions pkg/azuredisk/controllerserver_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ func (d *DriverV2) CreateVolume(ctx context.Context, req *csi.CreateVolumeReques
capacityBytes := req.GetCapacityRange().GetRequiredBytes()
volSizeBytes := int64(capacityBytes)
requestGiB := int(volumehelper.RoundUpGiB(volSizeBytes))

if diskParams.PerformancePlus != nil && *diskParams.PerformancePlus && requestGiB < consts.PerformancePlusMinimumDiskSizeGiB {
klog.Warningf("using PerformancePlus, increasing requested disk size from %vGiB to %vGiB (minimal size for PerformancePlus feature)", requestGiB, consts.PerformancePlusMinimumDiskSizeGiB)
requestGiB = consts.PerformancePlusMinimumDiskSizeGiB
}
if requestGiB < consts.MinimumDiskSizeGiB {
klog.Infof("increasing requested disk size from %vGiB to %vGiB (minimal disk size)")
requestGiB = consts.MinimumDiskSizeGiB
}

Expand Down

0 comments on commit 2ed798d

Please sign in to comment.