Merge pull request #80328 from davidz627/automated-cherry-pick-of-#80191-upstream-release-1.15

Automated cherry pick of #80191: Add passthrough for MountOptions for NodeStageVolume for
k3s-v1.15.3
Kubernetes Prow Robot 2019-08-07 00:52:51 -07:00 committed by GitHub
commit dda8703d20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 12 deletions

View File

@ -383,6 +383,11 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
accessMode = spec.PersistentVolume.Spec.AccessModes[0] accessMode = spec.PersistentVolume.Spec.AccessModes[0]
} }
var mountOptions []string
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.MountOptions != nil {
mountOptions = spec.PersistentVolume.Spec.MountOptions
}
fsType := csiSource.FSType fsType := csiSource.FSType
err = csi.NodeStageVolume(ctx, err = csi.NodeStageVolume(ctx,
csiSource.VolumeHandle, csiSource.VolumeHandle,
@ -391,7 +396,8 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
fsType, fsType,
accessMode, accessMode,
nodeStageSecrets, nodeStageSecrets,
csiSource.VolumeAttributes) csiSource.VolumeAttributes,
mountOptions)
if err != nil { if err != nil {
return err return err

View File

@ -21,6 +21,7 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"reflect"
"sync" "sync"
"testing" "testing"
"time" "time"
@ -1032,6 +1033,14 @@ func TestAttacherMountDevice(t *testing.T) {
stageUnstageSet: true, stageUnstageSet: true,
spec: volume.NewSpecFromPersistentVolume(makeTestPV(pvName, 10, testDriver, "test-vol1"), false), spec: volume.NewSpecFromPersistentVolume(makeTestPV(pvName, 10, testDriver, "test-vol1"), false),
}, },
{
testName: "normal PV with mount options",
volName: "test-vol1",
devicePath: "path1",
deviceMountPath: "path2",
stageUnstageSet: true,
spec: volume.NewSpecFromPersistentVolume(makeTestPVWithMountOptions(pvName, 10, testDriver, "test-vol1", []string{"test-op"}), false),
},
{ {
testName: "no vol name", testName: "no vol name",
volName: "", volName: "",
@ -1141,6 +1150,9 @@ func TestAttacherMountDevice(t *testing.T) {
if vol.Path != tc.deviceMountPath { if vol.Path != tc.deviceMountPath {
t.Errorf("expected mount path: %s. got: %s", tc.deviceMountPath, vol.Path) t.Errorf("expected mount path: %s. got: %s", tc.deviceMountPath, vol.Path)
} }
if !reflect.DeepEqual(vol.MountFlags, tc.spec.PersistentVolume.Spec.MountOptions) {
t.Errorf("expected mount options: %v, got: %v", tc.spec.PersistentVolume.Spec.MountOptions, vol.MountFlags)
}
} }
} }
} }

View File

@ -134,7 +134,8 @@ func (m *csiBlockMapper) stageVolumeForBlock(
fsTypeBlockName, fsTypeBlockName,
accessMode, accessMode,
nodeStageSecrets, nodeStageSecrets,
csiSource.VolumeAttributes) csiSource.VolumeAttributes,
nil /* MountOptions */)
if err != nil { if err != nil {
klog.Error(log("blockMapper.stageVolumeForBlock failed: %v", err)) klog.Error(log("blockMapper.stageVolumeForBlock failed: %v", err))

View File

@ -72,6 +72,7 @@ type csiClient interface {
accessMode api.PersistentVolumeAccessMode, accessMode api.PersistentVolumeAccessMode,
secrets map[string]string, secrets map[string]string,
volumeContext map[string]string, volumeContext map[string]string,
mountOptions []string,
) error ) error
NodeGetVolumeStats( NodeGetVolumeStats(
@ -515,6 +516,7 @@ func (c *csiDriverClient) NodeStageVolume(ctx context.Context,
accessMode api.PersistentVolumeAccessMode, accessMode api.PersistentVolumeAccessMode,
secrets map[string]string, secrets map[string]string,
volumeContext map[string]string, volumeContext map[string]string,
mountOptions []string,
) error { ) error {
klog.V(4).Info(log("calling NodeStageVolume rpc [volid=%s,staging_target_path=%s]", volID, stagingTargetPath)) klog.V(4).Info(log("calling NodeStageVolume rpc [volid=%s,staging_target_path=%s]", volID, stagingTargetPath))
if volID == "" { if volID == "" {
@ -525,9 +527,9 @@ func (c *csiDriverClient) NodeStageVolume(ctx context.Context,
} }
if c.nodeV1ClientCreator != nil { if c.nodeV1ClientCreator != nil {
return c.nodeStageVolumeV1(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext) return c.nodeStageVolumeV1(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext, mountOptions)
} else if c.nodeV0ClientCreator != nil { } else if c.nodeV0ClientCreator != nil {
return c.nodeStageVolumeV0(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext) return c.nodeStageVolumeV0(ctx, volID, publishContext, stagingTargetPath, fsType, accessMode, secrets, volumeContext, mountOptions)
} }
return fmt.Errorf("failed to call NodeStageVolume. Both nodeV1ClientCreator and nodeV0ClientCreator are nil") return fmt.Errorf("failed to call NodeStageVolume. Both nodeV1ClientCreator and nodeV0ClientCreator are nil")
@ -542,6 +544,7 @@ func (c *csiDriverClient) nodeStageVolumeV1(
accessMode api.PersistentVolumeAccessMode, accessMode api.PersistentVolumeAccessMode,
secrets map[string]string, secrets map[string]string,
volumeContext map[string]string, volumeContext map[string]string,
mountOptions []string,
) error { ) error {
nodeClient, closer, err := c.nodeV1ClientCreator(c.addr) nodeClient, closer, err := c.nodeV1ClientCreator(c.addr)
if err != nil { if err != nil {
@ -569,7 +572,8 @@ func (c *csiDriverClient) nodeStageVolumeV1(
} else { } else {
req.VolumeCapability.AccessType = &csipbv1.VolumeCapability_Mount{ req.VolumeCapability.AccessType = &csipbv1.VolumeCapability_Mount{
Mount: &csipbv1.VolumeCapability_MountVolume{ Mount: &csipbv1.VolumeCapability_MountVolume{
FsType: fsType, FsType: fsType,
MountFlags: mountOptions,
}, },
} }
} }
@ -587,6 +591,7 @@ func (c *csiDriverClient) nodeStageVolumeV0(
accessMode api.PersistentVolumeAccessMode, accessMode api.PersistentVolumeAccessMode,
secrets map[string]string, secrets map[string]string,
volumeContext map[string]string, volumeContext map[string]string,
mountOptions []string,
) error { ) error {
nodeClient, closer, err := c.nodeV0ClientCreator(c.addr) nodeClient, closer, err := c.nodeV0ClientCreator(c.addr)
if err != nil { if err != nil {
@ -614,7 +619,8 @@ func (c *csiDriverClient) nodeStageVolumeV0(
} else { } else {
req.VolumeCapability.AccessType = &csipbv0.VolumeCapability_Mount{ req.VolumeCapability.AccessType = &csipbv0.VolumeCapability_Mount{
Mount: &csipbv0.VolumeCapability_MountVolume{ Mount: &csipbv0.VolumeCapability_MountVolume{
FsType: fsType, FsType: fsType,
MountFlags: mountOptions,
}, },
} }
} }

View File

@ -175,6 +175,7 @@ func (c *fakeCsiDriverClient) NodeStageVolume(ctx context.Context,
accessMode api.PersistentVolumeAccessMode, accessMode api.PersistentVolumeAccessMode,
secrets map[string]string, secrets map[string]string,
volumeContext map[string]string, volumeContext map[string]string,
mountOptions []string,
) error { ) error {
c.t.Log("calling fake.NodeStageVolume...") c.t.Log("calling fake.NodeStageVolume...")
req := &csipbv1.NodeStageVolumeRequest{ req := &csipbv1.NodeStageVolumeRequest{
@ -187,7 +188,8 @@ func (c *fakeCsiDriverClient) NodeStageVolume(ctx context.Context,
}, },
AccessType: &csipbv1.VolumeCapability_Mount{ AccessType: &csipbv1.VolumeCapability_Mount{
Mount: &csipbv1.VolumeCapability_MountVolume{ Mount: &csipbv1.VolumeCapability_MountVolume{
FsType: fsType, FsType: fsType,
MountFlags: mountOptions,
}, },
}, },
}, },
@ -448,10 +450,11 @@ func TestClientNodeStageVolume(t *testing.T) {
stagingTargetPath string stagingTargetPath string
fsType string fsType string
secrets map[string]string secrets map[string]string
mountOptions []string
mustFail bool mustFail bool
err error err error
}{ }{
{name: "test ok", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "ext4"}, {name: "test ok", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "ext4", mountOptions: []string{"unvalidated"}},
{name: "missing volID", stagingTargetPath: "/test/path", mustFail: true}, {name: "missing volID", stagingTargetPath: "/test/path", mustFail: true},
{name: "missing target path", volID: "vol-test", mustFail: true}, {name: "missing target path", volID: "vol-test", mustFail: true},
{name: "bad fs", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "badfs", mustFail: true}, {name: "bad fs", volID: "vol-test", stagingTargetPath: "/test/path", fsType: "badfs", mustFail: true},
@ -479,6 +482,7 @@ func TestClientNodeStageVolume(t *testing.T) {
api.ReadWriteOnce, api.ReadWriteOnce,
tc.secrets, tc.secrets,
map[string]string{"attr0": "val0"}, map[string]string{"attr0": "val0"},
tc.mountOptions,
) )
checkErr(t, tc.mustFail, err) checkErr(t, tc.mustFail, err)

View File

@ -42,6 +42,12 @@ func TestMain(m *testing.M) {
os.Exit(m.Run()) os.Exit(m.Run())
} }
func makeTestPVWithMountOptions(name string, sizeGig int, driverName, volID string, mountOptions []string) *api.PersistentVolume {
pv := makeTestPV(name, sizeGig, driverName, volID)
pv.Spec.MountOptions = mountOptions
return pv
}
func makeTestPV(name string, sizeGig int, driverName, volID string) *api.PersistentVolume { func makeTestPV(name string, sizeGig int, driverName, volID string) *api.PersistentVolume {
return &api.PersistentVolume{ return &api.PersistentVolume{
ObjectMeta: meta.ObjectMeta{ ObjectMeta: meta.ObjectMeta{

View File

@ -189,20 +189,23 @@ func (f *NodeClient) NodeStageVolume(ctx context.Context, req *csipb.NodeStageVo
return nil, errors.New("missing staging target path") return nil, errors.New("missing staging target path")
} }
csiVol := CSIVolume{
Path: req.GetStagingTargetPath(),
VolumeContext: req.GetVolumeContext(),
}
fsType := "" fsType := ""
fsTypes := "block|ext4|xfs|zfs" fsTypes := "block|ext4|xfs|zfs"
mounted := req.GetVolumeCapability().GetMount() mounted := req.GetVolumeCapability().GetMount()
if mounted != nil { if mounted != nil {
fsType = mounted.GetFsType() fsType = mounted.GetFsType()
csiVol.MountFlags = mounted.GetMountFlags()
} }
if !strings.Contains(fsTypes, fsType) { if !strings.Contains(fsTypes, fsType) {
return nil, errors.New("invalid fstype") return nil, errors.New("invalid fstype")
} }
f.nodeStagedVolumes[req.GetVolumeId()] = CSIVolume{ f.nodeStagedVolumes[req.GetVolumeId()] = csiVol
Path: req.GetStagingTargetPath(),
VolumeContext: req.GetVolumeContext(),
}
return &csipb.NodeStageVolumeResponse{}, nil return &csipb.NodeStageVolumeResponse{}, nil
} }

View File

@ -350,6 +350,7 @@ func InitGcePDCSIDriver() testsuites.TestDriver {
"ext4", "ext4",
"xfs", "xfs",
), ),
SupportedMountOption: sets.NewString("debug", "nouid32"),
Capabilities: map[testsuites.Capability]bool{ Capabilities: map[testsuites.Capability]bool{
testsuites.CapPersistence: true, testsuites.CapPersistence: true,
testsuites.CapFsGroup: true, testsuites.CapFsGroup: true,