Skip to content

Commit 71740c6

Browse files
authored
Merge pull request #2344 from umagnus/modify-volume
feat: Implement KEP3751 ("ControllerModifyVolume")
2 parents bc01df4 + 63a446f commit 71740c6

19 files changed

+645
-14
lines changed
17 Bytes
Binary file not shown.

charts/latest/azuredisk-csi-driver/templates/rbac-csi-azuredisk-controller.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ rules:
7272
- apiGroups: ["storage.k8s.io"]
7373
resources: ["volumeattachments/status"]
7474
verbs: ["get", "list", "watch", "update", "patch"]
75+
- apiGroups: ["storage.k8s.io"]
76+
resources: ["volumeattributesclasses"]
77+
verbs: ["get"]
7578
- apiGroups: ["coordination.k8s.io"]
7679
resources: ["leases"]
7780
verbs: ["get", "watch", "list", "delete", "update", "create", "patch"]
@@ -158,6 +161,9 @@ rules:
158161
- apiGroups: [""]
159162
resources: ["pods"]
160163
verbs: ["get", "list", "watch"]
164+
- apiGroups: ["storage.k8s.io"]
165+
resources: ["volumeattributesclasses"]
166+
verbs: ["get", "list", "watch"]
161167
---
162168
kind: ClusterRoleBinding
163169
apiVersion: rbac.authorization.k8s.io/v1
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Volume Modification
2+
## Prerequisites
3+
Volume modification only work on a cluster with the `VolumeAttributesClass` feature enabled. To use this feature, it should:
4+
- `VolumeAttributesClass` feature gate on `kube-apiserver` (consult your Kubernetes distro's documentation)
5+
- `storage.k8s.io/v1alpha1` enabled in `kube-apiserver` via [`runtime-config`](https://kubernetes.io/docs/tasks/administer-cluster/enable-disable-api/) (consult your Kubernetes distro's documentation)
6+
- `VolumeAttributesClass` feature gate on `kube-controller-manager` (consult your Kubernetes distro's documentation)
7+
- `VolumeAttributesClass` feature gate on `csi-provisioner` container in csi-azuredisk-controller
8+
- `VolumeAttributesClass` feature gate on `csi-resizer` container in csi-azuredisk-controller
9+
10+
For more information, see the [Kubernetes documentation for the feature](https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/).
11+
12+
## Parameters
13+
Users can specify the following modification parameters:
14+
- `skuName`: to update the disk type(skuName is not allowed to change from or to UltraSSD_LRS or PremiumV2_LRS disk type, more details on [Change the disk type of an Azure managed disk](https://learn.microsoft.com/en-us/azure/virtual-machines/disks-convert-types?tabs=azure-powershell))
15+
- `DiskIOPSReadWrite`: to update the IOPS
16+
- `DiskMBpsReadWrite`: to update the throughput
17+
18+
## Usage
19+
20+
### Create an example Pod, PVC and StorageClass
21+
```console
22+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/azuredisk-csi-driver/master/deploy/example/modifyvolume/storageclass-azuredisk-csi-premiumv2.yaml
23+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/azuredisk-csi-driver/master/deploy/example/pvc-azuredisk-csi.yaml
24+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/azuredisk-csi-driver/master/deploy/example/nginx-pod-azuredisk.yaml
25+
```
26+
27+
### Wait for the PVC in Bound state and the pod in Running state
28+
```console
29+
kubectl get pvc pvc-azuredisk
30+
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
31+
pvc-azuredisk Bound pvc-e2a5c302-0b48-49a5-bde7-5c0528c7a06f 10Gi RWO managed-csi <unset> 17m
32+
33+
kubectl get pod nginx-azuredisk
34+
NAME READY STATUS RESTARTS AGE
35+
nginx-azuredisk 1/1 Running 0 20s
36+
```
37+
38+
### Create VolumeAttributesClass
39+
```console
40+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/azuredisk-csi-driver/master/deploy/example/modifyvolume/volumeattributesclass.yaml
41+
kubectl get volumeattributesclass premium2-disk-class
42+
NAME DRIVERNAME AGE
43+
premium2-disk-class disk.csi.azure.com 4s
44+
```
45+
46+
### Edit the PVC to point to the VolumeAttributesClass
47+
```console
48+
kubectl patch pvc pvc-azuredisk --patch '{"spec": {"volumeAttributesClassName": "premium2-disk-class"}}'
49+
```
50+
51+
### Wait for the VolumeAttributesClass to apply to the volume
52+
```console
53+
kubectl get pvc pvc-azuredisk
54+
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE
55+
pvc-azuredisk Bound pvc-e2a5c302-0b48-49a5-bde7-5c0528c7a06f 10Gi RWO managed-csi premium2-disk-class 20m
56+
57+
kubectl describe pvc pvc-azuredisk
58+
Name: pvc-azuredisk
59+
Namespace: default
60+
StorageClass: managed-csi-prev2
61+
Status: Bound
62+
Volume: pvc-e2a5c302-0b48-49a5-bde7-5c0528c7a06f
63+
Labels: <none>
64+
Annotations: pv.kubernetes.io/bind-completed: yes
65+
pv.kubernetes.io/bound-by-controller: yes
66+
volume.beta.kubernetes.io/storage-provisioner: disk.csi.azure.com
67+
volume.kubernetes.io/selected-node: aks-agentpool-17390711-vmss000000
68+
volume.kubernetes.io/storage-provisioner: disk.csi.azure.com
69+
Finalizers: [kubernetes.io/pvc-protection]
70+
Capacity: 10Gi
71+
Access Modes: RWO
72+
VolumeMode: Filesystem
73+
Used By: nginx-azuredisk
74+
Events:
75+
Type Reason Age From Message
76+
---- ------ ---- ---- -------
77+
Normal WaitForFirstConsumer 21m persistentvolume-controller waiting for first consumer to be created before binding
78+
Normal Provisioning 21m disk.csi.azure.com_aks-agentpool-17390711-vmss000000_c36f4e97-171f-46c7-ba4a-c8567bb41452 External provisioner is provisioning volume for claim "default/pvc-azuredisk"
79+
Normal ExternalProvisioning 21m (x2 over 21m) persistentvolume-controller Waiting for a volume to be created either by the external provisioner 'disk.csi.azure.com' or manually by the system administrator. If volume creation is delayed, please verify that the provisioner is running and correctly registered.
80+
Normal ProvisioningSucceeded 21m disk.csi.azure.com_aks-agentpool-17390711-vmss000000_c36f4e97-171f-46c7-ba4a-c8567bb41452 Successfully provisioned volume pvc-e2a5c302-0b48-49a5-bde7-5c0528c7a06f
81+
Normal VolumeModify 18s external-resizer disk.csi.azure.com external resizer is modifying volume pvc-azuredisk with vac premium2-disk-class
82+
Normal VolumeModifySuccessful 15s external-resizer disk.csi.azure.com external resizer modified volume pvc-azuredisk with vac premium2-disk-class successfully
83+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
apiVersion: storage.k8s.io/v1
3+
kind: StorageClass
4+
metadata:
5+
name: managed-csi
6+
provisioner: disk.csi.azure.com
7+
parameters:
8+
cachingMode: None
9+
skuName: PremiumV2_LRS
10+
DiskIOPSReadWrite: "4000"
11+
DiskMBpsReadWrite: "1000"
12+
reclaimPolicy: Delete
13+
volumeBindingMode: WaitForFirstConsumer
14+
allowVolumeExpansion: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
apiVersion: storage.k8s.io/v1alpha1
3+
kind: VolumeAttributesClass
4+
metadata:
5+
name: premium2-disk-class
6+
driverName: disk.csi.azure.com
7+
parameters:
8+
DiskIOPSReadWrite: "5000"
9+
DiskMBpsReadWrite: "1200"

deploy/rbac-csi-azuredisk-controller.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ rules:
7575
- apiGroups: ["storage.k8s.io"]
7676
resources: ["volumeattachments/status"]
7777
verbs: ["get", "list", "watch", "update", "patch"]
78+
- apiGroups: ["storage.k8s.io"]
79+
resources: ["volumeattributesclasses"]
80+
verbs: ["get"]
7881
- apiGroups: ["coordination.k8s.io"]
7982
resources: ["leases"]
8083
verbs: ["get", "watch", "list", "delete", "update", "create", "patch"]
@@ -157,6 +160,9 @@ rules:
157160
- apiGroups: [""]
158161
resources: ["pods"]
159162
verbs: ["get", "list", "watch"]
163+
- apiGroups: ["storage.k8s.io"]
164+
resources: ["volumeattributesclasses"]
165+
verbs: ["get", "list", "watch"]
160166
---
161167
kind: ClusterRoleBinding
162168
apiVersion: rbac.authorization.k8s.io/v1

hack/verify-yamllint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if [[ "${deployDirNum}" != "${helmDirNum}" ]]; then
2929
exit 1
3030
fi
3131

32-
for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/metrics/*.yaml" "deploy/example/snapshot/*.yaml" "deploy/example/cloning/*.yaml" "deploy/example/rawblock/*.yaml" "deploy/example/windows/*.yaml" "deploy/example/sharedisk/*.yaml" "docs/known-issues/node-shutdown-recovery/*.yaml"
32+
for path in "deploy/*.yaml" "deploy/example/*.yaml" "deploy/example/metrics/*.yaml" "deploy/example/snapshot/*.yaml" "deploy/example/cloning/*.yaml" "deploy/example/rawblock/*.yaml" "deploy/example/windows/*.yaml" "deploy/example/sharedisk/*.yaml" "deploy/example/modifyvolume/*.yaml" "docs/known-issues/node-shutdown-recovery/*.yaml"
3333
do
3434
echo "checking yamllint under path: $path ..."
3535
yamllint -f parsable $path | grep -v "line too long" > $LOG

pkg/azuredisk/azure_managedDiskController.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,79 @@ func (c *ManagedDiskController) ResizeDisk(ctx context.Context, diskURI string,
414414
return newSizeQuant, nil
415415
}
416416

417+
// ModifyDisk: modify disk
418+
func (c *ManagedDiskController) ModifyDisk(ctx context.Context, options *ManagedDiskOptions) error {
419+
klog.V(4).Infof("azureDisk - modifying managed Name:%s, StorageAccountType:%s, DiskIOPSReadWrite:%s, DiskMBpsReadWrite:%s", options.DiskName, options.StorageAccountType, options.DiskIOPSReadWrite, options.DiskMBpsReadWrite)
420+
421+
rg, subsID, err := getInfoFromDiskURI(options.SourceResourceID)
422+
if err != nil {
423+
return err
424+
}
425+
426+
diskClient, err := c.clientFactory.GetDiskClientForSub(subsID)
427+
if err != nil {
428+
return err
429+
}
430+
431+
model := armcompute.DiskUpdate{}
432+
result, err := diskClient.Get(ctx, rg, options.DiskName)
433+
if err != nil {
434+
return err
435+
}
436+
437+
if result.Properties == nil || result.SKU == nil || result.SKU.Name == nil {
438+
return fmt.Errorf("DiskProperties or SKU of disk(%s) is nil", options.DiskName)
439+
}
440+
441+
diskSku := *result.SKU.Name
442+
if options.StorageAccountType != "" && options.StorageAccountType != diskSku {
443+
diskSku = options.StorageAccountType
444+
model.SKU = &armcompute.DiskSKU{
445+
Name: to.Ptr(diskSku),
446+
}
447+
}
448+
449+
diskProperties := armcompute.DiskUpdateProperties{}
450+
451+
if diskSku == armcompute.DiskStorageAccountTypesUltraSSDLRS || diskSku == armcompute.DiskStorageAccountTypesPremiumV2LRS {
452+
if options.DiskIOPSReadWrite != "" {
453+
v, err := strconv.Atoi(options.DiskIOPSReadWrite)
454+
if err != nil {
455+
return fmt.Errorf("AzureDisk - failed to parse DiskIOPSReadWrite: %w", err)
456+
}
457+
diskIOPSReadWrite := int64(v)
458+
diskProperties.DiskIOPSReadWrite = pointer.Int64(diskIOPSReadWrite)
459+
}
460+
461+
if options.DiskMBpsReadWrite != "" {
462+
v, err := strconv.Atoi(options.DiskMBpsReadWrite)
463+
if err != nil {
464+
return fmt.Errorf("AzureDisk - failed to parse DiskMBpsReadWrite: %w", err)
465+
}
466+
diskMBpsReadWrite := int64(v)
467+
diskProperties.DiskMBpsReadWrite = pointer.Int64(diskMBpsReadWrite)
468+
}
469+
470+
model.Properties = &diskProperties
471+
} else {
472+
if options.DiskIOPSReadWrite != "" {
473+
return fmt.Errorf("AzureDisk - DiskIOPSReadWrite parameter is only applicable in UltraSSD_LRS or PremiumV2_LRS disk type")
474+
}
475+
if options.DiskMBpsReadWrite != "" {
476+
return fmt.Errorf("AzureDisk - DiskMBpsReadWrite parameter is only applicable in UltraSSD_LRS or PremiumV2_LRS disk type")
477+
}
478+
}
479+
480+
if model.SKU != nil || model.Properties != nil {
481+
if _, err := diskClient.Patch(ctx, rg, options.DiskName, model); err != nil {
482+
return err
483+
}
484+
} else {
485+
klog.V(4).Infof("azureDisk - no modification needed for disk(%s)", options.DiskName)
486+
}
487+
return nil
488+
}
489+
417490
// get resource group name, subs id from a managed disk URI, e.g. return {group-name}, {sub-id} according to
418491
// /subscriptions/{sub-id}/resourcegroups/{group-name}/providers/microsoft.compute/disks/{disk-id}
419492
// according to https://docs.microsoft.com/en-us/rest/api/compute/disks/get

0 commit comments

Comments
 (0)