Skip to content

Commit d98112c

Browse files
committed
Adding Snapshotting Functionality
1 parent 849aebb commit d98112c

19 files changed

Lines changed: 1010 additions & 118 deletions

.github/workflows/pr-check.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
name: Lint
99
runs-on: ubuntu-20.04
1010
steps:
11-
- uses: actions/checkout@v3
11+
- uses: actions/checkout@v4
1212
- name: golangci-lint
1313
uses: golangci/golangci-lint-action@v3
1414
with:
@@ -25,7 +25,7 @@ jobs:
2525
go-version: "^1.15"
2626

2727
- name: Check out code
28-
uses: actions/checkout@v3
28+
uses: actions/checkout@v4
2929

3030
- name: Cache
3131
uses: actions/cache@v3

.github/workflows/release.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: Check out code
21-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2222

2323
- name: Cache
2424
uses: actions/cache@v3
@@ -32,7 +32,7 @@ jobs:
3232
run: make container
3333

3434
- name: Log into registry
35-
uses: docker/login-action@v2
35+
uses: docker/login-action@v3
3636
with:
3737
registry: ghcr.io
3838
username: ${{github.actor}}
@@ -77,7 +77,7 @@ jobs:
7777

7878
steps:
7979
- name: Checkout code
80-
uses: actions/checkout@v3
80+
uses: actions/checkout@v4
8181

8282
- name: Create manifest
8383
run: |

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ 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-%

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

0 commit comments

Comments
 (0)