Skip to content

Add support for Volume snapshot for CloudStack CSI driver #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: increase-pod-affinity-leniency
Choose a base branch
from

Conversation

Pearl1594
Copy link
Member

@Pearl1594 Pearl1594 commented Jul 9, 2025

Issue #, if available:

Description of changes:

Testing performed:

Snapshot Creation

  1. Apply the configs at ~/deploy/k8s/ - this will deploy the cloudstack-csi-controller with csi-snapshotter & snapshot-controller sidecar containers
  2. Then apply 0-storageclass.yaml (with disk offering id set to that of custom offering), pod.yaml and pvc.yaml
  3. Once the PVC is created on ACS, apply the snapshot.yaml file in the ~/examples/k8s/snapshot path and update the PVC to the right pvc name in the config file
  4. Successfully creates a volume snapshot
$ kubectl get volumesnapshot,volumesnapshotcontent
NAME                                                READYTOUSE   SOURCEPVC     SOURCESNAPSHOTCONTENT   RESTORESIZE   SNAPSHOTCLASS         SNAPSHOTCONTENT                                    CREATIONTIME   AGE
volumesnapshot.snapshot.storage.k8s.io/snapshot-1   true         example-pvc                           0             cloudstack-snapshot   snapcontent-ab5b8e40-3ea8-43c8-ba17-10d78837f5ff   7m19s          7m19s

NAME                                                                                             READYTOUSE   RESTORESIZE   DELETIONPOLICY   DRIVER                      VOLUMESNAPSHOTCLASS   VOLUMESNAPSHOT   VOLUMESNAPSHOTNAMESPACE   AGE
volumesnapshotcontent.snapshot.storage.k8s.io/snapcontent-ab5b8e40-3ea8-43c8-ba17-10d78837f5ff   true         0             Delete           csi.cloudstack.apache.org   cloudstack-snapshot   snapshot-1       default                   7m19s

Logs in CSI controller:

I0710 15:30:34.363345       1 controller.go:299] CreateSnapshot
I0710 15:30:34.363776       1 volumes.go:46] "CloudStack API call" command="ListVolumes" params={"id":"912389c1-6459-4ce2-be01-477aa30127b7"}

Snapshot Deletion

  1. Since the deletion policy is set to 'Delete' in the volumeSnapshotClass, to delete a volume snapshot, we must first delete the volumesnapshotcontent
$ kubectl delete volumesnapshotcontent snapcontent-ab5b8e40-3ea8-43c8-ba17-10d78837f5ff
volumesnapshotcontent.snapshot.storage.k8s.io "snapcontent-ab5b8e40-3ea8-43c8-ba17-10d78837f5ff" deleted
$ kubectl delete volumesnapshot snapshot-1

logs in the csi-controller container

I0710 15:39:37.793973       1 controller.go:336] DeleteSnapshot

Snapshot restore - by creating a new Pod

Created PVC from snapshot
Then created a Pod that used the PVC

root@cks-root-control-1982e72c86a:~# kubectl get pvc
NAME             STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS        VOLUMEATTRIBUTESCLASS   AGE
example-pvc      Bound    pvc-4298b4ae-2abe-4ce0-9821-e8a5ac1b3f2a   1Gi        RWO            cloudstack-custom   <unset>                 28h
snapshot-pvc-1   Bound    pvc-6e1fc165-563b-4036-bfda-42138b97a284   1Gi        RWO            cloudstack-custom   <unset>                 28h

As seen the PVC is bound to a Persistent Volume (volume on CloudStack: pvc-6e1fc165-563b-4036-bfda-42138b97a284)

Pod with volume created from snapshot is in Running state

NAMESPACE              NAME                                                   READY   STATUS    RESTARTS       AGE
default                example-pod                                            1/1     Running   0              28h
default                restore-pod                                            1/1     Running   28 (54m ago)   28h <-----

Logs of successful volume creation from snapshot and attach to the worker node (additional logs added for debugging purpose)

I0722 14:40:01.681590       1 controller.go:133] "Creating volume from snapshot" snapshotID="d90c1aab-c024-4447-b79d-1e0d9f960668"
{
  "name": "pvc-6e1fc165-563b-4036-bfda-42138b97a284",
  "capacity_range": {
    "required_bytes": 1073741824
  },
  "volume_capabilities": [
    {
      "AccessType": {
        "Mount": {
          "fs_type": "ext4"
        }
      },
      "access_mode": {
        "mode": 1
      }
    }
  ],
  "parameters": {
    "csi.cloudstack.apache.org/disk-offering-id": "1597cc78-df0a-41e4-b729-079af2e529cb"
  },
  "volume_content_source": {
    "Type": {
      "Snapshot": {
        "snapshot_id": "d90c1aab-c024-4447-b79d-1e0d9f960668"
      }
    }
  },
  "accessibility_requirements": {
    "requisite": [
      {
        "segments": {
          "topology.csi.cloudstack.apache.org/zone": "f4a2df97-71b4-4083-be19-4accadf9382c"
        }
      }
    ],
    "preferred": [
      {
        "segments": {
          "topology.csi.cloudstack.apache.org/zone": "f4a2df97-71b4-4083-be19-4accadf9382c"
        }
      }
    ]
  }
}
I0722 14:40:01.726174       1 controller.go:143] "Disk offering ID" diskOfferingID: ="1597cc78-df0a-41e4-b729-079af2e529cb"
I0722 14:40:01.726266       1 controller.go:144] "Zone ID" ZoneID="f4a2df97-71b4-4083-be19-4accadf9382c"
I0722 14:40:01.726292       1 controller.go:145] "Name" name="pvc-6e1fc165-563b-4036-bfda-42138b97a284"
I0722 14:40:01.726316       1 controller.go:146] "Domain ID" DomainID="db0704ab-5827-11f0-804a-1e0052000469"
I0722 14:40:01.726339       1 controller.go:147] "Project ID" ProjectID=""
I0722 14:40:01.726361       1 controller.go:148] "Snapshot ID" snapshotID="d90c1aab-c024-4447-b79d-1e0d9f960668"
I0722 14:40:01.726388       1 controller.go:149] "Volume size" Size in GB=1
I0722 14:40:01.726428       1 controller.go:151] "snapshot size" snap size=0
I0722 14:40:01.753148       1 volumes.go:175] "CloudStack API call" command="CreateVolume" params={"name":"pvc-6e1fc165-563b-4036-bfda-42138b97a284","projectid":"","size":"1","snapshotid":"d90c1aab-c024-4447-b79d-1e0d9f960668","zoneid":"f4a2df97-71b4-4083-be19-4accadf9382c"}
I0722 14:40:03.704506       1 controller.go:417] "Initiating attaching volume" volumeID="10f299c8-993e-4ba5-86f3-2de28f480ae6" nodeID="3249e070-01f4-4f2f-ad68-aad70a1d3501"
I0722 14:40:03.704897       1 volumes.go:46] "CloudStack API call" command="ListVolumes" params={"id":"10f299c8-993e-4ba5-86f3-2de28f480ae6"}
I0722 14:40:03.731368       1 vms.go:13] "CloudStack API call" command="ListVirtualMachines" params={"id":"3249e070-01f4-4f2f-ad68-aad70a1d3501"}
I0722 14:40:03.778016       1 controller.go:462] "Attaching volume to node" volumeID="10f299c8-993e-4ba5-86f3-2de28f480ae6" nodeID="3249e070-01f4-4f2f-ad68-aad70a1d3501"
I0722 14:40:03.778425       1 volumes.go:103] "CloudStack API call" command="AttachVolume" params={"id":"10f299c8-993e-4ba5-86f3-2de28f480ae6","virtualmachineid":"3249e070-01f4-4f2f-ad68-aad70a1d3501"}
I0722 14:40:06.871095       1 controller.go:472] "Attached volume to node successfully" volumeID="10f299c8-993e-4ba5-86f3-2de28f480ae6" nodeID="3249e070-01f4-4f2f-ad68-aad70a1d3501"

Tested at Project level

Requires upstream changes to allow snapshot APIs for the kube-admin role

image image

Logs indicating that volume was successfully created from snapshot and attached to the node:

}
I0724 20:03:37.988477       1 snapshots.go:21] "CloudStack API call" command="ListSnapshots" params={"id":"e5d4111d-7fb0-4a60-9344-09bb5d6f6dae","projectid":"08eff2db-14eb-4a89-917a-986bf743cbe2"}
I0724 20:03:38.053380       1 controller.go:144] "PVC created with" size=1
I0724 20:03:38.053501       1 volumes.go:179] "CloudStack API call" command="CreateVolume" params={"name":"pvc-b0ebb701-6b61-4ae7-9dcd-ef39e5df99d5","projectid":"08eff2db-14eb-4a89-917a-986bf743cbe2","size":"1","snapshotid":"e5d4111d-7fb0-4a60-9344-09bb5d6f6dae","zoneid":"f4a2df97-71b4-4083-be19-4accadf9382c"}
I0724 20:03:40.383970       1 controller.go:414] "Initiating attaching volume" volumeID="d5164722-e6b0-4d6a-be02-18f945ee0009" nodeID="320bf70a-941c-4f61-94e4-a41504afa6fe"
I0724 20:03:40.384049       1 volumes.go:49] "CloudStack API call" command="ListVolumes" params={"id":"d5164722-e6b0-4d6a-be02-18f945ee0009","projectid":"08eff2db-14eb-4a89-917a-986bf743cbe2"}
I0724 20:03:40.415176       1 vms.go:16] "CloudStack API call" command="ListVirtualMachines" params={"id":"320bf70a-941c-4f61-94e4-a41504afa6fe","projectID":"08eff2db-14eb-4a89-917a-986bf743cbe2"}
I0724 20:03:40.481819       1 vms.go:31] "Returning VM" vmID="320bf70a-941c-4f61-94e4-a41504afa6fe" zoneID="f4a2df97-71b4-4083-be19-4accadf9382c"
I0724 20:03:40.481934       1 controller.go:459] "Attaching volume to node" volumeID="d5164722-e6b0-4d6a-be02-18f945ee0009" nodeID="320bf70a-941c-4f61-94e4-a41504afa6fe"
I0724 20:03:40.482463       1 volumes.go:111] "CloudStack API call" command="AttachVolume" params={"id":"d5164722-e6b0-4d6a-be02-18f945ee0009","virtualmachineid":"320bf70a-941c-4f61-94e4-a41504afa6fe"}
I0724 20:03:41.600488       1 controller.go:469] "Attached volume to node successfully" volumeID="d5164722-e6b0-4d6a-be02-18f945ee0009" nodeID="320bf70a-941c-4f61-94e4-a41504afa6fe"

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Pearl1594 Pearl1594 changed the title [WIP] Add support for Volume snapshot for CloudStack CSI driver Add support for Volume snapshot for CloudStack CSI driver Aug 8, 2025
@Pearl1594 Pearl1594 marked this pull request as ready for review August 12, 2025 13:22
Copy link
Member

@weizhouapache weizhouapache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants