Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#31 from NickrenREN/fstype
Browse files Browse the repository at this point in the history
Set FsType for VolumeCapability_MountVolume
  • Loading branch information
jsafrane authored Mar 12, 2018
2 parents 341457a + 574ae8e commit 0f32303
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
12 changes: 11 additions & 1 deletion pkg/connection/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

const (
defaultFSType = "ext4"
nodeIDAnnotation = "csi.volume.kubernetes.io/nodeid"
csiVolAttribsAnnotationKey = "csi.volume.kubernetes.io/volume-attributes"
)
Expand Down Expand Up @@ -53,10 +54,19 @@ func GetVolumeCapabilities(pv *v1.PersistentVolume) (*csi.VolumeCapability, erro
m[mode] = true
}

if pv.Spec.PersistentVolumeSource.CSI == nil {
return nil, fmt.Errorf("persistent volume does not contain CSI volume source")
}

fsType := pv.Spec.CSI.FSType
if len(fsType) == 0 {
fsType = defaultFSType
}

cap := &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{
// TODO: get FsType from somewhere
FsType: fsType,
MountFlags: pv.Spec.MountOptions,
},
},
Expand Down
27 changes: 21 additions & 6 deletions pkg/connection/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ func TestGetNodeID(t *testing.T) {
}
}

func createMountCapability(mode csi.VolumeCapability_AccessMode_Mode, mountOptions []string) *csi.VolumeCapability {
func createMountCapability(fsType string, mode csi.VolumeCapability_AccessMode_Mode, mountOptions []string) *csi.VolumeCapability {
return &csi.VolumeCapability{
AccessType: &csi.VolumeCapability_Mount{
Mount: &csi.VolumeCapability_MountVolume{
FsType: fsType,
MountFlags: mountOptions,
},
},
Expand All @@ -85,9 +86,11 @@ func createMountCapability(mode csi.VolumeCapability_AccessMode_Mode, mountOptio
},
}
}

func TestGetVolumeCapabilities(t *testing.T) {
tests := []struct {
name string
fsType string
modes []v1.PersistentVolumeAccessMode
mountOptions []string
expectedCapability *csi.VolumeCapability
Expand All @@ -96,31 +99,38 @@ func TestGetVolumeCapabilities(t *testing.T) {
{
name: "RWX",
modes: []v1.PersistentVolumeAccessMode{v1.ReadWriteMany},
expectedCapability: createMountCapability(csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, nil),
expectedCapability: createMountCapability(defaultFSType, csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, nil),
expectError: false,
},
{
name: "RWX + specified fsType",
fsType: "ext3",
modes: []v1.PersistentVolumeAccessMode{v1.ReadWriteMany},
expectedCapability: createMountCapability("ext3", csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, nil),
expectError: false,
},
{
name: "RWO",
modes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
expectedCapability: createMountCapability(csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, nil),
expectedCapability: createMountCapability(defaultFSType, csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER, nil),
expectError: false,
},
{
name: "ROX",
modes: []v1.PersistentVolumeAccessMode{v1.ReadOnlyMany},
expectedCapability: createMountCapability(csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY, nil),
expectedCapability: createMountCapability(defaultFSType, csi.VolumeCapability_AccessMode_MULTI_NODE_READER_ONLY, nil),
expectError: false,
},
{
name: "RWX + anytyhing",
modes: []v1.PersistentVolumeAccessMode{v1.ReadWriteMany, v1.ReadOnlyMany, v1.ReadWriteOnce},
expectedCapability: createMountCapability(csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, nil),
expectedCapability: createMountCapability(defaultFSType, csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, nil),
expectError: false,
},
{
name: "mount options",
modes: []v1.PersistentVolumeAccessMode{v1.ReadWriteMany},
expectedCapability: createMountCapability(csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, []string{"first", "second"}),
expectedCapability: createMountCapability(defaultFSType, csi.VolumeCapability_AccessMode_MULTI_NODE_MULTI_WRITER, []string{"first", "second"}),
mountOptions: []string{"first", "second"},
expectError: false,
},
Expand All @@ -143,6 +153,11 @@ func TestGetVolumeCapabilities(t *testing.T) {
Spec: v1.PersistentVolumeSpec{
AccessModes: test.modes,
MountOptions: test.mountOptions,
PersistentVolumeSource: v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
FSType: test.fsType,
},
},
},
}
cap, err := GetVolumeCapabilities(pv)
Expand Down

0 comments on commit 0f32303

Please sign in to comment.