Skip to content

Commit f19cd2a

Browse files
authored
Merge pull request #879 from andyzhangx/snapshot-mountOptions
feat: support mountOptions parameter in VolumeSnapshotClass
2 parents b175003 + b42674e commit f19cd2a

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

docs/driver-parameters.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ volumeAttributes.server | NFS Server address | domain name `nfs-server.default.s
2828
volumeAttributes.share | NFS share path | `/` | Yes |
2929
volumeAttributes.mountPermissions | mounted folder permissions. The default is `0`, if set as non-zero, driver will perform `chmod` after mount | | No |
3030

31+
### `VolumeSnapshotClass`
32+
33+
Name | Meaning | Available Value | Mandatory | Default value
34+
--- | --- | --- | --- | ---
35+
mountOptions | mount options separated by comma, e.g. `"nfsvers=4.1,sec=sys"` | | No | ""
36+
server | NFS Server address | domain name `nfs-server.default.svc.cluster.local` <br>or IP address `127.0.0.1` | Yes |
37+
share | NFS share path | `/` | Yes |
38+
3139
### Tips
3240
#### `subDir` parameter supports following pv/pvc metadata conversion
3341
> if `subDir` value contains following strings, it would be converted into corresponding pv/pvc name or namespace

pkg/nfs/controllerserver.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
376376
return nil, status.Errorf(codes.NotFound, "failed to create nfsSnapshot: %v", err)
377377
}
378378
snapVol := volumeFromSnapshot(snapshot)
379-
if err = cs.internalMount(ctx, snapVol, nil, nil); err != nil {
379+
if err = cs.internalMount(ctx, snapVol, req.GetParameters(), nil); err != nil {
380380
return nil, status.Errorf(codes.Internal, "failed to mount snapshot nfs server: %v", err)
381381
}
382382
defer func() {
@@ -392,7 +392,7 @@ func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
392392
return nil, err
393393
}
394394

395-
if err = cs.internalMount(ctx, srcVol, nil, nil); err != nil {
395+
if err = cs.internalMount(ctx, srcVol, req.GetParameters(), nil); err != nil {
396396
return nil, status.Errorf(codes.Internal, "failed to mount src nfs server: %v", err)
397397
}
398398
defer func() {
@@ -652,6 +652,8 @@ func newNFSSnapshot(name string, params map[string]string, vol *nfsVolume) (*nfs
652652
server = v
653653
case paramShare:
654654
baseDir = v
655+
case mountOptionsField:
656+
// no op
655657
default:
656658
return nil, status.Errorf(codes.InvalidArgument, "invalid parameter %q in snapshot storage class", k)
657659
}

pkg/nfs/controllerserver_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ func TestCreateSnapshot(t *testing.T) {
933933
req: &csi.CreateSnapshotRequest{
934934
SourceVolumeId: "nfs-server.default.svc.cluster.local#share#subdir#src-pv-name",
935935
Name: "snapshot-name",
936+
Parameters: map[string]string{"mountOptions": "nfsvers=4.1,sec=sys"},
936937
},
937938
expResp: &csi.CreateSnapshotResponse{
938939
Snapshot: &csi.Snapshot{
@@ -954,6 +955,15 @@ func TestCreateSnapshot(t *testing.T) {
954955
},
955956
expectErr: true,
956957
},
958+
{
959+
desc: "create snapshot with non supported parameters",
960+
req: &csi.CreateSnapshotRequest{
961+
SourceVolumeId: "nfs-server.default.svc.cluster.local#share#subdir#src-pv-name",
962+
Name: "snapshot-name",
963+
Parameters: map[string]string{"unknown": "value"},
964+
},
965+
expectErr: true,
966+
},
957967
}
958968
for _, test := range cases {
959969
t.Run(test.desc, func(t *testing.T) {

0 commit comments

Comments
 (0)