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 9994cae02b..427f9b528a 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 { + 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 } diff --git a/pkg/azuredisk/controllerserver_test.go b/pkg/azuredisk/controllerserver_test.go index f6868ffcc0..5a28537d0f 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 3f87ec5940..07ddfa4dd4 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 }