From 9f77016f4ae8f748b73208f3c09d674ae4be4a5a Mon Sep 17 00:00:00 2001 From: Roman Bednar Date: Fri, 25 Aug 2023 13:53:48 +0200 Subject: [PATCH] allow resizing to min required size for performance plus disks --- pkg/azureconstants/azure_constants.go | 145 +++++++++++++------------ pkg/azuredisk/controllerserver.go | 6 + pkg/azuredisk/controllerserver_test.go | 35 ++++++ pkg/azuredisk/controllerserver_v2.go | 6 + 4 files changed, 120 insertions(+), 72 deletions(-) diff --git a/pkg/azureconstants/azure_constants.go b/pkg/azureconstants/azure_constants.go index 2237004dff..d1f5632b93 100644 --- a/pkg/azureconstants/azure_constants.go +++ b/pkg/azureconstants/azure_constants.go @@ -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 ) diff --git a/pkg/azuredisk/controllerserver.go b/pkg/azuredisk/controllerserver.go index 8c8499cc4c..e88c71c3c3 100644 --- a/pkg/azuredisk/controllerserver.go +++ b/pkg/azuredisk/controllerserver.go @@ -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 && 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) requestGiB = consts.MinimumDiskSizeGiB } diff --git a/pkg/azuredisk/controllerserver_test.go b/pkg/azuredisk/controllerserver_test.go index e4c08456fb..9d2642b4f5 100644 --- a/pkg/azuredisk/controllerserver_test.go +++ b/pkg/azuredisk/controllerserver_test.go @@ -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) diff --git a/pkg/azuredisk/controllerserver_v2.go b/pkg/azuredisk/controllerserver_v2.go index d477ef578e..c99d41c20d 100644 --- a/pkg/azuredisk/controllerserver_v2.go +++ b/pkg/azuredisk/controllerserver_v2.go @@ -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) requestGiB = consts.MinimumDiskSizeGiB }