Skip to content

Add subDir parameter support in VolumeSnapshotClass #869

Open
@bells17

Description

@bells17

Is your feature request related to a problem?/Why is this needed**

Currently, the subDir parameter is supported in StorageClass, allowing PVCs to be created inside a specific folder. This is particularly useful for organizing and separating data by directories in the NFS CSI driver.

However, when creating snapshots via VolumeSnapshot, there is no option to specify subDir. As a result, snapshots are always stored in the root directory of the NFS server, with names like snapshot-<snapshotUID>.
https://github.com/kubernetes-csi/external-snapshotter/blob/v8.2.0/pkg/sidecar-controller/csi_handler.go#L87

Describe the solution you'd like in detail

VolumeSnapshotClass should support the subDir parameter, just like StorageClass. This would allow snapshots to be stored in the same subdirectory as their corresponding PVCs when using the NFS CSI driver.

Since VolumeSnapshotClass already has a parameters field, this change would require modifications to the CSI driver and would not impact any Kubernetes core components or external-snapshotter behavior.

Proposed Parameter Handling:

The subDir parameter should be processed within the CSI driver to determine the directory where snapshots are stored. Below is an example configuration:

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
name: my-snapshot-class
parameters:
subDir: "snapshots"
  • If subDir is specified, the snapshot will be stored inside the given subdirectory.
  • If not specified, the default behavior (storing in the root directory) remains unchanged.

Describe alternatives you've considered

  • Manually moving snapshots to the desired subdirectory after creation, which is not ideal due to automation and access control limitations. Additionally, the VolumeSnapshotContent.status.snapshotHandle would also need to be manually updated, which is not supported by Kubernetes and can lead to inconsistencies.

Additional context

This feature would be particularly beneficial for this CSI driver, where organizing snapshots in specific directories can improve manageability. Allowing users to specify subDir in VolumeSnapshotClass ensures consistency in snapshot placement and improves manageability.

Additionally, modifying subDir does not affect existing snapshots. Since parameters in VolumeSnapshotClass cannot be modified after creation, users must create a new VolumeSnapshotClass with the desired subDir. Moreover, the snapshotHandle stored in VolumeSnapshotContent.status includes folder information, ensuring that restoring snapshots remains unaffected by subDir changes.

Expected Directory Structure Change

Current Behavior:

/nfs-root/snapshot-<snapshotUID>

Proposed Behavior with subDir: snapshots:

/nfs-root/snapshots/snapshot-<snapshotUID>

Metadata

Metadata

Assignees

Labels

lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions