Skip to content

Commit 6eea15f

Browse files
authored
Merge pull request #9 from shapeblue/enhancements-csi
Enhancements to CloudStack CSI driver
2 parents 5183b54 + 2c19a99 commit 6eea15f

File tree

20 files changed

+1716
-23
lines changed

20 files changed

+1716
-23
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: 128 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] (https://github.com/leaseweb/cloudstack-csi-driver) maitained cloudstack-csi-driver, which is in-turn a fork of [Apalia's](https://github.com/apalia/cloudstack-csi-driver) 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)
@@ -76,13 +80,28 @@ The storage class must also have a parameter named
7680
`csi.cloudstack.apache.org/disk-offering-id` whose value is the CloudStack disk
7781
offering ID.
7882

83+
**Reclaim Policy**: Storage classes can have a `reclaimPolicy` of either `Delete` or `Retain`. If no `reclaimPolicy` is specified, it defaults to `Delete`.
84+
85+
- `Delete`: When a PVC is deleted or a CKS cluster (Managed Kubernetes Cluster in CloudStack) is deleted, the associated persistent volumes and their underlying CloudStack disk volumes will be automatically removed.
86+
- `Retain`: Persistent volumes and their underlying CloudStack disk volumes will be preserved even after PVC deletion or cluster deletion, allowing for manual recovery or data preservation.
87+
7988
#### Using cloudstack-csi-sc-syncer
8089

8190
The tool `cloudstack-csi-sc-syncer` may also be used to synchronize CloudStack
8291
disk offerings to Kubernetes storage classes.
8392

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

95+
> **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.
96+
97+
98+
```
99+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.3.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
100+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.3.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml
101+
kubectl apply -f https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/v8.3.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
102+
103+
```
104+
86105
### Usage
87106

88107
Example:
@@ -106,6 +125,115 @@ To build the container images:
106125
make container
107126
```
108127

128+
129+
## Volume Snapshots
130+
131+
**NOTE:** To create volume snapshots in KVM, make sure to set the `kvm.snapshot.enabled` global setting to true and restart the Management Server
132+
133+
### Volume snapshot creation
134+
For Volume snapshots to be created, the following configurations need to be applied:
135+
136+
```
137+
kubectl apply -f deploy/k8s/00-snapshot-crds.yaml # Installs the VolumeSnapshotClass, VolumeSnapshotContent and VolumeSnapshtot CRDs
138+
kubectl apply -f deploy/k8s/volume-snapshot-class.yaml # Defines VolumeSnapshotClass for CloudStack CSI driver
139+
```
140+
141+
Once the CRDs are installed, the snapshot can be taken by applying:
142+
```
143+
kubectl apply ./examples/k8s/snapshot/snapshot.yaml
144+
```
145+
146+
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.
147+
148+
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
149+
150+
```
151+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system # defaults to tailing logs of cloudstack-csi-controller
152+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system -c csi-snapshotter
153+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system -c snapshot-controller
154+
```
155+
156+
### Restoring a Volume snapshot
157+
158+
To restore a volume snapshot:
159+
1. Restore a snapshot and Use it in a pod
160+
* Create a PVC from the snapshot - for example ./examples/k8s/snapshot/pvc-from-snapshot.yaml
161+
* Apply the configuration:
162+
```
163+
kubectl apply -f ./examples/k8s/snapshot/pvc-from-snapshot.yaml
164+
```
165+
* Create a pod that uses the restored PVC; example pod config ./examples/k8s/snapshot/restore-pod.yaml
166+
```
167+
kubectl apply -f ./examples/k8s/snapshot/restore-pod.yaml
168+
```
169+
2. To restore a snapshot when using a deployment
170+
Update the deployment to point to the restored PVC
171+
172+
```
173+
spec:
174+
volumes:
175+
- name: app-volume
176+
persistentVolumeClaim:
177+
claimName: pvc-from-snapshot
178+
```
179+
180+
181+
### Deletion of a volume snapshot
182+
183+
To delete a volume snapshot
184+
One can simlpy delete the volume snapshot created in kubernetes using
185+
186+
```
187+
kubectl delete volumesnapshot snapshot-1 # here, snapshot-1 is the name of the snapshot created
188+
```
189+
190+
#### Troubleshooting issues with volume snapshot deletion
191+
If for whatever reason, snapshot deletion gets stuck, one can troubleshoot the issue doing the following:
192+
193+
* Inspect the snapshot
194+
195+
```
196+
kubectl get volumesnapshot <snapshot-name> [-n <namespace>] -o yaml
197+
```
198+
199+
Look for the following section:
200+
```
201+
metadata:
202+
finalizers:
203+
- snapshot.storage.kubernetes.io/volumesnapshot-as-source
204+
```
205+
206+
If finalizers are present, Kubernetes will not delete the resource until they are removed or resolved.
207+
208+
* Patch to Remove Finalizers
209+
210+
```
211+
kubectl patch volumesnapshot <snapshot-name> [-n <namespace>] --type=merge -p '{"metadata":{"finalizers":[]}}'
212+
```
213+
214+
**Caution:** This bypasses cleanup logic. Use only if you're certain the snapshot is no longer needed at the CSI/backend level
215+
216+
### What happens when you restore a volume from a snapshot
217+
* The CSI external-provisioner (a container in the cloudstack-csi-controller pod) sees the new PVC and notices it references a snapshot
218+
* The CSI driver's `CreateVolume` method is called with a `VolumeContentSource` that contains the snapshot ID
219+
* The CSI driver creates a new volume from the snapshot (using the CloudStack's createVolume API)
220+
* The new volume is now available as a PV (persistent volume) and is bound to the new PVC
221+
* 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
222+
* The CSI driver's `ControllerPublishVolume` and `NodePublishVolume` methods are called to attach and mount the volume to the node where the Pod is running
223+
224+
Hence to debug any issues during restoring a snapshot, check the logs of the cloudstack-csi-controller, external-provisioner containers
225+
226+
```
227+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system # defaults to tailing logs of cloudstack-csi-controller
228+
kubectl logs -f <cloudstack-csi-controller pod_name> -n kube-system -c external-provisioner
229+
```
230+
231+
## Additional General Notes:
232+
233+
**Node Scheduling Best Practices**: When deploying applications that require specific node placement, use `nodeSelector` or `nodeAffinity` instead of `nodeName`. The `nodeName` field bypasses the Kubernetes scheduler, which can cause issues with storage provisioning. When a StorageClass has `volumeBindingMode: WaitForFirstConsumer`, the CSI controller relies on scheduler decisions to properly bind PVCs. Using `nodeName` prevents this scheduling integration, potentially causing PVC binding failures.
234+
235+
**Network CIDR Considerations**: When deploying CKS (CloudStack Kubernetes Service) clusters on pre-existing networks, avoid using the `10.0.0.0/16` CIDR range as it conflicts with Calico's default pod network configuration. This overlap can prevent proper CSI driver initialization and may cause networking issues within the cluster.
236+
109237
## See also
110238

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

cmd/cloudstack-csi-driver/Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ RUN apk add --no-cache \
1414
# blkid, mount and umount are required by k8s.io/mount-utils \
1515
blkid \
1616
mount \
17-
umount
17+
umount \
18+
# Provides udevadm for device path detection \
19+
udev
1820

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

0 commit comments

Comments
 (0)