Skip to content

Commit de81f37

Browse files
committed
feat: add volume resize support
fix fix fix
1 parent c5f0687 commit de81f37

14 files changed

+335
-29
lines changed

charts/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
7777
| `controller.workingMountDir` | working directory for provisioner to mount smb shares temporarily | `/tmp` |
7878
| `controller.runOnMaster` | run controller on master node | `false` |
7979
| `controller.runOnControlPlane` | run controller on control plane node | `false` |
80-
| `controller.resources.csiProvisioner.limits.memory` | csi-provisioner memory limits | `100Mi` |
80+
| `controller.resources.csiProvisioner.limits.memory` | csi-provisioner memory limits | `400Mi` |
8181
| `controller.resources.csiProvisioner.requests.cpu` | csi-provisioner cpu requests limits | `10m` |
8282
| `controller.resources.csiProvisioner.requests.memory` | csi-provisioner memory requests limits | `20Mi` |
8383
| `controller.resources.livenessProbe.limits.memory` | liveness-probe memory limits | `300Mi` |
@@ -86,7 +86,7 @@ The following table lists the configurable parameters of the latest SMB CSI Driv
8686
| `controller.resources.smb.limits.memory` | smb-csi-driver memory limits | `200Mi` |
8787
| `controller.resources.smb.requests.cpu` | smb-csi-driver cpu requests limits | `10m` |
8888
| `controller.resources.smb.requests.memory` | smb-csi-driver memory requests limits | `20Mi` |
89-
| `controller.resources.csiResizer.limits.memory` | csi-resizer memory limits | `300Mi` |
89+
| `controller.resources.csiResizer.limits.memory` | csi-resizer memory limits | `400Mi` |
9090
| `controller.resources.csiResizer.requests.cpu` | csi-resizer cpu requests limits | `10m` |
9191
| `controller.resources.csiResizer.requests.memory` | csi-resizer memory requests limits | `20Mi` |
9292
| `controller.affinity` | controller pod affinity | `{}` |
151 Bytes
Binary file not shown.

charts/latest/csi-driver-smb/templates/csi-smb-controller.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ spec:
7878
capabilities:
7979
drop:
8080
- ALL
81+
- name: csi-resizer
82+
{{- if hasPrefix "/" .Values.image.csiResizer.repository }}
83+
image: "{{ .Values.image.baseRepo }}{{ .Values.image.csiResizer.repository }}:{{ .Values.image.csiResizer.tag }}"
84+
{{- else }}
85+
image: "{{ .Values.image.csiResizer.repository }}:{{ .Values.image.csiResizer.tag }}"
86+
{{- end }}
87+
args:
88+
- "-csi-address=$(ADDRESS)"
89+
- "-v=2"
90+
- "-leader-election"
91+
- "--leader-election-namespace={{ .Release.Namespace }}"
92+
- '-handle-volume-inuse-error=false'
93+
env:
94+
- name: ADDRESS
95+
value: /csi/csi.sock
96+
imagePullPolicy: {{ .Values.image.csiResizer.pullPolicy }}
97+
volumeMounts:
98+
- name: socket-dir
99+
mountPath: /csi
100+
resources: {{- toYaml .Values.controller.resources.csiResizer | nindent 12 }}
101+
securityContext:
102+
capabilities:
103+
drop:
104+
- ALL
81105
- name: liveness-probe
82106
{{- if hasPrefix "/" .Values.image.livenessProbe.repository }}
83107
image: "{{ .Values.image.baseRepo }}{{ .Values.image.livenessProbe.repository }}:{{ .Values.image.livenessProbe.tag }}"

charts/latest/csi-driver-smb/templates/rbac-csi-smb.yaml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ rules:
4848
resources: ["secrets"]
4949
verbs: ["get"]
5050
---
51-
5251
kind: ClusterRoleBinding
5352
apiVersion: rbac.authorization.k8s.io/v1
5453
metadata:
@@ -62,4 +61,40 @@ roleRef:
6261
kind: ClusterRole
6362
name: {{ .Values.rbac.name }}-external-provisioner-role
6463
apiGroup: rbac.authorization.k8s.io
64+
---
65+
kind: ClusterRole
66+
apiVersion: rbac.authorization.k8s.io/v1
67+
metadata:
68+
name: {{ .Values.rbac.name }}-external-resizer-role
69+
{{ include "smb.labels" . | indent 2 }}
70+
rules:
71+
- apiGroups: [""]
72+
resources: ["persistentvolumes"]
73+
verbs: ["get", "list", "watch", "update", "patch"]
74+
- apiGroups: [""]
75+
resources: ["persistentvolumeclaims"]
76+
verbs: ["get", "list", "watch"]
77+
- apiGroups: [""]
78+
resources: ["persistentvolumeclaims/status"]
79+
verbs: ["update", "patch"]
80+
- apiGroups: [""]
81+
resources: ["events"]
82+
verbs: ["list", "watch", "create", "update", "patch"]
83+
- apiGroups: ["coordination.k8s.io"]
84+
resources: ["leases"]
85+
verbs: ["get", "list", "watch", "create", "update", "patch"]
86+
---
87+
kind: ClusterRoleBinding
88+
apiVersion: rbac.authorization.k8s.io/v1
89+
metadata:
90+
name: {{ .Values.rbac.name }}-csi-resizer-role
91+
{{ include "smb.labels" . | indent 2 }}
92+
subjects:
93+
- kind: ServiceAccount
94+
name: {{ .Values.serviceAccount.controller }}
95+
namespace: {{ .Release.Namespace }}
96+
roleRef:
97+
kind: ClusterRole
98+
name: {{ .Values.rbac.name }}-external-resizer-role
99+
apiGroup: rbac.authorization.k8s.io
65100
{{ end }}

charts/latest/csi-driver-smb/values.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ image:
88
repository: /csi-provisioner
99
tag: v5.1.0
1010
pullPolicy: IfNotPresent
11+
csiResizer:
12+
repository: registry.k8s.io/sig-storage/csi-resizer
13+
tag: v1.12.0
14+
pullPolicy: IfNotPresent
1115
livenessProbe:
1216
repository: /livenessprobe
1317
tag: v2.14.0
@@ -50,7 +54,13 @@ controller:
5054
resources:
5155
csiProvisioner:
5256
limits:
53-
memory: 300Mi
57+
memory: 400Mi
58+
requests:
59+
cpu: 10m
60+
memory: 20Mi
61+
csiResizer:
62+
limits:
63+
memory: 400Mi
5464
requests:
5565
cpu: 10m
5666
memory: 20Mi

deploy/csi-smb-controller.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,31 @@ spec:
5555
resources:
5656
limits:
5757
cpu: 1
58-
memory: 300Mi
58+
memory: 400Mi
59+
requests:
60+
cpu: 10m
61+
memory: 20Mi
62+
securityContext:
63+
capabilities:
64+
drop:
65+
- ALL
66+
- name: csi-resizer
67+
image: registry.k8s.io/sig-storage/csi-resizer:v1.12.0
68+
args:
69+
- "-csi-address=$(ADDRESS)"
70+
- "-v=2"
71+
- "-leader-election"
72+
- "--leader-election-namespace=kube-system"
73+
- '-handle-volume-inuse-error=false'
74+
env:
75+
- name: ADDRESS
76+
value: /csi/csi.sock
77+
volumeMounts:
78+
- name: socket-dir
79+
mountPath: /csi
80+
resources:
81+
limits:
82+
memory: 400Mi
5983
requests:
6084
cpu: 10m
6185
memory: 20Mi

deploy/rbac-csi-smb.yaml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ rules:
4141
resources: ["secrets"]
4242
verbs: ["get"]
4343
---
44-
4544
kind: ClusterRoleBinding
4645
apiVersion: rbac.authorization.k8s.io/v1
4746
metadata:
@@ -54,3 +53,37 @@ roleRef:
5453
kind: ClusterRole
5554
name: smb-external-provisioner-role
5655
apiGroup: rbac.authorization.k8s.io
56+
---
57+
kind: ClusterRole
58+
apiVersion: rbac.authorization.k8s.io/v1
59+
metadata:
60+
name: smb-external-resizer-role
61+
rules:
62+
- apiGroups: [""]
63+
resources: ["persistentvolumes"]
64+
verbs: ["get", "list", "watch", "update", "patch"]
65+
- apiGroups: [""]
66+
resources: ["persistentvolumeclaims"]
67+
verbs: ["get", "list", "watch"]
68+
- apiGroups: [""]
69+
resources: ["persistentvolumeclaims/status"]
70+
verbs: ["update", "patch"]
71+
- apiGroups: [""]
72+
resources: ["events"]
73+
verbs: ["list", "watch", "create", "update", "patch"]
74+
- apiGroups: ["coordination.k8s.io"]
75+
resources: ["leases"]
76+
verbs: ["get", "list", "watch", "create", "update", "patch"]
77+
---
78+
kind: ClusterRoleBinding
79+
apiVersion: rbac.authorization.k8s.io/v1
80+
metadata:
81+
name: smb-csi-resizer-role
82+
subjects:
83+
- kind: ServiceAccount
84+
name: csi-smb-controller-sa
85+
namespace: kube-system
86+
roleRef:
87+
kind: ClusterRole
88+
name: smb-external-resizer-role
89+
apiGroup: rbac.authorization.k8s.io

hack/verify-helm-chart.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ pip install yq --break-system-packages --ignore-installed PyYAML
6262

6363
# Extract images from csi-smb-controller.yaml
6464
expected_csi_provisioner_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[0].image | head -n 1)"
65-
expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
66-
expected_smb_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
65+
expected_csi_resizer_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[1].image | head -n 1)"
66+
expected_liveness_probe_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[2].image | head -n 1)"
67+
expected_smb_image="$(cat ${PKG_ROOT}/deploy/csi-smb-controller.yaml | yq -r .spec.template.spec.containers[3].image | head -n 1)"
6768

6869
csi_provisioner_image="$(get_image_from_helm_chart "csiProvisioner")"
6970
validate_image "${expected_csi_provisioner_image}" "${csi_provisioner_image}"

pkg/smb/controllerserver.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,19 @@ func (d *Driver) ListVolumes(_ context.Context, _ *csi.ListVolumesRequest) (*csi
308308
}
309309

310310
// ControllerExpandVolume expand volume
311-
func (d *Driver) ControllerExpandVolume(_ context.Context, _ *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
312-
return nil, status.Error(codes.Unimplemented, "")
311+
func (d *Driver) ControllerExpandVolume(_ context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
312+
if len(req.GetVolumeId()) == 0 {
313+
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
314+
}
315+
316+
if req.GetCapacityRange() == nil {
317+
return nil, status.Error(codes.InvalidArgument, "Capacity Range missing in request")
318+
}
319+
320+
volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes())
321+
klog.V(2).Infof("ControllerExpandVolume(%s) successfully, currentQuota: %d bytes", req.VolumeId, volSizeBytes)
322+
323+
return &csi.ControllerExpandVolumeResponse{CapacityBytes: req.GetCapacityRange().GetRequiredBytes()}, nil
313324
}
314325

315326
func (d *Driver) CreateSnapshot(_ context.Context, _ *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {

pkg/smb/controllerserver_test.go

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,11 +398,54 @@ func TestListVolumes(t *testing.T) {
398398

399399
func TestControllerExpandVolume(t *testing.T) {
400400
d := NewFakeDriver()
401-
req := csi.ControllerExpandVolumeRequest{}
402-
resp, err := d.ControllerExpandVolume(context.Background(), &req)
403-
assert.Nil(t, resp)
404-
if !reflect.DeepEqual(err, status.Error(codes.Unimplemented, "")) {
405-
t.Errorf("Unexpected error: %v", err)
401+
402+
testCases := []struct {
403+
name string
404+
testFunc func(t *testing.T)
405+
}{
406+
{
407+
name: "volume ID missing",
408+
testFunc: func(t *testing.T) {
409+
req := &csi.ControllerExpandVolumeRequest{}
410+
_, err := d.ControllerExpandVolume(context.Background(), req)
411+
expectedErr := status.Error(codes.InvalidArgument, "Volume ID missing in request")
412+
if !reflect.DeepEqual(err, expectedErr) {
413+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
414+
}
415+
},
416+
},
417+
{
418+
name: "Capacity Range missing",
419+
testFunc: func(t *testing.T) {
420+
req := &csi.ControllerExpandVolumeRequest{
421+
VolumeId: "unit-test",
422+
}
423+
_, err := d.ControllerExpandVolume(context.Background(), req)
424+
expectedErr := status.Error(codes.InvalidArgument, "Capacity Range missing in request")
425+
if !reflect.DeepEqual(err, expectedErr) {
426+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
427+
}
428+
},
429+
},
430+
{
431+
name: "Error = nil",
432+
testFunc: func(t *testing.T) {
433+
req := &csi.ControllerExpandVolumeRequest{
434+
VolumeId: "unit-test",
435+
CapacityRange: &csi.CapacityRange{
436+
RequiredBytes: 10000,
437+
},
438+
}
439+
_, err := d.ControllerExpandVolume(context.Background(), req)
440+
if !reflect.DeepEqual(err, nil) {
441+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, nil)
442+
}
443+
},
444+
},
445+
}
446+
447+
for _, tc := range testCases {
448+
t.Run(tc.name, tc.testFunc)
406449
}
407450
}
408451

pkg/smb/smb.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func (d *Driver) Run(endpoint, _ string, testMode bool) {
157157
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
158158
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
159159
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
160+
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
160161
})
161162

162163
d.AddVolumeCapabilityAccessModes([]csi.VolumeCapability_AccessMode_Mode{

0 commit comments

Comments
 (0)