Skip to content

Commit 8c3a06c

Browse files
committed
csi: revist rbac rules, add Snapshotter sidecar and roles
* Most of the rules are now removed and will not be part of upcoming k8s releases. Going forward drivers have to install themself. * Add `csi-snapshotter` sidecar, needed to handle Volume snapshots * This also adds the necessary roles and bindings needed for the csi-snapshotter sidecar.
1 parent 65221f0 commit 8c3a06c

File tree

7 files changed

+239
-26
lines changed

7 files changed

+239
-26
lines changed

CHANGELOG.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
## unreleased
22

3-
* Add Snapshots functionality
3+
* Add CSI Snapshots functionality
44
[[GH-103]](https://github.com/digitalocean/csi-digitalocean/pull/103)
5+
* Add csi-snapshotter sidecars and associated RBAC rules
6+
[[GH-104]](https://github.com/digitalocean/csi-digitalocean/pull/104)
7+
* Revisit existing RBAC rules for the attacher, provisioner and
8+
driver-registrar. We no longer use the system cluster-role bindings as those
9+
will be deleted in v1.13
10+
[[GH-104]](https://github.com/digitalocean/csi-digitalocean/pull/104)
511
* Fix inconsistent usage of the driver name
612
[[GH-100]](https://github.com/digitalocean/csi-digitalocean/pull/100)
713
* Use publish_info in ControllerPublishVolume for storing and accessing the

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ test:
4747
test-integration:
4848

4949
@echo "==> Started integration tests"
50-
@env GOCACHE=off go test -v -tags integration ./test/...
50+
@env go test -v -tags integration ./test/...
5151

5252

5353
.PHONY: build

deploy/kubernetes/releases/csi-digitalocean-dev.yaml

+139-24
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ provisioner: dobs.csi.digitalocean.com
118118

119119
---
120120

121+
# NOTE(arslan): this will probably fail , because the CRD is created via the
122+
# csi-snapshotter sidecar, that is part of the csi-do-controller statefulset.
123+
# We need to create this seperately.
124+
kind: VolumeSnapshotClass
125+
apiVersion: snapshot.storage.k8s.io/v1alpha1
126+
metadata:
127+
name: do-block-storage
128+
namespace: kube-system
129+
annotations:
130+
snapshot.storage.kubernetes.io/is-default-class: "true"
131+
snapshotter: dobs.csi.digitalocean.com
132+
133+
---
134+
121135
##############################################
122136
########### ############
123137
########### Controller plugin ############
@@ -165,6 +179,18 @@ spec:
165179
volumeMounts:
166180
- name: socket-dir
167181
mountPath: /var/lib/csi/sockets/pluginproxy/
182+
- name: csi-snapshotter
183+
image: quay.io/k8scsi/csi-snapshotter:v0.4.1
184+
args:
185+
- "--connection-timeout=15s"
186+
- "--csi-address=$(ADDRESS)"
187+
env:
188+
- name: ADDRESS
189+
value: /var/lib/csi/sockets/pluginproxy/csi.sock
190+
imagePullPolicy: Always
191+
volumeMounts:
192+
- name: socket-dir
193+
mountPath: /var/lib/csi/sockets/pluginproxy/
168194
- name: csi-do-plugin
169195
image: digitalocean/do-csi-plugin:dev
170196
args :
@@ -190,46 +216,140 @@ spec:
190216
emptyDir: {}
191217
---
192218

193-
apiVersion: v1
194219
kind: ServiceAccount
220+
apiVersion: v1
195221
metadata:
196222
name: csi-do-controller-sa
197223
namespace: kube-system
198224

225+
---
226+
kind: ClusterRole
227+
apiVersion: rbac.authorization.k8s.io/v1
228+
metadata:
229+
name: csi-do-provisioner-role
230+
rules:
231+
- apiGroups: [""]
232+
resources: ["secrets"]
233+
verbs: ["get", "list"]
234+
- apiGroups: [""]
235+
resources: ["persistentvolumes"]
236+
verbs: ["get", "list", "watch", "create", "delete"]
237+
- apiGroups: [""]
238+
resources: ["persistentvolumeclaims"]
239+
verbs: ["get", "list", "watch", "update"]
240+
- apiGroups: ["storage.k8s.io"]
241+
resources: ["storageclasses"]
242+
verbs: ["get", "list", "watch"]
243+
- apiGroups: [""]
244+
resources: ["events"]
245+
verbs: ["list", "watch", "create", "update", "patch"]
246+
- apiGroups: ["snapshot.storage.k8s.io"]
247+
resources: ["volumesnapshots"]
248+
verbs: ["get", "list"]
249+
- apiGroups: ["snapshot.storage.k8s.io"]
250+
resources: ["volumesnapshotcontents"]
251+
verbs: ["get", "list"]
252+
199253
---
200254

201255
kind: ClusterRoleBinding
202256
apiVersion: rbac.authorization.k8s.io/v1
203257
metadata:
204-
name: csi-do-controller-provisioner-binding
205-
namespace: kube-system
258+
name: csi-do-provisioner-binding
206259
subjects:
207260
- kind: ServiceAccount
208261
name: csi-do-controller-sa
209262
namespace: kube-system
210263
roleRef:
211264
kind: ClusterRole
212-
name: system:csi-external-provisioner
265+
name: csi-do-provisioner-role
213266
apiGroup: rbac.authorization.k8s.io
214267

215268
---
269+
# Attacher must be able to work with PVs, nodes and VolumeAttachments
270+
kind: ClusterRole
271+
apiVersion: rbac.authorization.k8s.io/v1
272+
metadata:
273+
name: csi-do-attacher-role
274+
rules:
275+
- apiGroups: [""]
276+
resources: ["persistentvolumes"]
277+
verbs: ["get", "list", "watch", "update"]
278+
- apiGroups: [""]
279+
resources: ["nodes"]
280+
verbs: ["get", "list", "watch"]
281+
- apiGroups: ["csi.storage.k8s.io"]
282+
resources: ["csinodeinfos"]
283+
verbs: ["get", "list", "watch"]
284+
- apiGroups: ["storage.k8s.io"]
285+
resources: ["volumeattachments"]
286+
verbs: ["get", "list", "watch", "update"]
216287

288+
---
217289
kind: ClusterRoleBinding
218290
apiVersion: rbac.authorization.k8s.io/v1
219291
metadata:
220-
name: csi-do-controller-attacher-binding
221-
namespace: kube-system
292+
name: csi-do-attacher-binding
222293
subjects:
223294
- kind: ServiceAccount
224295
name: csi-do-controller-sa
225296
namespace: kube-system
226297
roleRef:
227298
kind: ClusterRole
228-
name: system:csi-external-attacher
299+
name: csi-do-attacher-role
229300
apiGroup: rbac.authorization.k8s.io
230301

231302
---
232303

304+
kind: ClusterRole
305+
apiVersion: rbac.authorization.k8s.io/v1
306+
metadata:
307+
name: csi-do-snapshotter-role
308+
rules:
309+
- apiGroups: [""]
310+
resources: ["persistentvolumes"]
311+
verbs: ["get", "list", "watch"]
312+
- apiGroups: [""]
313+
resources: ["persistentvolumeclaims"]
314+
verbs: ["get", "list", "watch"]
315+
- apiGroups: ["storage.k8s.io"]
316+
resources: ["storageclasses"]
317+
verbs: ["get", "list", "watch"]
318+
- apiGroups: [""]
319+
resources: ["events"]
320+
verbs: ["list", "watch", "create", "update", "patch"]
321+
- apiGroups: [""]
322+
resources: ["secrets"]
323+
verbs: ["get", "list"]
324+
- apiGroups: ["snapshot.storage.k8s.io"]
325+
resources: ["volumesnapshotclasses"]
326+
verbs: ["get", "list", "watch"]
327+
- apiGroups: ["snapshot.storage.k8s.io"]
328+
resources: ["volumesnapshotcontents"]
329+
verbs: ["create", "get", "list", "watch", "update", "delete"]
330+
- apiGroups: ["snapshot.storage.k8s.io"]
331+
resources: ["volumesnapshots"]
332+
verbs: ["get", "list", "watch", "update"]
333+
- apiGroups: ["apiextensions.k8s.io"]
334+
resources: ["customresourcedefinitions"]
335+
verbs: ["create", "list", "watch", "delete"]
336+
337+
---
338+
kind: ClusterRoleBinding
339+
apiVersion: rbac.authorization.k8s.io/v1
340+
metadata:
341+
name: csi-do-snapshotter-binding
342+
subjects:
343+
- kind: ServiceAccount
344+
name: csi-do-controller-sa
345+
namespace: kube-system
346+
roleRef:
347+
kind: ClusterRole
348+
name: csi-do-snapshotter-role
349+
apiGroup: rbac.authorization.k8s.io
350+
351+
352+
233353

234354
########################################
235355
########### ############
@@ -336,11 +456,22 @@ metadata:
336456

337457
---
338458

459+
kind: ClusterRole
460+
apiVersion: rbac.authorization.k8s.io/v1
461+
metadata:
462+
name: csi-do-driver-registrar-role
463+
namespace: kube-system
464+
rules:
465+
- apiGroups: [""]
466+
resources: ["events"]
467+
verbs: ["get", "list", "watch", "create", "update", "patch"]
468+
469+
---
470+
339471
kind: ClusterRoleBinding
340472
apiVersion: rbac.authorization.k8s.io/v1
341473
metadata:
342474
name: csi-do-driver-registrar-binding
343-
namespace: kube-system
344475
subjects:
345476
- kind: ServiceAccount
346477
name: csi-do-node-sa
@@ -350,19 +481,3 @@ roleRef:
350481
name: csi-do-driver-registrar-role
351482
apiGroup: rbac.authorization.k8s.io
352483

353-
354-
---
355-
356-
kind: ClusterRole
357-
apiVersion: rbac.authorization.k8s.io/v1
358-
metadata:
359-
name: csi-do-driver-registrar-role
360-
namespace: kube-system
361-
rules:
362-
- apiGroups: [""]
363-
resources: ["nodes"]
364-
verbs: ["get", "list", "update"]
365-
- apiGroups: [""]
366-
resources: ["events"]
367-
verbs: ["list", "watch", "create", "update", "patch"]
368-
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Creating a snapshot from an exiting volume and restore it back
2+
3+
Note that we assume you correctly installed the csi-digitalocean driver, and
4+
it's up and running.
5+
6+
7+
1. Create a `pvc`:
8+
9+
10+
```
11+
$ kubectl create -f pvc.yaml
12+
```
13+
14+
2. Create a `snapshot` from the previous `pvc`:
15+
16+
17+
```
18+
$ kubectl create -f snapshot.yaml
19+
```
20+
21+
At this point you should have a volume and a snapshot originating from that
22+
volume. You can observe the state of your pvc's and snapshots with the
23+
following command:
24+
25+
26+
```
27+
$ kubectl get pvc && kubectl get pv && kubectl get volumesnapshot
28+
```
29+
30+
31+
3. Restore from a `snapshot`:
32+
33+
To restore from a given snapshot, you need to create a new `pvc` that refers to
34+
the snapshot:
35+
36+
37+
```
38+
$ kubectl create -f restore.yaml
39+
```
40+
41+
This will create a new `pvc` that you can use with your applications.
42+
43+
4. Cleanup your resources:
44+
45+
Make sure to delete your test resources:
46+
47+
```
48+
$ kubectl delete -f pvc.yaml
49+
$ kubectl delete -f restore.yaml
50+
$ kubectl delete -f snapshot.yaml
51+
```
52+
53+
---
54+
55+
To understand how snapshotting works, please read the official blog
56+
announcement with examples:
57+
https://kubernetes.io/blog/2018/10/09/introducing-volume-snapshot-alpha-for-kubernetes/
58+
59+

examples/kubernetes/snapshot/pvc.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: csi-do-test-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
resources:
9+
requests:
10+
storage: 5Gi
11+
storageClassName: do-block-storage
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: csi-do-test-pvc-restore
5+
spec:
6+
dataSource:
7+
name: csi-do-test-snapshot
8+
kind: VolumeSnapshot
9+
apiGroup: snapshot.storage.k8s.io
10+
accessModes:
11+
- ReadWriteOnce
12+
resources:
13+
requests:
14+
storage: 5Gi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: snapshot.storage.k8s.io/v1alpha1
2+
kind: VolumeSnapshot
3+
metadata:
4+
name: csi-do-test-snapshot
5+
spec:
6+
source:
7+
name: csi-do-test-pvc
8+
kind: PersistentVolumeClaim

0 commit comments

Comments
 (0)