Skip to content

Commit 3b8354d

Browse files
authored
Merge pull request #2 from cloudstack/cloudstack-csi-enhancements
Cloudstack csi enhancements
2 parents 8c92ce5 + 97d0b1b commit 3b8354d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2625
-51
lines changed

.github/workflows/pr-check.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ on:
66
jobs:
77
lint:
88
name: Lint
9-
runs-on: ubuntu-20.04
9+
runs-on: ubuntu-24.04
1010
steps:
11-
- name: Setup up Go 1.x
11+
- name: Setup up Go 1.23
1212
uses: actions/setup-go@v5
1313
with:
14-
go-version: "^1.15"
14+
go-version: "1.23"
1515
- name: Check out code
1616
uses: actions/checkout@v4
1717
- name: golangci-lint
1818
uses: golangci/golangci-lint-action@v6
1919
with:
20-
version: v1.58.2
20+
version: v1.63.4
2121
args: --timeout=5m
2222

2323
build:
2424
name: Test & Build
25-
runs-on: ubuntu-20.04
25+
runs-on: ubuntu-24.04
2626
steps:
27-
- name: Setup up Go 1.x
27+
- name: Setup up Go 1.23
2828
uses: actions/setup-go@v5
2929
with:
30-
go-version: "^1.15"
30+
go-version: "1.23"
3131

3232
- name: Check out code
3333
uses: actions/checkout@v4

.github/workflows/release.yaml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414
jobs:
1515
push:
1616
name: Push images
17-
runs-on: ubuntu-20.04
17+
runs-on: ubuntu-24.04
1818

1919
steps:
2020
- name: Check out code
@@ -67,7 +67,7 @@ jobs:
6767

6868
release:
6969
name: Release
70-
runs-on: ubuntu-20.04
70+
runs-on: ubuntu-24.04
7171

7272
# Run only if previous job has succeeded
7373
needs: [push]
@@ -87,9 +87,11 @@ jobs:
8787
echo "---" >> manifest.yaml
8888
cat deploy/k8s/csidriver.yaml >> manifest.yaml
8989
echo "---" >> manifest.yaml
90-
sed -E "s|image: +cloudstack-csi-driver|image: ${REGISTRY_NAME}/cloudstack-csi-driver:${VERSION}|" deploy/k8s/controller-deployment.yaml >> manifest.yaml
90+
sed -E "s|(image: +${REGISTRY_NAME}/cloudstack-csi-driver)(:[^ ]+)?|\\1:${VERSION}|" deploy/k8s/controller-deployment.yaml >> manifest.yaml
9191
echo "---" >> manifest.yaml
92-
sed -E "s|image: +cloudstack-csi-driver|image: ${REGISTRY_NAME}/cloudstack-csi-driver:${VERSION}|" deploy/k8s/node-daemonset.yaml >> manifest.yaml
92+
sed -E "s|(image: +${REGISTRY_NAME}/cloudstack-csi-driver)(:[^ ]+)?|\\1:${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:

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CMDS=cloudstack-csi-driver cloudstack-csi-sc-syncer
22

3-
PKG=github.com/shapeblue/cloudstack-csi-driver
3+
PKG=github.com/cloudstack/cloudstack-csi-driver
44
# Revision that gets built into each binary via the main.version
55
# string. Uses the `git describe` output based on the most recent
66
# version tag with a short revision suffix or, if nothing has been

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/cloudstack/cloudstack-csi-driver.svg)](https://pkg.go.dev/github.com/cloudstack/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

charts/cloudstack-csi/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: cloudstack-csi
33
description: A Helm chart for CloudStack CSI driver
44
type: application
5-
version: 2.0.3
5+
version: 3.0.0
66
appVersion: 0.6.1
77
sources:
88
- https://github.com/cloudstack/cloudstack-csi-driver

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"]

cmd/cloudstack-csi-driver/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
120
// cloudstack-csi-driver binary.
221
//
322
// To get usage information:

cmd/cloudstack-csi-sc-syncer/main.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
120
// Small utility to synchronize CloudStack disk offerings to
221
// Kubernetes storage classes.
322
package main

0 commit comments

Comments
 (0)