Repository navigation
Conversation
CreateSnapshotResponse and ListSnapshots entries never set SizeBytes, so VolumeSnapshot.status.restoreSize was always 0. Kubernetes uses this value to show the minimum restore size and to reject PVCs that are too small. Use the snapshot virtualsize from CloudStack, falling back to the source volume size. Also populate Size/CreatedAt in GetSnapshotByID and Size in GetSnapshotByName so callers see the real snapshot size.
CloudStack creates a volume from a snapshot at the snapshot's size and ignores a larger requested size. The driver returned that smaller capacity, so external-provisioner rejected it with 'created volume capacity X less than requested capacity Y', deleted the volume and retried forever. After creating the volume, resize it to the requested size when it is smaller. If the resize fails, delete the undersized volume and return an error. The node plugin already grows the filesystem on NodeStage.
CreateSnapshot always called CloudStack createSnapshot, so a retry from csi-snapshotter (e.g. after a timeout) created a duplicate snapshot. The CSI spec requires CreateSnapshot to return the existing snapshot when one with the same name and source volume already exists. Look up the snapshot by name first; return it if it belongs to the same volume, return AlreadyExists if it belongs to a different volume, and only create a new snapshot when none exists.
… state A timed-out CreateSnapshot keeps running against CloudStack, so a retry could miss the in-progress snapshot and create a duplicate. Hold a per-name lock for the call and return Aborted to concurrent calls. CreateSnapshot and ListSnapshots always returned ReadyToUse: true, even while CloudStack was still creating or backing up the snapshot. Report ReadyToUse=false until the snapshot leaves Allocated/Creating/ CreatedOnPrimary/BackingUp/Copying, and an error for the Error state.
If a snapshot was destroyed outside the driver, or an earlier delete completed after the RPC timed out, CloudStack returns errorcode 431 '... is already destroyed'. That was not mapped to ErrNotFound, so DeleteSnapshot returned Internal and the VolumeSnapshotContent (and its VolumeSnapshot) could never be deleted. The CSI spec requires DeleteSnapshot to succeed when the snapshot no longer exists.
d9e0141 to
ee5d32c
Compare
…elete as done CloudStack returns error 4350 (InvalidParameterValueException) both for an unknown ID and for refusals such as deleting a volume that is still attached. DeleteVolume mapped every 4350 to ErrNotFound, so a refused delete was reported as success: Kubernetes removed the PV and the CloudStack volume was left behind with nothing tracking it. DeleteSnapshot matched error text instead, which missed messages such as 'unable to find a snapshot with id N', leaving VolumeSnapshots stuck. The cloud client now returns delete errors unchanged. After a failed delete, the controller looks the volume or snapshot up by ID and only reports success if it is gone or already destroyed. A volume that is still attached returns FailedPrecondition; anything else returns the CloudStack error.
|
Added a commit (8725abd) that fixes a silent volume leak in DeleteVolume (#45): CloudStack's error 4350 also covers refusals such as "volume is attached", which the driver reported as success. Failed deletes of volumes and snapshots are now checked by ID, which also replaces the error-text matching from #41. Details are in item 7 of the description. Tested: attached-volume delete now returns FailedPrecondition instead of orphaning the volume, and the regression tests all pass. |
|
@Pearl1594 any chance you can take look? |
|
@mw-0 Will definitely have a look and review and test it. Thanks! |
There was a problem hiding this comment.
🟡 Changes recommended
Snapshot handling still permits restores above capacity limits, blocks retries after failed resize cleanup, and can report incorrect snapshot readiness and size.
4 open issues
What changed in this PR
Updates the CloudStack CSI driver to improve snapshot metadata, restore sizing, and retry handling for snapshot creation and resource deletion.
Changes:
- Reports snapshot size and readiness, reuses existing snapshots, and serializes same-name creation calls.
- Expands restored volumes to the requested size and attempts cleanup after resize failures.
- Verifies resource state after failed deletions and adds focused regression tests.
| File | Description |
|---|---|
pkg/driver/controller.go |
Implements snapshot status, idempotency, restore resizing, and delete verification. |
pkg/driver/controller_snapshot_size_test.go |
Checks that snapshot creation reports a nonzero size. |
pkg/driver/controller_snapshot_ready_test.go |
Tests readiness mapping for snapshot states. |
pkg/driver/controller_snapshot_idempotent_test.go |
Checks that repeated creation returns the same snapshot ID. |
pkg/driver/controller_restore_resize_test.go |
Tests resize, no-op, and resize-error paths. |
pkg/driver/controller_delete_test.go |
Tests delete outcomes based on follow-up resource lookups. |
pkg/cloud/volumes.go |
Maps volume state and preserves raw deletion errors. |
pkg/cloud/snapshots.go |
Populates snapshot metadata and preserves raw deletion errors. |
pkg/cloud/cloud.go |
Adds state fields to volume and snapshot models. |
Review effort: Balanced
| switch state { | ||
| case "Allocated", "Creating", "CreatedOnPrimary", "BackingUp", "Copying": | ||
| return false | ||
| default: | ||
| return true |
| sizeInGB = snapshotSizeGiB | ||
| } |
| if delErr := cs.connector.DeleteVolume(ctx, vol.ID); delErr != nil { | ||
| logger.Error(delErr, "Failed to delete undersized volume after resize failure", "volumeID", vol.ID) | ||
| } |
| Snapshot: &csi.Snapshot{ | ||
| SnapshotId: snap.ID, | ||
| SourceVolumeId: snap.VolumeID, | ||
| SizeBytes: snap.Size, |
There was a problem hiding this comment.
Functionality wise, works well - LGTM. Can you please have a look at the copilot comments @mw-0
Did the following tests:
- Provisioned a PVC, attached it to a pod, and wrote data.
- A VolumeSnapshot reached readyToUse: true with restoreSize 2Gi.
- Restored at the same size (2Gi). Data intact.
- Restored into a larger PVC (4Gi). Data intact
- Online expand from 2Gi to 3Gi with the pod running.
- Deleted the snapshot. The restored PVCs were unaffected.
- Deleted the PVCs. The PVs were removed
- A restore smaller than the snapshot (1Gi from 3Gi) was rejected - while (acs driver) code allows it external provisioner prevents this
- Deleted the source PVC while snapshots existed, then restored from a snapshot. Data intact.

Fixes #37, Fixes #38, Fixes #39, Fixes #40, Fixes #41 Fixes #45
Description of changes:
Each change is a separate commit.
Report snapshot size (#37). CreateSnapshot and ListSnapshots set SizeBytes, using CloudStack's virtualsize and falling back to the source volume's size. GetSnapshotByID and GetSnapshotByName now populate Size (and GetSnapshotByID populates CreatedAt).
Resize restored volumes to the requested size (#38). After CreateVolumeFromSnapshot, a volume smaller than requested is grown with ExpandVolume. If the resize fails, the undersized volume is deleted so the provisioner's retry starts clean.
Make CreateSnapshot idempotent (#39). The snapshot is looked up by name first:
if it exists for the same volume, it is returned;
if it exists for a different volume, the call returns AlreadyExists;
otherwise a new snapshot is created.
The lookup uses the client's default options, so it respects the project ID.
Move the restore path into createVolumeFromSnapshot. No behaviour change; this keeps CreateVolume within the nestif limit, and the now-unused //nolint:gocognit is removed.
Serialize CreateSnapshot per name and report ReadyToUse from the snapshot state (#39, #40).
A per-name lock returns Aborted to a concurrent call while the first is still running against CloudStack, so a retry can't race it.
cloud.Snapshot gains a State field. ReadyToUse is false while the snapshot is in progress, and a snapshot in Error state is returned as an error.
Treat already-destroyed snapshots as deleted (#41). DeleteSnapshot maps "is already destroyed" to not-found, so it succeeds idempotently.
#45
Check that volumes and snapshots are gone before treating a failed delete as done (#41, #45). After a failed delete, the controller looks the object up by ID: gone or already destroyed means success, an attached volume returns FailedPrecondition, anything else returns the CloudStack error. This replaces the error-text matching from item 6, which missed unable to find a snapshot with id N.
New unit tests:
TestCreateSnapshotReportsSize
TestGrowVolumeFromSnapshot (resize, no-op and failure paths)
TestCreateSnapshotIsIdempotent
TestIsSnapshotReady
TestIsSnapshotGoneError
Testing performed:
golangci-lint run ./... (v1.63.4, repo config), make test and make test-sanity all pass.
Lab: CloudStack 4.23(KVM, NFS), a CKS cluster on Kubernetes 1.37.0. I ran the same end-to-end script against the stock image and against this branch
Additional stress test with csi-snapshotter --timeout=5s:
Stock: 6 duplicate snapshots, and the VolumeSnapshot never became ready.
This PR: one snapshot, READYTOUSE false until CloudStack showed BackedUp, and retries returned the existing snapshot.
If you want a bash script to run against fixed and main releases I can upload it.