Skip to content

Commit a722f94

Browse files
authored
Snapshot support if the infra cluster supports snapshots. (#98)
* Implement snapshot support Signed-off-by: Alexander Wels <[email protected]> * Address review comments Signed-off-by: Alexander Wels <[email protected]> * Addressed more review comments Added extra unit tests to the client. Now am checking if the storage class is in the allowed list. Signed-off-by: Alexander Wels <[email protected]> --------- Signed-off-by: Alexander Wels <[email protected]>
1 parent 7aa580f commit a722f94

File tree

86 files changed

+6017
-6874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+6017
-6874
lines changed

cmd/kubevirt-csi-driver/kubevirt-csi-driver.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ func handle() {
8383
klog.Fatalf("Failed to build tenant client set: %v", err)
8484
}
8585

86-
virtClient, err := kubevirt.NewClient(infraRestConfig)
86+
infraClusterLabelsMap := parseLabels()
87+
storageClassEnforcement := configureStorageClassEnforcement(infraStorageClassEnforcement)
88+
89+
virtClient, err := kubevirt.NewClient(infraRestConfig, infraClusterLabelsMap, storageClassEnforcement)
8790
if err != nil {
8891
klog.Fatal(err)
8992
}
@@ -107,31 +110,34 @@ func handle() {
107110
}
108111
}
109112

110-
infraClusterLabelsMap := parseLabels()
113+
driver := service.NewKubevirtCSIDriver(virtClient,
114+
identityClientset,
115+
*infraClusterNamespace,
116+
infraClusterLabelsMap,
117+
storageClassEnforcement,
118+
nodeID,
119+
*runNodeService,
120+
*runControllerService)
121+
122+
driver.Run(*endpoint)
123+
}
124+
125+
func configureStorageClassEnforcement(infraStorageClassEnforcement string) util.StorageClassEnforcement {
111126
var storageClassEnforcement util.StorageClassEnforcement
112-
//parse yaml
127+
113128
if infraStorageClassEnforcement == "" {
114129
storageClassEnforcement = util.StorageClassEnforcement{
115130
AllowAll: true,
116131
AllowDefault: true,
117132
}
118133
} else {
134+
//parse yaml
119135
err := yaml.Unmarshal([]byte(infraStorageClassEnforcement), &storageClassEnforcement)
120136
if err != nil {
121137
klog.Fatalf("Failed to parse infra-storage-class-enforcement %v", err)
122138
}
123139
}
124-
125-
driver := service.NewKubevirtCSIDriver(virtClient,
126-
identityClientset,
127-
*infraClusterNamespace,
128-
infraClusterLabelsMap,
129-
storageClassEnforcement,
130-
nodeID,
131-
*runNodeService,
132-
*runControllerService)
133-
134-
driver.Run(*endpoint)
140+
return storageClassEnforcement
135141
}
136142

137143
func parseLabels() map[string]string {

deploy/controller-infra/base/deploy.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ spec:
110110
requests:
111111
memory: 50Mi
112112
cpu: 10m
113+
limits:
114+
memory: 500Mi
115+
cpu: 250m
113116
- name: csi-liveness-probe
114117
image: quay.io/openshift/origin-csi-livenessprobe:latest
115118
args:
@@ -125,6 +128,32 @@ spec:
125128
requests:
126129
memory: 50Mi
127130
cpu: 10m
131+
limits:
132+
memory: 500Mi
133+
cpu: 250m
134+
- name: csi-snapshotter
135+
args:
136+
- "--v=5"
137+
- "--csi-address=/csi/csi.sock"
138+
- "--kubeconfig=/var/run/secrets/tenantcluster/value"
139+
image: k8s.gcr.io/sig-storage/csi-snapshotter:v4.2.1
140+
imagePullPolicy: IfNotPresent
141+
securityContext:
142+
privileged: true
143+
terminationMessagePath: /dev/termination-log
144+
terminationMessagePolicy: File
145+
volumeMounts:
146+
- mountPath: /csi
147+
name: socket-dir
148+
- name: tenantcluster
149+
mountPath: "/var/run/secrets/tenantcluster"
150+
resources:
151+
requests:
152+
memory: 20Mi
153+
cpu: 10m
154+
limits:
155+
memory: 500Mi
156+
cpu: 250m
128157
volumes:
129158
- name: socket-dir
130159
emptyDir: {}

deploy/controller-tenant/base/deploy.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ spec:
7373
requests:
7474
memory: 50Mi
7575
cpu: 10m
76+
limits:
77+
memory: 500Mi
78+
cpu: 250m
7679
- name: csi-provisioner
7780
image: quay.io/openshift/origin-csi-external-provisioner:latest
7881
args:
@@ -85,6 +88,13 @@ spec:
8588
volumeMounts:
8689
- name: socket-dir
8790
mountPath: /var/lib/csi/sockets/pluginproxy/
91+
resources:
92+
requests:
93+
memory: 50Mi
94+
cpu: 10m
95+
limits:
96+
memory: 500Mi
97+
cpu: 250m
8898
- name: csi-attacher
8999
image: quay.io/openshift/origin-csi-external-attacher:latest
90100
args:
@@ -100,6 +110,9 @@ spec:
100110
requests:
101111
memory: 50Mi
102112
cpu: 10m
113+
limits:
114+
memory: 500Mi
115+
cpu: 250m
103116
- name: csi-liveness-probe
104117
image: quay.io/openshift/origin-csi-livenessprobe:latest
105118
args:
@@ -113,9 +126,45 @@ spec:
113126
requests:
114127
memory: 50Mi
115128
cpu: 10m
129+
limits:
130+
memory: 500Mi
131+
cpu: 250m
132+
- name: csi-snapshotter
133+
args:
134+
- --v=3
135+
- --csi-address=/csi/csi.sock
136+
image: k8s.gcr.io/sig-storage/csi-snapshotter:v4.2.1
137+
imagePullPolicy: IfNotPresent
138+
securityContext:
139+
privileged: true
140+
terminationMessagePath: /dev/termination-log
141+
terminationMessagePolicy: File
142+
volumeMounts:
143+
- mountPath: /csi
144+
name: socket-dir
145+
resources:
146+
requests:
147+
memory: 20Mi
148+
cpu: 10m
149+
limits:
150+
memory: 500Mi
151+
cpu: 250m
116152
volumes:
117153
- name: socket-dir
118154
emptyDir: {}
119155
- name: infracluster
120156
secret:
121157
secretName: infra-cluster-credentials
158+
---
159+
kind: ClusterRoleBinding
160+
apiVersion: rbac.authorization.k8s.io/v1
161+
metadata:
162+
name: csi-snapshotter-role
163+
subjects:
164+
- kind: ServiceAccount
165+
name: kubevirt-csi-controller-sa
166+
namespace: kubevirt-csi-driver
167+
roleRef:
168+
kind: ClusterRole
169+
name: external-snapshotter-runner
170+
apiGroup: rbac.authorization.k8s.io

deploy/infra-cluster-service-account.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ rules:
1717
- apiGroups: ["subresources.kubevirt.io"]
1818
resources: ["virtualmachineinstances/addvolume", "virtualmachineinstances/removevolume"]
1919
verbs: ["update"]
20+
- apiGroups: ["snapshot.storage.k8s.io"]
21+
resources: ["volumesnapshots"]
22+
verbs: ["get", "create", "delete"]
23+
- apiGroups: [""]
24+
resources: ["persistentvolumeclaims"]
25+
verbs: ["get"]
2026
---
2127
apiVersion: rbac.authorization.k8s.io/v1
2228
kind: RoleBinding
@@ -29,4 +35,5 @@ roleRef:
2935
subjects:
3036
- kind: ServiceAccount
3137
name: kubevirt-csi
32-
---
38+
39+

deploy/tenant/base/deploy.yaml

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ metadata:
8787
name: kubevirt-csi-node-sa
8888
namespace: kubevirt-csi-driver
8989
---
90+
apiVersion: v1
91+
kind: ServiceAccount
92+
metadata:
93+
name: kubevirt-csi-snapshot-sa
94+
namespace: kubevirt-csi-driver
95+
---
9096
apiVersion: rbac.authorization.k8s.io/v1
9197
kind: ClusterRole
9298
metadata:
@@ -124,6 +130,24 @@ rules:
124130
verbs: ["use"]
125131
resourceNames: ["privileged"]
126132
---
133+
kind: ClusterRole
134+
apiVersion: rbac.authorization.k8s.io/v1
135+
metadata:
136+
name: external-snapshotter-runner
137+
rules:
138+
- apiGroups: [""]
139+
resources: ["events"]
140+
verbs: ["list", "watch", "create", "update", "patch"]
141+
- apiGroups: ["snapshot.storage.k8s.io"]
142+
resources: ["volumesnapshotclasses"]
143+
verbs: ["get", "list", "watch"]
144+
- apiGroups: ["snapshot.storage.k8s.io"]
145+
resources: ["volumesnapshotcontents"]
146+
verbs: ["create", "get", "list", "watch", "update", "delete", "patch"]
147+
- apiGroups: ["snapshot.storage.k8s.io"]
148+
resources: ["volumesnapshotcontents/status"]
149+
verbs: ["update", "patch"]
150+
---
127151
kind: ClusterRoleBinding
128152
apiVersion: rbac.authorization.k8s.io/v1
129153
metadata:
@@ -137,6 +161,20 @@ roleRef:
137161
name: kubevirt-csi-node-cr
138162
apiGroup: rbac.authorization.k8s.io
139163
---
164+
kind: ClusterRoleBinding
165+
apiVersion: rbac.authorization.k8s.io/v1
166+
metadata:
167+
name: csi-snapshotter-role
168+
subjects:
169+
- kind: ServiceAccount
170+
name: kubevirt-csi-snapshot-sa
171+
namespace: kubevirt-csi-driver
172+
roleRef:
173+
kind: ClusterRole
174+
# change the name also here if the ClusterRole gets renamed
175+
name: external-snapshotter-runner
176+
apiGroup: rbac.authorization.k8s.io
177+
---
140178
kind: DaemonSet
141179
apiVersion: apps/v1
142180
metadata:
@@ -201,6 +239,9 @@ spec:
201239
requests:
202240
memory: 50Mi
203241
cpu: 10m
242+
limits:
243+
memory: 500Mi
244+
cpu: 250m
204245
- name: csi-node-driver-registrar
205246
image: quay.io/openshift/origin-csi-node-driver-registrar:latest
206247
args:
@@ -225,6 +266,9 @@ spec:
225266
requests:
226267
memory: 20Mi
227268
cpu: 5m
269+
limits:
270+
memory: 500Mi
271+
cpu: 100m
228272
- name: csi-liveness-probe
229273
image: quay.io/openshift/origin-csi-livenessprobe:latest
230274
args:
@@ -238,6 +282,9 @@ spec:
238282
requests:
239283
memory: 20Mi
240284
cpu: 5m
285+
limits:
286+
memory: 500Mi
287+
cpu: 100m
241288
volumes:
242289
- name: kubelet-dir
243290
hostPath:
@@ -277,4 +324,11 @@ metadata:
277324
provisioner: csi.kubevirt.io
278325
parameters:
279326
infraStorageClassName: standard
280-
bus: scsi
327+
bus: scsi
328+
---
329+
apiVersion: snapshot.storage.k8s.io/v1
330+
kind: VolumeSnapshotClass
331+
metadata:
332+
name: kubevirt-csi-snapclass
333+
driver: csi.kubevirt.io
334+
deletionPolicy: Delete

deploy/tenant/base/kustomization.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
commonLabels:
22
app: kubevirt-csi-driver
33
resources:
4+
- rbac-snapshot-controller.yaml
5+
- setup-snapshot-controller.yaml
6+
- snapshot.storage.k8s.io_volumesnapshotclasses.yaml
7+
- snapshot.storage.k8s.io_volumesnapshotcontents.yaml
8+
- snapshot.storage.k8s.io_volumesnapshots.yaml
49
- deploy.yaml

0 commit comments

Comments
 (0)