Merge pull request #67898 from NetApp/csi-mount-options

Add support for mount options to CSI drivers
This commit is contained in:
k8s-ci-robot 2018-10-30 19:48:20 -07:00 committed by GitHub
commit 56796f3bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 3 deletions

View File

@ -276,6 +276,7 @@ func (m *csiBlockMapper) MapDevice(devicePath, globalMapPath, volumeMapPath, vol
csiSource.VolumeAttributes, csiSource.VolumeAttributes,
nodePublishSecrets, nodePublishSecrets,
fsTypeBlockName, fsTypeBlockName,
[]string{},
) )
if err != nil { if err != nil {

View File

@ -49,6 +49,7 @@ type csiClient interface {
volumeAttribs map[string]string, volumeAttribs map[string]string,
nodePublishSecrets map[string]string, nodePublishSecrets map[string]string,
fsType string, fsType string,
mountOptions []string,
) error ) error
NodeUnpublishVolume( NodeUnpublishVolume(
ctx context.Context, ctx context.Context,
@ -138,6 +139,7 @@ func (c *csiDriverClient) NodePublishVolume(
volumeAttribs map[string]string, volumeAttribs map[string]string,
nodePublishSecrets map[string]string, nodePublishSecrets map[string]string,
fsType string, fsType string,
mountOptions []string,
) error { ) error {
glog.V(4).Info(log("calling NodePublishVolume rpc [volid=%s,target_path=%s]", volID, targetPath)) glog.V(4).Info(log("calling NodePublishVolume rpc [volid=%s,target_path=%s]", volID, targetPath))
if volID == "" { if volID == "" {
@ -177,7 +179,8 @@ func (c *csiDriverClient) NodePublishVolume(
} else { } else {
req.VolumeCapability.AccessType = &csipb.VolumeCapability_Mount{ req.VolumeCapability.AccessType = &csipb.VolumeCapability_Mount{
Mount: &csipb.VolumeCapability_MountVolume{ Mount: &csipb.VolumeCapability_MountVolume{
FsType: fsType, FsType: fsType,
MountFlags: mountOptions,
}, },
} }
} }

View File

@ -60,6 +60,7 @@ func (c *fakeCsiDriverClient) NodePublishVolume(
volumeAttribs map[string]string, volumeAttribs map[string]string,
nodePublishSecrets map[string]string, nodePublishSecrets map[string]string,
fsType string, fsType string,
mountOptions []string,
) error { ) error {
c.t.Log("calling fake.NodePublishVolume...") c.t.Log("calling fake.NodePublishVolume...")
req := &csipb.NodePublishVolumeRequest{ req := &csipb.NodePublishVolumeRequest{
@ -75,7 +76,8 @@ func (c *fakeCsiDriverClient) NodePublishVolume(
}, },
AccessType: &csipb.VolumeCapability_Mount{ AccessType: &csipb.VolumeCapability_Mount{
Mount: &csipb.VolumeCapability_MountVolume{ Mount: &csipb.VolumeCapability_MountVolume{
FsType: fsType, FsType: fsType,
MountFlags: mountOptions,
}, },
}, },
}, },
@ -268,6 +270,7 @@ func TestClientNodePublishVolume(t *testing.T) {
map[string]string{"attr0": "val0"}, map[string]string{"attr0": "val0"},
map[string]string{}, map[string]string{},
tc.fsType, tc.fsType,
[]string{},
) )
checkErr(t, tc.mustFail, err) checkErr(t, tc.mustFail, err)

View File

@ -195,6 +195,7 @@ func (c *csiMountMgr) SetUpAt(dir string, fsGroup *int64) error {
attribs, attribs,
nodePublishSecrets, nodePublishSecrets,
fsType, fsType,
c.spec.PersistentVolume.Spec.MountOptions,
) )
if err != nil { if err != nil {

View File

@ -164,6 +164,7 @@ func MounterSetUpTests(t *testing.T, podInfoEnabled bool) {
pv := makeTestPV("test-pv", 10, test.driver, testVol) pv := makeTestPV("test-pv", 10, test.driver, testVol)
pv.Spec.CSI.VolumeAttributes = test.attributes pv.Spec.CSI.VolumeAttributes = test.attributes
pv.Spec.MountOptions = []string{"foo=bar", "baz=qux"}
pvName := pv.GetName() pvName := pv.GetName()
mounter, err := plug.NewMounter( mounter, err := plug.NewMounter(
@ -240,6 +241,9 @@ func MounterSetUpTests(t *testing.T, podInfoEnabled bool) {
if vol.Path != csiMounter.GetPath() { if vol.Path != csiMounter.GetPath() {
t.Errorf("csi server expected path %s, got %s", csiMounter.GetPath(), vol.Path) t.Errorf("csi server expected path %s, got %s", csiMounter.GetPath(), vol.Path)
} }
if !reflect.DeepEqual(vol.MountFlags, pv.Spec.MountOptions) {
t.Errorf("csi server expected mount options %v, got %v", pv.Spec.MountOptions, vol.MountFlags)
}
if podInfoEnabled { if podInfoEnabled {
if !reflect.DeepEqual(vol.Attributes, test.expectedAttributes) { if !reflect.DeepEqual(vol.Attributes, test.expectedAttributes) {
t.Errorf("csi server expected attributes %+v, got %+v", test.expectedAttributes, vol.Attributes) t.Errorf("csi server expected attributes %+v, got %+v", test.expectedAttributes, vol.Attributes)

View File

@ -333,7 +333,10 @@ func (p *csiPlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.S
func (p *csiPlugin) SupportsMountOption() bool { func (p *csiPlugin) SupportsMountOption() bool {
// TODO (vladimirvivien) use CSI VolumeCapability.MountVolume.mount_flags // TODO (vladimirvivien) use CSI VolumeCapability.MountVolume.mount_flags
// to probe for the result for this method // to probe for the result for this method
return false // (bswartz) Until the CSI spec supports probing, our only option is to
// make plugins register their support for mount options or lack thereof
// directly with kubernetes.
return true
} }
func (p *csiPlugin) SupportsBulkVolumeVerification() bool { func (p *csiPlugin) SupportsBulkVolumeVerification() bool {

View File

@ -59,6 +59,7 @@ func (f *IdentityClient) Probe(ctx context.Context, in *csipb.ProbeRequest, opts
type CSIVolume struct { type CSIVolume struct {
Attributes map[string]string Attributes map[string]string
Path string Path string
MountFlags []string
} }
// NodeClient returns CSI node client // NodeClient returns CSI node client
@ -126,6 +127,7 @@ func (f *NodeClient) NodePublishVolume(ctx context.Context, req *csipb.NodePubli
f.nodePublishedVolumes[req.GetVolumeId()] = CSIVolume{ f.nodePublishedVolumes[req.GetVolumeId()] = CSIVolume{
Path: req.GetTargetPath(), Path: req.GetTargetPath(),
Attributes: req.GetVolumeAttributes(), Attributes: req.GetVolumeAttributes(),
MountFlags: req.GetVolumeCapability().GetMount().MountFlags,
} }
return &csipb.NodePublishVolumeResponse{}, nil return &csipb.NodePublishVolumeResponse{}, nil
} }