Skip to content

Commit 835552e

Browse files
authored
Merge pull request kubernetes#80191 from davidz627/fix/mountStage
Add passthrough for MountOptions for NodeStageVolume for CSI
2 parents 683e405 + b6a38d7 commit 835552e

File tree

8 files changed

+51
-12
lines changed

8 files changed

+51
-12
lines changed

pkg/volume/csi/csi_attacher.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
390390
accessMode = spec.PersistentVolume.Spec.AccessModes[0]
391391
}
392392

393+
var mountOptions []string
394+
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.MountOptions != nil {
395+
mountOptions = spec.PersistentVolume.Spec.MountOptions
396+
}
397+
393398
fsType := csiSource.FSType
394399
err = csi.NodeStageVolume(ctx,
395400
csiSource.VolumeHandle,
@@ -398,7 +403,8 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
398403
fsType,
399404
accessMode,
400405
nodeStageSecrets,
401-
csiSource.VolumeAttributes)
406+
csiSource.VolumeAttributes,
407+
mountOptions)
402408

403409
if err != nil {
404410
return err

pkg/volume/csi/csi_attacher_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io/ioutil"
2222
"os"
2323
"path/filepath"
24+
"reflect"
2425
"sync"
2526
"testing"
2627
"time"
@@ -1032,6 +1033,14 @@ func TestAttacherMountDevice(t *testing.T) {
10321033
stageUnstageSet: true,
10331034
spec: volume.NewSpecFromPersistentVolume(makeTestPV(pvName, 10, testDriver, "test-vol1"), false),
10341035
},
1036+
{
1037+
testName: "normal PV with mount options",
1038+
volName: "test-vol1",
1039+
devicePath: "path1",
1040+
deviceMountPath: "path2",
1041+
stageUnstageSet: true,
1042+
spec: volume.NewSpecFromPersistentVolume(makeTestPVWithMountOptions(pvName, 10, testDriver, "test-vol1", []string{"test-op"}), false),
1043+
},
10351044
{
10361045
testName: "no vol name",
10371046
volName: "",
@@ -1141,6 +1150,9 @@ func TestAttacherMountDevice(t *testing.T) {
11411150
if vol.Path != tc.deviceMountPath {
11421151
t.Errorf("expected mount path: %s. got: %s", tc.deviceMountPath, vol.Path)
11431152
}
1153+
if !reflect.DeepEqual(vol.MountFlags, tc.spec.PersistentVolume.Spec.MountOptions) {
1154+
t.Errorf("expected mount options: %v, got: %v", tc.spec.PersistentVolume.Spec.MountOptions, vol.MountFlags)
1155+
}
11441156
}
11451157
}
11461158
}

pkg/volume/csi/csi_block.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ func (m *csiBlockMapper) stageVolumeForBlock(
134134
fsTypeBlockName,
135135
accessMode,
136136
nodeStageSecrets,
137-
csiSource.VolumeAttributes)
137+
csiSource.VolumeAttributes,
138+
nil /* MountOptions */)
138139

139140
if err != nil {
140141
klog.Error(log("blockMapper.stageVolumeForBlock failed: %v", err))

pkg/volume/csi/csi_client.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type csiClient interface {
7070
accessMode api.PersistentVolumeAccessMode,
7171
secrets map[string]string,
7272
volumeContext map[string]string,
73+
mountOptions []string,
7374
) error
7475

7576
NodeGetVolumeStats(
@@ -507,6 +508,7 @@ func (c *csiDriverClient) NodeStageVolume(ctx context.Context,
507508
accessMode api.PersistentVolumeAccessMode,
508509
secrets map[string]string,
509510
volumeContext map[string]string,
511+
mountOptions []string,
510512
) error {
511513
klog.V(4).Info(log("calling NodeStageVolume rpc [volid=%s,staging_target_path=%s]", volID, stagingTargetPath))
512514
if volID == "" {
@@ -517,9 +519,9 @@ func (c *csiDriverClient) NodeStageVolume(ctx context.Context,
517519
}
518520

519521
if c.nodeV1ClientCreator != nil {
520-
return c.nodeStageVolumeV1(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext)
522+
return c.nodeStageVolumeV1(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext, mountOptions)
521523
} else if c.nodeV0ClientCreator != nil {
522-
return c.nodeStageVolumeV0(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext)
524+
return c.nodeStageVolumeV0(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext, mountOptions)
523525
}
524526

525527
return fmt.Errorf("failed to call NodeStageVolume. Both nodeV1ClientCreator and nodeV0ClientCreator are nil")
@@ -534,6 +536,7 @@ func (c *csiDriverClient) nodeStageVolumeV1(
534536
accessMode api.PersistentVolumeAccessMode,
535537
secrets map[string]string,
536538
volumeContext map[string]string,
539+
mountOptions []string,
537540
) error {
538541
nodeClient, closer, err := c.nodeV1ClientCreator(c.addr)
539542
if err != nil {
@@ -561,7 +564,8 @@ func (c *csiDriverClient) nodeStageVolumeV1(
561564
} else {
562565
req.VolumeCapability.AccessType = &csipbv1.VolumeCapability_Mount{
563566
Mount: &csipbv1.VolumeCapability_MountVolume{
564-
FsType: fsType,
567+
FsType: fsType,
568+
MountFlags: mountOptions,
565569
},
566570
}
567571
}
@@ -579,6 +583,7 @@ func (c *csiDriverClient) nodeStageVolumeV0(
579583
accessMode api.PersistentVolumeAccessMode,
580584
secrets map[string]string,
581585
volumeContext map[string]string,
586+
mountOptions []string,
582587
) error {
583588
nodeClient, closer, err := c.nodeV0ClientCreator(c.addr)
584589
if err != nil {
@@ -606,7 +611,8 @@ func (c *csiDriverClient) nodeStageVolumeV0(
606611
} else {
607612
req.VolumeCapability.AccessType = &csipbv0.VolumeCapability_Mount{
608613
Mount: &csipbv0.VolumeCapability_MountVolume{
609-
FsType: fsType,
614+
FsType: fsType,
615+
MountFlags: mountOptions,
610616
},
611617
}
612618
}

pkg/volume/csi/csi_client_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ func (c *fakeCsiDriverClient) NodeStageVolume(ctx context.Context,
175175
accessMode api.PersistentVolumeAccessMode,
176176
secrets map[string]string,
177177
volumeContext map[string]string,
178+
mountOptions []string,
178179
) error {
179180
c.t.Log("calling fake.NodeStageVolume...")
180181
req := &csipbv1.NodeStageVolumeRequest{
@@ -187,7 +188,8 @@ func (c *fakeCsiDriverClient) NodeStageVolume(ctx context.Context,
187188
},
188189
AccessType: &csipbv1.VolumeCapability_Mount{
189190
Mount: &csipbv1.VolumeCapability_MountVolume{
190-
FsType: fsType,
191+
FsType: fsType,
192+
MountFlags: mountOptions,
191193
},
192194
},
193195
},
@@ -448,10 +450,11 @@ func TestClientNodeStageVolume(t *testing.T) {
448450
stagingTargetPath string
449451
fsType string
450452
secrets map[string]string
453+
mountOptions []string
451454
mustFail bool
452455
err error
453456
}{
454-
{name: "test ok", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "ext4"},
457+
{name: "test ok", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "ext4", mountOptions: []string{"unvalidated"}},
455458
{name: "missing volID", stagingTargetPath: "/test/path", mustFail: true},
456459
{name: "missing target path", volID: "vol-test", mustFail: true},
457460
{name: "bad fs", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "badfs", mustFail: true},
@@ -479,6 +482,7 @@ func TestClientNodeStageVolume(t *testing.T) {
479482
api.ReadWriteOnce,
480483
tc.secrets,
481484
map[string]string{"attr0": "val0"},
485+
tc.mountOptions,
482486
)
483487
checkErr(t, tc.mustFail, err)
484488

pkg/volume/csi/csi_util_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ func TestMain(m *testing.M) {
4242
os.Exit(m.Run())
4343
}
4444

45+
func makeTestPVWithMountOptions(name string, sizeGig int, driverName, volID string, mountOptions []string) *api.PersistentVolume {
46+
pv := makeTestPV(name, sizeGig, driverName, volID)
47+
pv.Spec.MountOptions = mountOptions
48+
return pv
49+
}
50+
4551
func makeTestPV(name string, sizeGig int, driverName, volID string) *api.PersistentVolume {
4652
return &api.PersistentVolume{
4753
ObjectMeta: meta.ObjectMeta{

pkg/volume/csi/fake/fake_client.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,23 @@ func (f *NodeClient) NodeStageVolume(ctx context.Context, req *csipb.NodeStageVo
189189
return nil, errors.New("missing staging target path")
190190
}
191191

192+
csiVol := CSIVolume{
193+
Path: req.GetStagingTargetPath(),
194+
VolumeContext: req.GetVolumeContext(),
195+
}
196+
192197
fsType := ""
193198
fsTypes := "block|ext4|xfs|zfs"
194199
mounted := req.GetVolumeCapability().GetMount()
195200
if mounted != nil {
196201
fsType = mounted.GetFsType()
202+
csiVol.MountFlags = mounted.GetMountFlags()
197203
}
198204
if !strings.Contains(fsTypes, fsType) {
199205
return nil, errors.New("invalid fstype")
200206
}
201207

202-
f.nodeStagedVolumes[req.GetVolumeId()] = CSIVolume{
203-
Path: req.GetStagingTargetPath(),
204-
VolumeContext: req.GetVolumeContext(),
205-
}
208+
f.nodeStagedVolumes[req.GetVolumeId()] = csiVol
206209
return &csipb.NodeStageVolumeResponse{}, nil
207210
}
208211

test/e2e/storage/drivers/csi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ func InitGcePDCSIDriver() testsuites.TestDriver {
347347
"ext4",
348348
"xfs",
349349
),
350+
SupportedMountOption: sets.NewString("debug", "nouid32"),
350351
Capabilities: map[testsuites.Capability]bool{
351352
testsuites.CapPersistence: true,
352353
testsuites.CapFsGroup: true,

0 commit comments

Comments
 (0)