Skip to content

Commit f7ce93f

Browse files
authored
Merge pull request #811 from andyzhangx/expand-vol
feat: add volume resize support
2 parents 8813b5b + 9211889 commit f7ce93f

14 files changed

+350
-19
lines changed

charts/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ The following table lists the configurable parameters of the latest NFS CSI Driv
7979
| `controller.resources.csiProvisioner.limits.memory` | csi-provisioner memory limits | 100Mi |
8080
| `controller.resources.csiProvisioner.requests.cpu` | csi-provisioner cpu requests limits | 10m |
8181
| `controller.resources.csiProvisioner.requests.memory` | csi-provisioner memory requests limits | 20Mi |
82+
| `controller.resources.csiResizer.limits.memory` | csi-resizer memory limits | 400Mi |
83+
| `controller.resources.csiResizer.requests.cpu` | csi-resizer cpu requests | 10m |
84+
| `controller.resources.csiResizer.requests.memory` | csi-resizer memory requests | 20Mi |
8285
| `controller.resources.livenessProbe.limits.memory` | liveness-probe memory limits | 100Mi |
8386
| `controller.resources.livenessProbe.requests.cpu` | liveness-probe cpu requests limits | 10m |
8487
| `controller.resources.livenessProbe.requests.memory` | liveness-probe memory requests limits | 20Mi |
122 Bytes
Binary file not shown.

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

+24
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,30 @@ spec:
7575
capabilities:
7676
drop:
7777
- ALL
78+
- name: csi-resizer
79+
{{- if hasPrefix "/" .Values.image.csiResizer.repository }}
80+
image: "{{ .Values.image.baseRepo }}{{ .Values.image.csiResizer.repository }}:{{ .Values.image.csiResizer.tag }}"
81+
{{- else }}
82+
image: "{{ .Values.image.csiResizer.repository }}:{{ .Values.image.csiResizer.tag }}"
83+
{{- end }}
84+
args:
85+
- "-csi-address=$(ADDRESS)"
86+
- "-v=2"
87+
- "-leader-election"
88+
- "--leader-election-namespace={{ .Release.Namespace }}"
89+
- '-handle-volume-inuse-error=false'
90+
env:
91+
- name: ADDRESS
92+
value: /csi/csi.sock
93+
imagePullPolicy: {{ .Values.image.csiResizer.pullPolicy }}
94+
volumeMounts:
95+
- name: socket-dir
96+
mountPath: /csi
97+
resources: {{- toYaml .Values.controller.resources.csiResizer | nindent 12 }}
98+
securityContext:
99+
capabilities:
100+
drop:
101+
- ALL
78102
- name: csi-snapshotter
79103
{{- if hasPrefix "/" .Values.image.csiSnapshotter.repository }}
80104
image: "{{ .Values.image.baseRepo }}{{ .Values.image.csiSnapshotter.repository }}:{{ .Values.image.csiSnapshotter.tag }}"

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

+36
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,42 @@ rules:
5757
resources: ["secrets"]
5858
verbs: ["get"]
5959
---
60+
kind: ClusterRole
61+
apiVersion: rbac.authorization.k8s.io/v1
62+
metadata:
63+
name: {{ .Values.rbac.name }}-external-resizer-role
64+
{{ include "nfs.labels" . | indent 2 }}
65+
rules:
66+
- apiGroups: [""]
67+
resources: ["persistentvolumes"]
68+
verbs: ["get", "list", "watch", "update", "patch"]
69+
- apiGroups: [""]
70+
resources: ["persistentvolumeclaims"]
71+
verbs: ["get", "list", "watch"]
72+
- apiGroups: [""]
73+
resources: ["persistentvolumeclaims/status"]
74+
verbs: ["update", "patch"]
75+
- apiGroups: [""]
76+
resources: ["events"]
77+
verbs: ["list", "watch", "create", "update", "patch"]
78+
- apiGroups: ["coordination.k8s.io"]
79+
resources: ["leases"]
80+
verbs: ["get", "list", "watch", "create", "update", "patch"]
81+
---
82+
kind: ClusterRoleBinding
83+
apiVersion: rbac.authorization.k8s.io/v1
84+
metadata:
85+
name: {{ .Values.rbac.name }}-csi-resizer-role
86+
{{ include "nfs.labels" . | indent 2 }}
87+
subjects:
88+
- kind: ServiceAccount
89+
name: {{ .Values.serviceAccount.controller }}
90+
namespace: {{ .Release.Namespace }}
91+
roleRef:
92+
kind: ClusterRole
93+
name: {{ .Values.rbac.name }}-external-resizer-role
94+
apiGroup: rbac.authorization.k8s.io
95+
---
6096
kind: ClusterRoleBinding
6197
apiVersion: rbac.authorization.k8s.io/v1
6298
metadata:

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

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ image:
99
repository: registry.k8s.io/sig-storage/csi-provisioner
1010
tag: v5.1.0
1111
pullPolicy: IfNotPresent
12+
csiResizer:
13+
repository: registry.k8s.io/sig-storage/csi-resizer
14+
tag: v1.12.0
15+
pullPolicy: IfNotPresent
1216
csiSnapshotter:
1317
repository: registry.k8s.io/sig-storage/csi-snapshotter
1418
tag: v8.1.0
@@ -81,6 +85,12 @@ controller:
8185
requests:
8286
cpu: 10m
8387
memory: 20Mi
88+
csiResizer:
89+
limits:
90+
memory: 400Mi
91+
requests:
92+
cpu: 10m
93+
memory: 20Mi
8494
csiSnapshotter:
8595
limits:
8696
memory: 200Mi

deploy/csi-nfs-controller.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ spec:
6363
capabilities:
6464
drop:
6565
- 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
83+
requests:
84+
cpu: 10m
85+
memory: 20Mi
86+
securityContext:
87+
capabilities:
88+
drop:
89+
- ALL
6690
- name: csi-snapshotter
6791
image: registry.k8s.io/sig-storage/csi-snapshotter:v8.1.0
6892
args:

deploy/rbac-csi-nfs.yaml

+36
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,39 @@ roleRef:
6464
kind: ClusterRole
6565
name: nfs-external-provisioner-role
6666
apiGroup: rbac.authorization.k8s.io
67+
---
68+
69+
kind: ClusterRole
70+
apiVersion: rbac.authorization.k8s.io/v1
71+
metadata:
72+
name: nfs-external-resizer-role
73+
rules:
74+
- apiGroups: [""]
75+
resources: ["persistentvolumes"]
76+
verbs: ["get", "list", "watch", "update", "patch"]
77+
- apiGroups: [""]
78+
resources: ["persistentvolumeclaims"]
79+
verbs: ["get", "list", "watch"]
80+
- apiGroups: [""]
81+
resources: ["persistentvolumeclaims/status"]
82+
verbs: ["update", "patch"]
83+
- apiGroups: [""]
84+
resources: ["events"]
85+
verbs: ["list", "watch", "create", "update", "patch"]
86+
- apiGroups: ["coordination.k8s.io"]
87+
resources: ["leases"]
88+
verbs: ["get", "list", "watch", "create", "update", "patch"]
89+
---
90+
91+
kind: ClusterRoleBinding
92+
apiVersion: rbac.authorization.k8s.io/v1
93+
metadata:
94+
name: nfs-csi-resizer-role
95+
subjects:
96+
- kind: ServiceAccount
97+
name: csi-nfs-controller-sa
98+
namespace: kube-system
99+
roleRef:
100+
kind: ClusterRole
101+
name: nfs-external-resizer-role
102+
apiGroup: rbac.authorization.k8s.io

hack/verify-helm-chart.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ pip install yq --ignore-installed PyYAML
6262

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

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

pkg/nfs/controllerserver.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,19 @@ func (cs *ControllerServer) ListSnapshots(_ context.Context, _ *csi.ListSnapshot
476476
return nil, status.Error(codes.Unimplemented, "")
477477
}
478478

479-
func (cs *ControllerServer) ControllerExpandVolume(_ context.Context, _ *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
480-
return nil, status.Error(codes.Unimplemented, "")
479+
func (cs *ControllerServer) ControllerExpandVolume(_ context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
480+
if len(req.GetVolumeId()) == 0 {
481+
return nil, status.Error(codes.InvalidArgument, "Volume ID missing in request")
482+
}
483+
484+
if req.GetCapacityRange() == nil {
485+
return nil, status.Error(codes.InvalidArgument, "Capacity Range missing in request")
486+
}
487+
488+
volSizeBytes := int64(req.GetCapacityRange().GetRequiredBytes())
489+
klog.V(2).Infof("ControllerExpandVolume(%s) successfully, currentQuota: %d bytes", req.VolumeId, volSizeBytes)
490+
491+
return &csi.ControllerExpandVolumeResponse{CapacityBytes: req.GetCapacityRange().GetRequiredBytes()}, nil
481492
}
482493

483494
// Mount nfs server at base-dir

pkg/nfs/controllerserver_test.go

+61
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ func TestControllerGetCapabilities(t *testing.T) {
372372
},
373373
},
374374
},
375+
{
376+
Type: &csi.ControllerServiceCapability_Rpc{
377+
Rpc: &csi.ControllerServiceCapability_RPC{
378+
Type: csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
379+
},
380+
},
381+
},
375382
},
376383
},
377384
expectedErr: nil,
@@ -1057,6 +1064,60 @@ func TestDeleteSnapshot(t *testing.T) {
10571064
}
10581065
}
10591066

1067+
func TestControllerExpandVolume(t *testing.T) {
1068+
testCases := []struct {
1069+
name string
1070+
testFunc func(t *testing.T)
1071+
}{
1072+
{
1073+
name: "volume ID missing",
1074+
testFunc: func(t *testing.T) {
1075+
d := initTestController(t)
1076+
req := &csi.ControllerExpandVolumeRequest{}
1077+
_, err := d.ControllerExpandVolume(context.Background(), req)
1078+
expectedErr := status.Error(codes.InvalidArgument, "Volume ID missing in request")
1079+
if !reflect.DeepEqual(err, expectedErr) {
1080+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
1081+
}
1082+
},
1083+
},
1084+
{
1085+
name: "Capacity Range missing",
1086+
testFunc: func(t *testing.T) {
1087+
d := initTestController(t)
1088+
req := &csi.ControllerExpandVolumeRequest{
1089+
VolumeId: "unit-test",
1090+
}
1091+
_, err := d.ControllerExpandVolume(context.Background(), req)
1092+
expectedErr := status.Error(codes.InvalidArgument, "Capacity Range missing in request")
1093+
if !reflect.DeepEqual(err, expectedErr) {
1094+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, expectedErr)
1095+
}
1096+
},
1097+
},
1098+
{
1099+
name: "Error = nil",
1100+
testFunc: func(t *testing.T) {
1101+
d := initTestController(t)
1102+
req := &csi.ControllerExpandVolumeRequest{
1103+
VolumeId: "unit-test",
1104+
CapacityRange: &csi.CapacityRange{
1105+
RequiredBytes: 10000,
1106+
},
1107+
}
1108+
_, err := d.ControllerExpandVolume(context.Background(), req)
1109+
if !reflect.DeepEqual(err, nil) {
1110+
t.Errorf("actualErr: (%v), expectedErr: (%v)", err, nil)
1111+
}
1112+
},
1113+
},
1114+
}
1115+
1116+
for _, tc := range testCases {
1117+
t.Run(tc.name, tc.testFunc)
1118+
}
1119+
}
1120+
10601121
func matchCreateSnapshotResponse(e, r *csi.CreateSnapshotResponse) error {
10611122
if e == nil && r == nil {
10621123
return nil

pkg/nfs/nfs.go

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func NewDriver(options *DriverOptions) *Driver {
103103
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
104104
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
105105
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
106+
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
106107
})
107108

108109
n.AddNodeServiceCapabilities([]csi.NodeServiceCapability_RPC_Type{

0 commit comments

Comments
 (0)