Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@WebberHuang1118
Copy link
Member

Solution:

HEP for Harvester CSI Snapshot Support

Related Issue(s):

#3778

@innobead innobead requested a review from brandboat September 22, 2025 02:36
Signed-off-by: Webber Huang <[email protected]>

Co-authored-by: Ivan Sim <[email protected]>
@WebberHuang1118
Copy link
Member Author

Hi @ihcsim,

Thanks for the feedback! I’ve replied to and applied your suggestions and questions—please take a look.

Snapshots created by the driver include essential metadata labels:
- `harvesterhci.io/snapHostSC`: Original storage class name
- `harvesterhci.io/snapHostStorage`: Original volume capacity
- `harvesterhci.io/snapHostVolumeMode`: Original volume mode (Block/Filesystem)
Copy link
Contributor

Choose a reason for hiding this comment

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

During snapshot restore, the volume mode can be derived from the volume snapshot content's .spec.sourceVolumeMode field.

Copy link
Member Author

Choose a reason for hiding this comment

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

This field may not be populated—it seems to depend on the CSI driver. These manifests are from my environment.

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotContent
metadata:
  name: snapcontent-a86c8a81-96ee-456a-b09b-0f8875a39c67
spec:
  deletionPolicy: Delete
  driver: driver.longhorn.io
  source:
    volumeHandle: pvc-9ae5d635-cd0a-4795-ae7f-b68e26bd850d
  volumeSnapshotClassName: longhorn-snapshot
  volumeSnapshotRef:
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    name: snapshot-057280cb-2346-4cb8-969a-9744037358c6
    namespace: default
    resourceVersion: "53038639"
    uid: a86c8a81-96ee-456a-b09b-0f8875a39c67
status:
  creationTime: 1758785089000000000
  readyToUse: true
  restoreSize: 2147483648
  snapshotHandle: snap://pvc-9ae5d635-cd0a-4795-ae7f-b68e26bd850d/snapshot-a86c8a81-96ee-456a-b09b-0f8875a39c67

and

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotContent
metadata:
  creationTimestamp: "2025-09-25T08:12:53Z"
  finalizers:
  - snapshot.storage.kubernetes.io/volumesnapshotcontent-bound-protection
  generation: 1
  name: snapcontent-cb6b8087-1fe5-4410-9d08-c5efca0a7fdd
  resourceVersion: "4417662"
  uid: 5e005c30-a1ef-4e57-bfce-a3750df40b80
spec:
  deletionPolicy: Delete
  driver: driver.harvesterhci.io
  source:
    volumeHandle: pvc-e5ced3a0-1537-4fab-9b74-9d70a6dd3900
  sourceVolumeMode: Filesystem
  volumeSnapshotClassName: harvester-snapshot
  volumeSnapshotRef:
    apiVersion: snapshot.storage.k8s.io/v1
    kind: VolumeSnapshot
    name: snapshot-fs-vol
    namespace: default
    resourceVersion: "4417147"
    uid: cb6b8087-1fe5-4410-9d08-c5efca0a7fdd
status:
  creationTime: 1758787988000000000
  readyToUse: true
  restoreSize: 1972171
  snapshotHandle: snapshot-cb6b8087-1fe5-4410-9d08-c5efca0a7fdd

Since the Harvester CSI driver still requires the annotation for the host StorageClass, I prefer to keep the current design.

Copy link
Member Author

@WebberHuang1118 WebberHuang1118 Sep 26, 2025

Choose a reason for hiding this comment

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

Update on why .spec.sourceVolumeMode isn’t always populated:

it’s set by the snapshot-controller only when the PreventVolumeModeConversion feature gate is enabled and the source PV defines volumeMode. See the relevant code in snapshot_controller.go (L775–L780).

The PreventVolumeModeConversion feature gate has been enabled by default since v7.0, as noted in the CHANGELOG 7.0.

- Enable prevent-volume-mode-conversion feature flag by default.
  
  Volume mode change will be rejected when creating a PVC from a VolumeSnapshot unless the AllowVolumeModeChange annotation has been set to true

Since Harvester v1.6.0 uses snapshotter v6.3.3, the PreventVolumeModeConversion feature gate is disabled by default. If we update Harvester’s snapshot-controller deployment with it enabled, .spec.sourceVolumeMode will then be populated whenever the source PV defines volumeMode:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: snapshot-controller
  namespace: kube-system
spec:
  template:
    spec:
      containers:
      - name: snapshot-controller
        image: registry.k8s.io/sig-storage/snapshot-controller:v6.3.3
        args:
        - --v=5
        - --leader-election=true
        - --prevent-volume-mode-conversion=true  # Added this line

All subsequent VSCs will be populated with .spec.sourceVolumeMode.

Back to the original discussion: since the presence of .spec.sourceVolumeMode in a VSC depends on the snapshot controller’s deployment, IMO, Harvester CSI shouldn’t rely on this field.

Instead, the Harvester CSI driver could leverage the label on the host CSI snapshot for more flexibility in determining the correct volume mode during snapshot restore. cc @Vicente-Cheng


Snapshots created by the driver include essential metadata labels:
- `harvesterhci.io/snapHostSC`: Original storage class name
- `harvesterhci.io/snapHostStorage`: Original volume capacity
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use the volume snapshot content's .status.restoreSize when restoring the snapshot to a PVC?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ditto, since the Harvester CSI driver still requires the annotation for the host StorageClass, I prefer to keep the current design.

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