Merge pull request #879 from andyzhangx/snapshot-mountOptions

feat: support mountOptions parameter in VolumeSnapshotClass
This commit is contained in:
Andy Zhang 2025-03-18 11:20:01 +08:00 committed by GitHub
commit f19cd2a268
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 2 deletions

View File

@ -28,6 +28,14 @@ volumeAttributes.server | NFS Server address | domain name `nfs-server.default.s
volumeAttributes.share | NFS share path | `/` | Yes | volumeAttributes.share | NFS share path | `/` | Yes |
volumeAttributes.mountPermissions | mounted folder permissions. The default is `0`, if set as non-zero, driver will perform `chmod` after mount | | No | volumeAttributes.mountPermissions | mounted folder permissions. The default is `0`, if set as non-zero, driver will perform `chmod` after mount | | No |
### `VolumeSnapshotClass`
Name | Meaning | Available Value | Mandatory | Default value
--- | --- | --- | --- | ---
mountOptions | mount options separated by comma, e.g. `"nfsvers=4.1,sec=sys"` | | No | ""
server | NFS Server address | domain name `nfs-server.default.svc.cluster.local` <br>or IP address `127.0.0.1` | Yes |
share | NFS share path | `/` | Yes |
### Tips ### Tips
#### `subDir` parameter supports following pv/pvc metadata conversion #### `subDir` parameter supports following pv/pvc metadata conversion
> if `subDir` value contains following strings, it would be converted into corresponding pv/pvc name or namespace > if `subDir` value contains following strings, it would be converted into corresponding pv/pvc name or namespace

View File

@ -376,7 +376,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
return nil, status.Errorf(codes.NotFound, "failed to create nfsSnapshot: %v", err) return nil, status.Errorf(codes.NotFound, "failed to create nfsSnapshot: %v", err)
} }
snapVol := volumeFromSnapshot(snapshot) snapVol := volumeFromSnapshot(snapshot)
if err = cs.internalMount(ctx, snapVol, nil, nil); err != nil { if err = cs.internalMount(ctx, snapVol, req.GetParameters(), nil); err != nil {
return nil, status.Errorf(codes.Internal, "failed to mount snapshot nfs server: %v", err) return nil, status.Errorf(codes.Internal, "failed to mount snapshot nfs server: %v", err)
} }
defer func() { defer func() {
@ -392,7 +392,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
return nil, err return nil, err
} }
if err = cs.internalMount(ctx, srcVol, nil, nil); err != nil { if err = cs.internalMount(ctx, srcVol, req.GetParameters(), nil); err != nil {
return nil, status.Errorf(codes.Internal, "failed to mount src nfs server: %v", err) return nil, status.Errorf(codes.Internal, "failed to mount src nfs server: %v", err)
} }
defer func() { defer func() {
@ -652,6 +652,8 @@ func newNFSSnapshot(name string, params map[string]string, vol *nfsVolume) (*nfs
server = v server = v
case paramShare: case paramShare:
baseDir = v baseDir = v
case mountOptionsField:
// no op
default: default:
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in snapshot storage class", k) return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in snapshot storage class", k)
} }

View File

@ -933,6 +933,7 @@ func TestCreateSnapshot(t *testing.T) {
req: &csi.CreateSnapshotRequest{ req: &csi.CreateSnapshotRequest{
SourceVolumeId: "nfs-server.default.svc.cluster.local#share#subdir#src-pv-name", SourceVolumeId: "nfs-server.default.svc.cluster.local#share#subdir#src-pv-name",
Name: "snapshot-name", Name: "snapshot-name",
Parameters: map[string]string{"mountOptions": "nfsvers=4.1,sec=sys"},
}, },
expResp: &csi.CreateSnapshotResponse{ expResp: &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{ Snapshot: &csi.Snapshot{
@ -954,6 +955,15 @@ func TestCreateSnapshot(t *testing.T) {
}, },
expectErr: true, expectErr: true,
}, },
{
desc: "create snapshot with non supported parameters",
req: &csi.CreateSnapshotRequest{
SourceVolumeId: "nfs-server.default.svc.cluster.local#share#subdir#src-pv-name",
Name: "snapshot-name",
Parameters: map[string]string{"unknown": "value"},
},
expectErr: true,
},
} }
for _, test := range cases { for _, test := range cases {
t.Run(test.desc, func(t *testing.T) { t.Run(test.desc, func(t *testing.T) {