Skip to content

Commit 010fbb4

Browse files
committed
feat: add mountOptions parameter for inline volume
1 parent 6028557 commit 010fbb4

File tree

9 files changed

+34
-26
lines changed

9 files changed

+34
-26
lines changed

charts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The following table lists the configurable parameters of the latest NFS CSI Driv
4040
| `driver.name` | alternative driver name | `nfs.csi.k8s.io` |
4141
| `driver.mountPermissions` | mounted folder permissions name | `0777`
4242
| `feature.enableFSGroupPolicy` | enable `fsGroupPolicy` on a k8s 1.20+ cluster | `false` |
43-
| `feature.enableInlineVolume` | enable inline volume | `true` |
43+
| `feature.enableInlineVolume` | enable inline volume | `false` |
4444
| `image.nfs.repository` | csi-driver-nfs image | `mcr.microsoft.com/k8s/csi/nfs-csi` |
4545
| `image.nfs.tag` | csi-driver-nfs image tag | `latest` |
4646
| `image.nfs.pullPolicy` | csi-driver-nfs image pull policy | `IfNotPresent` |
1 Byte
Binary file not shown.

charts/latest/csi-driver-nfs/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ driver:
3030

3131
feature:
3232
enableFSGroupPolicy: false
33-
enableInlineVolume: true
33+
enableInlineVolume: false
3434

3535
controller:
3636
name: csi-nfs-controller

deploy/example/nginx-pod-inline-volume.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,6 @@ spec:
2121
csi:
2222
driver: nfs.csi.k8s.io
2323
volumeAttributes:
24-
server: nfs-server.default.svc.cluster.local # required
25-
share: / # required
24+
server: nfs-server.default.svc.cluster.local # required
25+
share: / # required
26+
mountOptions: "nfsvers=4.1" # optional

pkg/nfs/nodeserver.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type NodeServer struct {
3838

3939
// NodePublishVolume mount the volume
4040
func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
41-
if req.GetVolumeCapability() == nil {
41+
volCap := req.GetVolumeCapability()
42+
if volCap == nil {
4243
return nil, status.Error(codes.InvalidArgument, "Volume capability missing in request")
4344
}
4445
volumeID := req.GetVolumeId()
@@ -49,6 +50,10 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
4950
if len(targetPath) == 0 {
5051
return nil, status.Error(codes.InvalidArgument, "Target path not provided")
5152
}
53+
mountOptions := volCap.GetMount().GetMountFlags()
54+
if req.GetReadonly() {
55+
mountOptions = append(mountOptions, "ro")
56+
}
5257

5358
var server, baseDir string
5459
for k, v := range req.GetVolumeContext() {
@@ -57,6 +62,10 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
5762
server = v
5863
case paramShare:
5964
baseDir = v
65+
case mountOptionsField:
66+
if v != "" {
67+
mountOptions = append(mountOptions, v)
68+
}
6069
}
6170
}
6271

@@ -83,11 +92,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8392
return &csi.NodePublishVolumeResponse{}, nil
8493
}
8594

86-
mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags()
87-
if req.GetReadonly() {
88-
mountOptions = append(mountOptions, "ro")
89-
}
90-
9195
klog.V(2).Infof("NodePublishVolume: volumeID(%v) source(%s) targetPath(%s) mountflags(%v)", volumeID, source, targetPath, mountOptions)
9296
err = ns.mounter.Mount(source, targetPath, "nfs", mountOptions)
9397
if err != nil {

test/e2e/dynamic_provisioning_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
275275
}
276276

277277
test := testsuites.DynamicallyProvisionedInlineVolumeTest{
278-
CSIDriver: testDriver,
279-
Pods: pods,
280-
Server: nfsServerAddress,
281-
Share: nfsShare,
282-
ReadOnly: false,
278+
CSIDriver: testDriver,
279+
Pods: pods,
280+
Server: nfsServerAddress,
281+
Share: nfsShare,
282+
MountOptions: "nfsvers=4.1",
283+
ReadOnly: false,
283284
}
284285
test.Run(cs, ns)
285286
})

test/e2e/testsuites/dynamically_provisioned_inline_volume.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ import (
2727
// Waiting for the PV provisioner to create an inline volume
2828
// Testing if the Pod(s) Cmd is run with a 0 exit code
2929
type DynamicallyProvisionedInlineVolumeTest struct {
30-
CSIDriver driver.DynamicPVTestDriver
31-
Pods []PodDetails
32-
Server string
33-
Share string
34-
ReadOnly bool
30+
CSIDriver driver.DynamicPVTestDriver
31+
Pods []PodDetails
32+
Server string
33+
Share string
34+
MountOptions string
35+
ReadOnly bool
3536
}
3637

3738
func (t *DynamicallyProvisionedInlineVolumeTest) Run(client clientset.Interface, namespace *v1.Namespace) {
3839
for _, pod := range t.Pods {
3940
var tpod *TestPod
4041
var cleanup []func()
41-
tpod, cleanup = pod.SetupWithCSIInlineVolumes(client, namespace, t.CSIDriver, t.Server, t.Share, t.ReadOnly)
42+
tpod, cleanup = pod.SetupWithCSIInlineVolumes(client, namespace, t.CSIDriver, t.Server, t.Share, t.MountOptions, t.ReadOnly)
4243
// defer must be called here for resources not get removed before using them
4344
for i := range cleanup {
4445
defer cleanup[i]()

test/e2e/testsuites/specs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ func (pod *PodDetails) SetupWithDynamicVolumes(client clientset.Interface, names
123123
return tpod, cleanupFuncs
124124
}
125125

126-
func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, server, share string, readOnly bool) (*TestPod, []func()) {
126+
func (pod *PodDetails) SetupWithCSIInlineVolumes(client clientset.Interface, namespace *v1.Namespace, csiDriver driver.DynamicPVTestDriver, server, share, mountOptions string, readOnly bool) (*TestPod, []func()) {
127127
tpod := NewTestPod(client, namespace, pod.Cmd)
128128
cleanupFuncs := make([]func(), 0)
129129
for n, v := range pod.Volumes {
130-
tpod.SetupCSIInlineVolume(fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), server, share, readOnly)
130+
tpod.SetupCSIInlineVolume(fmt.Sprintf("%s%d", v.VolumeMount.NameGenerate, n+1), fmt.Sprintf("%s%d", v.VolumeMount.MountPathGenerate, n+1), server, share, mountOptions, readOnly)
131131
}
132132
return tpod, cleanupFuncs
133133
}

test/e2e/testsuites/testsuites.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ func (t *TestPod) SetupVolumeMountWithSubpath(pvc *v1.PersistentVolumeClaim, nam
596596
t.pod.Spec.Volumes = append(t.pod.Spec.Volumes, volume)
597597
}
598598

599-
func (t *TestPod) SetupCSIInlineVolume(name, mountPath, server, share string, readOnly bool) {
599+
func (t *TestPod) SetupCSIInlineVolume(name, mountPath, server, share, mountOptions string, readOnly bool) {
600600
volumeMount := v1.VolumeMount{
601601
Name: name,
602602
MountPath: mountPath,
@@ -610,8 +610,9 @@ func (t *TestPod) SetupCSIInlineVolume(name, mountPath, server, share string, re
610610
CSI: &v1.CSIVolumeSource{
611611
Driver: nfs.DefaultDriverName,
612612
VolumeAttributes: map[string]string{
613-
"server": server,
614-
"share": share,
613+
"server": server,
614+
"share": share,
615+
"mountOptions": mountOptions,
615616
},
616617
ReadOnly: &readOnly,
617618
},

0 commit comments

Comments
 (0)