Skip to content

Commit 909412b

Browse files
authored
Merge pull request #8 from shapeblue/add-volume-snapshot-support
Add support for Volume snapshot for CloudStack CSI driver
2 parents 9a7a654 + ec84788 commit 909412b

File tree

16 files changed

+1482
-5
lines changed

16 files changed

+1482
-5
lines changed

.github/workflows/release.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ jobs:
9090
sed -E "s|image: +cloudstack-csi-driver|image: ${REGISTRY_NAME}/cloudstack-csi-driver:${VERSION}|" deploy/k8s/controller-deployment.yaml >> manifest.yaml
9191
echo "---" >> manifest.yaml
9292
sed -E "s|image: +cloudstack-csi-driver|image: ${REGISTRY_NAME}/cloudstack-csi-driver:${VERSION}|" deploy/k8s/node-daemonset.yaml >> manifest.yaml
93+
echo "---" >> manifest.yaml
94+
cat deploy/k8s/volume-snapshot-class.yaml >> manifest.yaml
9395
9496
- name: Create Release
9597
id: create_release
@@ -102,6 +104,16 @@ jobs:
102104
draft: false
103105
prerelease: false
104106

107+
- name: Upload Snapshot CRDs Asset
108+
uses: actions/upload-release-asset@v1
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
with:
112+
upload_url: ${{ steps.create_release.outputs.upload_url }}
113+
asset_path: deploy/k8s/00-snapshot-crds.yaml
114+
asset_name: snapshot-crds.yaml
115+
asset_content_type: application/x-yaml
116+
105117
- name: Upload Release Asset
106118
uses: actions/upload-release-asset@v1
107119
env:

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**Fork Notice:**
2+
3+
This repo is a fork of the Leaseweb's maitained cloudstack-csi-driver, which is in-turn a fork of Apalia's cloudstack-csi-driver
4+
15
# CloudStack CSI Driver
26

37
[![Go Reference](https://pkg.go.dev/badge/github.com/shapeblue/cloudstack-csi-driver.svg)](https://pkg.go.dev/github.com/shapeblue/cloudstack-csi-driver)
@@ -83,6 +87,17 @@ disk offerings to Kubernetes storage classes.
8387

8488
[More info...](./cmd/cloudstack-csi-sc-syncer/README.md)
8589

90+
> **Note:** The VolumeSnapshot CRDs (CustomResourceDefinitions) of version 8.3.0 are installed in this deployment. If you use a different version, please ensure compatibility with your Kubernetes cluster and CSI sidecars.
91+
92+
// TODO: Should we have the crds locally or manually install it from:
93+
94+
```
95+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.3.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
96+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.3.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
97+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.3.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
98+
99+
```
100+
86101
### Usage
87102

88103
Example:
@@ -106,6 +121,67 @@ To build the container images:
106121
make container
107122
```
108123

124+
125+
## Volume Snapshots
126+
For Volume snapshots to be created, the following configurations need to be applied:
127+
128+
```
129+
kubectl aplly -f 00-snapshot-crds.yaml # Installs the VolumeSnapshotClass, VolumeSnapshotContent and VolumeSnapshtot CRDs
130+
volume-snapshot-class.yaml # Defines VolumeSnapshotClass for CloudStack CSI driver
131+
```
132+
133+
Once the CRDs are installed, the snapshot can be taken by applying:
134+
```
135+
kubectl apply ./examples/k8s/snapshot/snapshot.yaml
136+
```
137+
138+
In order to take the snapshot of a volume, `persistentVolumeClaimName` should be set to the right PVC name that is bound to the volume whose snapshot is to be taken.
139+
140+
You can check CloudStack volume snapshots if the snapshot was successfully created. If for any reason there was an issue, it can be investgated by checking the logs of the cloudstack-csi-controller pods: cloudstack-csi-controller, csi-snapshotter and snapshot-controller containers
141+
142+
```
143+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system # defaults to tailing logs of cloudstack-csi-controller
144+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system -c csi-snapshotter
145+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system -c snapshot-controller
146+
```
147+
148+
To restore a volume snapshot:
149+
1. Restore a snapshot and Use it in a pod
150+
* Create a PVC from the snapshot - for example ./examples/k8s/snapshot/pvc-from-snapshot.yaml
151+
* Apply the configuration:
152+
```
153+
kubectl apply -f ./examples/k8s/snapshot/pvc-from-snapshot.yaml
154+
```
155+
* Create a pod that uses the restored PVC; example pod config ./examples/k8s/snapshot/restore-pod.yaml
156+
```
157+
kubectl apply -f ./examples/k8s/snapshot/restore-pod.yaml
158+
```
159+
2. To restore a snapshot when using a deployment
160+
Update the deployment to point to the restored PVC
161+
162+
```
163+
spec:
164+
volumes:
165+
- name: app-volume
166+
persistentVolumeClaim:
167+
claimName: pvc-from-snapshot
168+
```
169+
170+
### What happens when you restore a volume from a snapshot
171+
* The CSI external-provisioner (a container in the cloudstack-csi-controller pod) sees the new PVC and notices it references a snapshot
172+
* The CSI driver's `CreateVolume` method is called with a `VolumeContentSource` that contains the snapshot ID
173+
* The CSI driver creates a new volume from the snapshot (using the CloudStack's createVolume API)
174+
* The new volume is now available as a PV (persistent volume) and is bound to the new PVC
175+
* The volume is NOT attached to any node just by restoring from a snapshot, the volume is only attached to a node when a Pod that uses the new PVC is scheduled on a node
176+
* The CSI driver's `ControllerPublishVolume` and `NodePublishVolume` methods are called to attach and mount the volume to the node where the Pod is running
177+
178+
Hence to debug any issues during restoring a snapshot, check the logs of the cloudstack-csi-controller, external-provisioner containers
179+
180+
```
181+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system # defaults to tailing logs of cloudstack-csi-controller
182+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system -c external-provisioner
183+
```
184+
109185
## See also
110186

111187
- [CloudStack Kubernetes Provider](https://github.com/apache/cloudstack-kubernetes-provider) - Kubernetes Cloud Controller Manager for Apache CloudStack

cmd/cloudstack-csi-driver/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN apk add --no-cache \
1616
mount \
1717
umount \
1818
# Provides udevadm for device path detection \
19-
udev
19+
udev
2020

2121
COPY ./bin/cloudstack-csi-driver /cloudstack-csi-driver
22-
ENTRYPOINT ["/cloudstack-csi-driver"]
22+
ENTRYPOINT ["/cloudstack-csi-driver"]

0 commit comments

Comments
 (0)