Skip to content

Commit

Permalink
Adding Snapshotting Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Farnaz Babaeian committed Dec 5, 2023
1 parent 39117b6 commit 91c3b79
Show file tree
Hide file tree
Showing 17 changed files with 1,000 additions and 113 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ clean:
.PHONY: build-%
$(CMDS:%=build-%): build-%:
mkdir -p bin
CGO_ENABLED=0 go build -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*" ./cmd/$*
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*" ./cmd/$*

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

.PHONY: test
Expand Down
22 changes: 22 additions & 0 deletions deploy/k8s/controller-deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# In this YAML file CloudStack CSI Controller contains the following sidecars:
# external-attacher, external-provisioner, external-snapshotter, liveness-probe
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -105,6 +107,26 @@ spec:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/

- name: external-snapshotter
image: registry.k8s.io/sig-storage/csi-snapshotter:v6.3.1
imagePullPolicy: IfNotPresent
args:
- --v=4
- --csi-address=$(ADDRESS)
- --timeout=300s
- --leader-election
- --leader-election-lease-duration=120s
- --leader-election-renew-deadline=60s
- --leader-election-retry-period=30s
- --kube-api-qps=100
- --kube-api-burst=100
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
volumeMounts:
- mountPath: /var/lib/csi/sockets/pluginproxy/
name: socket-dir

- name: liveness-probe
image: registry.k8s.io/sig-storage/livenessprobe:v2.10.0
args:
Expand Down
43 changes: 43 additions & 0 deletions deploy/k8s/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,46 @@ roleRef:
kind: ClusterRole
name: cloudstack-csi-controller-role
apiGroup: rbac.authorization.k8s.io

---
# external snapshotter
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-snapshotter-role
rules:
- apiGroups: [""]
resources: ["events"]
verbs: ["list", "watch", "create", "update", "patch"]
# Secret permission is optional.
# Enable it if your driver needs secret.
# For example, `csi.storage.k8s.io/snapshotter-secret-name` is set in VolumeSnapshotClass.
# See https://kubernetes-csi.github.io/docs/secrets-and-credentials.html for more details.
# - apiGroups: [""]
# resources: ["secrets"]
# verbs: ["get", "list"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotclasses"]
verbs: ["get", "list", "watch"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotcontents"]
verbs: ["create", "get", "list", "watch", "update", "delete", "patch"]
- apiGroups: ["snapshot.storage.k8s.io"]
resources: ["volumesnapshotcontents/status"]
verbs: ["update", "patch"]
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "watch", "list", "delete", "update", "create"]
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: csi-snapshotter-binding
subjects:
- kind: ServiceAccount
name: cloudstack-csi-controller
namespace: kube-system
roleRef:
kind: ClusterRole
name: csi-snapshotter-role
apiGroup: rbac.authorization.k8s.io
2 changes: 2 additions & 0 deletions examples/k8s/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ spec:
containers:
- name: example
image: busybox
command: ["/bin/sh"]
args: ["-c", "while true; do date >> /data/date.txt; sleep 5; done"]
volumeMounts:
- mountPath: "/data"
name: example-volume
Expand Down
6 changes: 6 additions & 0 deletions examples/k8s/snapshot/0-volumestorageclass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: csi-cloudstack-snapclass
deletionPolicy: Delete
driver: csi.cloudstack.apache.org
18 changes: 18 additions & 0 deletions examples/k8s/snapshot/pod-with-snapshot-data.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: Pod
metadata:
name: example-pod-from-snapshot-data
spec:
containers:
- name: example
image: busybox
volumeMounts:
- mountPath: "/data"
name: example-volume
stdin: true
stdinOnce: true
tty: true
volumes:
- name: example-volume
persistentVolumeClaim:
claimName: pvc-from-snapshot
15 changes: 15 additions & 0 deletions examples/k8s/snapshot/pvc-from-snapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-from-snapshot
spec:
accessModes:
- ReadWriteOnce
storageClassName: cloudstack-custom
resources:
requests:
storage: 1Gi
dataSource:
kind: VolumeSnapshot
name: example-snapshot
apiGroup: snapshot.storage.k8s.io
8 changes: 8 additions & 0 deletions examples/k8s/snapshot/volumesnapshot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: example-snapshot
spec:
volumeSnapshotClassName: csi-cloudstack-snapclass
source:
persistentVolumeClaimName: example-pvc
41 changes: 21 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ require (
github.com/container-storage-interface/spec v1.8.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/hashicorp/go-uuid v1.0.3
github.com/kubernetes-csi/csi-lib-utils v0.16.0
github.com/kubernetes-csi/csi-test/v4 v4.4.0
go.uber.org/zap v1.25.0
golang.org/x/text v0.12.0
google.golang.org/grpc v1.57.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.59.0
google.golang.org/protobuf v1.31.0
gopkg.in/gcfg.v1 v1.2.3
k8s.io/api v0.27.5
k8s.io/apimachinery v0.27.5
k8s.io/client-go v0.27.5
k8s.io/api v0.28.0
k8s.io/apimachinery v0.28.0
k8s.io/client-go v0.28.0
k8s.io/klog/v2 v2.100.1
k8s.io/mount-utils v0.27.5
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
)
Expand All @@ -23,17 +26,17 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -44,24 +47,22 @@ require (
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.27.4 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/oauth2 v0.11.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 91c3b79

Please sign in to comment.