Skip to content

Commit 91c3b79

Browse files
committed
Adding Snapshotting Functionality
1 parent 39117b6 commit 91c3b79

File tree

17 files changed

+1000
-113
lines changed

17 files changed

+1000
-113
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ clean:
3131
.PHONY: build-%
3232
$(CMDS:%=build-%): build-%:
3333
mkdir -p bin
34-
CGO_ENABLED=0 go build -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*" ./cmd/$*
34+
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*" ./cmd/$*
3535

3636
.PHONY: container-%
3737
$(CMDS:%=container-%): container-%: build-%
38-
$(DOCKER) build -f ./cmd/$*/Dockerfile -t $*:latest \
38+
$(DOCKER) build -f ./cmd/$*/Dockerfile -t $*:latest\
3939
--label org.opencontainers.image.revision=$(REV) .
4040

4141
.PHONY: test

deploy/k8s/controller-deployment.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# In this YAML file CloudStack CSI Controller contains the following sidecars:
2+
# external-attacher, external-provisioner, external-snapshotter, liveness-probe
13
apiVersion: apps/v1
24
kind: Deployment
35
metadata:
@@ -105,6 +107,26 @@ spec:
105107
- name: socket-dir
106108
mountPath: /var/lib/csi/sockets/pluginproxy/
107109

110+
- name: external-snapshotter
111+
image: registry.k8s.io/sig-storage/csi-snapshotter:v6.3.1
112+
imagePullPolicy: IfNotPresent
113+
args:
114+
- --v=4
115+
- --csi-address=$(ADDRESS)
116+
- --timeout=300s
117+
- --leader-election
118+
- --leader-election-lease-duration=120s
119+
- --leader-election-renew-deadline=60s
120+
- --leader-election-retry-period=30s
121+
- --kube-api-qps=100
122+
- --kube-api-burst=100
123+
env:
124+
- name: ADDRESS
125+
value: /var/lib/csi/sockets/pluginproxy/csi.sock
126+
volumeMounts:
127+
- mountPath: /var/lib/csi/sockets/pluginproxy/
128+
name: socket-dir
129+
108130
- name: liveness-probe
109131
image: registry.k8s.io/sig-storage/livenessprobe:v2.10.0
110132
args:

deploy/k8s/rbac.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,46 @@ roleRef:
4949
kind: ClusterRole
5050
name: cloudstack-csi-controller-role
5151
apiGroup: rbac.authorization.k8s.io
52+
53+
---
54+
# external snapshotter
55+
kind: ClusterRole
56+
apiVersion: rbac.authorization.k8s.io/v1
57+
metadata:
58+
name: csi-snapshotter-role
59+
rules:
60+
- apiGroups: [""]
61+
resources: ["events"]
62+
verbs: ["list", "watch", "create", "update", "patch"]
63+
# Secret permission is optional.
64+
# Enable it if your driver needs secret.
65+
# For example, `csi.storage.k8s.io/snapshotter-secret-name` is set in VolumeSnapshotClass.
66+
# See https://kubernetes-csi.github.io/docs/secrets-and-credentials.html for more details.
67+
# - apiGroups: [""]
68+
# resources: ["secrets"]
69+
# verbs: ["get", "list"]
70+
- apiGroups: ["snapshot.storage.k8s.io"]
71+
resources: ["volumesnapshotclasses"]
72+
verbs: ["get", "list", "watch"]
73+
- apiGroups: ["snapshot.storage.k8s.io"]
74+
resources: ["volumesnapshotcontents"]
75+
verbs: ["create", "get", "list", "watch", "update", "delete", "patch"]
76+
- apiGroups: ["snapshot.storage.k8s.io"]
77+
resources: ["volumesnapshotcontents/status"]
78+
verbs: ["update", "patch"]
79+
- apiGroups: ["coordination.k8s.io"]
80+
resources: ["leases"]
81+
verbs: ["get", "watch", "list", "delete", "update", "create"]
82+
---
83+
kind: ClusterRoleBinding
84+
apiVersion: rbac.authorization.k8s.io/v1
85+
metadata:
86+
name: csi-snapshotter-binding
87+
subjects:
88+
- kind: ServiceAccount
89+
name: cloudstack-csi-controller
90+
namespace: kube-system
91+
roleRef:
92+
kind: ClusterRole
93+
name: csi-snapshotter-role
94+
apiGroup: rbac.authorization.k8s.io

examples/k8s/pod.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ spec:
66
containers:
77
- name: example
88
image: busybox
9+
command: ["/bin/sh"]
10+
args: ["-c", "while true; do date >> /data/date.txt; sleep 5; done"]
911
volumeMounts:
1012
- mountPath: "/data"
1113
name: example-volume
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: snapshot.storage.k8s.io/v1
2+
kind: VolumeSnapshotClass
3+
metadata:
4+
name: csi-cloudstack-snapclass
5+
deletionPolicy: Delete
6+
driver: csi.cloudstack.apache.org
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: example-pod-from-snapshot-data
5+
spec:
6+
containers:
7+
- name: example
8+
image: busybox
9+
volumeMounts:
10+
- mountPath: "/data"
11+
name: example-volume
12+
stdin: true
13+
stdinOnce: true
14+
tty: true
15+
volumes:
16+
- name: example-volume
17+
persistentVolumeClaim:
18+
claimName: pvc-from-snapshot
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: pvc-from-snapshot
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
storageClassName: cloudstack-custom
9+
resources:
10+
requests:
11+
storage: 1Gi
12+
dataSource:
13+
kind: VolumeSnapshot
14+
name: example-snapshot
15+
apiGroup: snapshot.storage.k8s.io
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: snapshot.storage.k8s.io/v1
2+
kind: VolumeSnapshot
3+
metadata:
4+
name: example-snapshot
5+
spec:
6+
volumeSnapshotClassName: csi-cloudstack-snapclass
7+
source:
8+
persistentVolumeClaimName: example-pvc

go.mod

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@ require (
77
github.com/container-storage-interface/spec v1.8.0
88
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
99
github.com/hashicorp/go-uuid v1.0.3
10+
github.com/kubernetes-csi/csi-lib-utils v0.16.0
1011
github.com/kubernetes-csi/csi-test/v4 v4.4.0
1112
go.uber.org/zap v1.25.0
12-
golang.org/x/text v0.12.0
13-
google.golang.org/grpc v1.57.0
13+
golang.org/x/text v0.14.0
14+
google.golang.org/grpc v1.59.0
15+
google.golang.org/protobuf v1.31.0
1416
gopkg.in/gcfg.v1 v1.2.3
15-
k8s.io/api v0.27.5
16-
k8s.io/apimachinery v0.27.5
17-
k8s.io/client-go v0.27.5
17+
k8s.io/api v0.28.0
18+
k8s.io/apimachinery v0.28.0
19+
k8s.io/client-go v0.28.0
20+
k8s.io/klog/v2 v2.100.1
1821
k8s.io/mount-utils v0.27.5
1922
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
2023
)
@@ -23,17 +26,17 @@ require (
2326
github.com/davecgh/go-spew v1.1.1 // indirect
2427
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
2528
github.com/fsnotify/fsnotify v1.4.9 // indirect
26-
github.com/go-logr/logr v1.2.3 // indirect
29+
github.com/go-logr/logr v1.2.4 // indirect
2730
github.com/go-openapi/jsonpointer v0.19.6 // indirect
28-
github.com/go-openapi/jsonreference v0.20.1 // indirect
31+
github.com/go-openapi/jsonreference v0.20.2 // indirect
2932
github.com/go-openapi/swag v0.22.3 // indirect
3033
github.com/gogo/protobuf v1.3.2 // indirect
3134
github.com/golang/mock v1.6.0 // indirect
3235
github.com/golang/protobuf v1.5.3 // indirect
33-
github.com/google/gnostic v0.5.7-v3refs // indirect
36+
github.com/google/gnostic-models v0.6.8 // indirect
3437
github.com/google/go-cmp v0.5.9 // indirect
35-
github.com/google/gofuzz v1.1.0 // indirect
36-
github.com/google/uuid v1.3.0 // indirect
38+
github.com/google/gofuzz v1.2.0 // indirect
39+
github.com/google/uuid v1.3.1 // indirect
3740
github.com/imdario/mergo v0.3.6 // indirect
3841
github.com/josharian/intern v1.0.0 // indirect
3942
github.com/json-iterator/go v1.1.12 // indirect
@@ -44,24 +47,22 @@ require (
4447
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
4548
github.com/nxadm/tail v1.4.8 // indirect
4649
github.com/onsi/ginkgo v1.16.5 // indirect
47-
github.com/onsi/gomega v1.27.4 // indirect
50+
github.com/onsi/gomega v1.27.6 // indirect
4851
github.com/spf13/pflag v1.0.5 // indirect
4952
go.uber.org/multierr v1.10.0 // indirect
50-
golang.org/x/net v0.9.0 // indirect
51-
golang.org/x/oauth2 v0.7.0 // indirect
52-
golang.org/x/sys v0.7.0 // indirect
53-
golang.org/x/term v0.7.0 // indirect
54-
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
53+
golang.org/x/net v0.18.0 // indirect
54+
golang.org/x/oauth2 v0.11.0 // indirect
55+
golang.org/x/sys v0.14.0 // indirect
56+
golang.org/x/term v0.14.0 // indirect
57+
golang.org/x/time v0.3.0 // indirect
5558
google.golang.org/appengine v1.6.7 // indirect
56-
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
57-
google.golang.org/protobuf v1.30.0 // indirect
59+
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
5860
gopkg.in/inf.v0 v0.9.1 // indirect
5961
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
6062
gopkg.in/warnings.v0 v0.1.2 // indirect
6163
gopkg.in/yaml.v2 v2.4.0 // indirect
6264
gopkg.in/yaml.v3 v3.0.1 // indirect
63-
k8s.io/klog/v2 v2.90.1 // indirect
64-
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
65+
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
6566
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
6667
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
6768
sigs.k8s.io/yaml v1.3.0 // indirect

0 commit comments

Comments
 (0)