Skip to content

Commit

Permalink
Implement support for storage class parameter - fsType
Browse files Browse the repository at this point in the history
Fixes: #62
  • Loading branch information
Cheng Pan committed Oct 16, 2018
1 parent 290b6d0 commit a0cdd1b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ type Disk struct {
VolumeID string
CapacityGiB int64
AvailabilityZone string
FsType string
}

// DiskOptions represents parameters to create an EBS volume
Expand Down
5 changes: 5 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not create volume %q: %v", volName, err)
}
fsType := req.GetParameters()["fsType"]
disk.FsType = fsType
return newCreateVolumeResponse(disk), nil
}

Expand Down Expand Up @@ -279,6 +281,9 @@ func newCreateVolumeResponse(disk *cloud.Disk) *csi.CreateVolumeResponse {
Volume: &csi.Volume{
Id: disk.VolumeID,
CapacityBytes: util.GiBToBytes(disk.CapacityGiB),
Attributes: map[string]string{
"fsType": disk.FsType,
},
AccessibleTopology: []*csi.Topology{
&csi.Topology{
Segments: map[string]string{topologyKey: disk.AvailabilityZone},
Expand Down
22 changes: 18 additions & 4 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestCreateVolume(t *testing.T) {
expVol: &csi.Volume{
CapacityBytes: stdVolSize,
Id: "vol-test",
Attributes: nil,
Attributes: map[string]string{"fsType": ""},
},
},
{
Expand Down Expand Up @@ -89,7 +89,7 @@ func TestCreateVolume(t *testing.T) {
expVol: &csi.Volume{
CapacityBytes: stdVolSize,
Id: "vol-test",
Attributes: nil,
Attributes: map[string]string{"fsType": ""},
},
},
{
Expand Down Expand Up @@ -118,7 +118,7 @@ func TestCreateVolume(t *testing.T) {
expVol: &csi.Volume{
CapacityBytes: cloud.DefaultVolumeSize,
Id: "vol-test",
Attributes: nil,
Attributes: map[string]string{"fsType": ""},
},
},
{
Expand All @@ -132,7 +132,21 @@ func TestCreateVolume(t *testing.T) {
expVol: &csi.Volume{
CapacityBytes: 2147483648, // 1 GiB + 1 byte = 2 GiB
Id: "vol-test",
Attributes: nil,
Attributes: map[string]string{"fsType": ""},
},
},
{
name: "success with fstype parameter",
req: &csi.CreateVolumeRequest{
Name: "vol-test",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: map[string]string{"fsType": "ext4"},
},
expVol: &csi.Volume{
CapacityBytes: stdVolSize,
Id: "vol-test",
Attributes: map[string]string{"fsType": "ext4"},
},
},
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,20 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
msg := fmt.Sprintf("target %q is not a valid mount point", target)
return nil, status.Error(codes.InvalidArgument, msg)
}
// Get fs type that the volume will be formatted with
var (
fsType string
exists bool
)
attributes := req.GetVolumeAttributes()
fsType, exists = attributes["fsType"]
if !exists || fsType == "" {
fsType = "ext4"
}

// FormatAndMount will format only if needed
glog.V(5).Infof("NodeStageVolume: formatting %s and mounting at %s", source, target)
err = d.mounter.FormatAndMount(source, target, "ext4", nil)
err = d.mounter.FormatAndMount(source, target, fsType, nil)
if err != nil {
msg := fmt.Sprintf("could not format %q and mount it at %q", source, target)
return nil, status.Error(codes.Internal, msg)
Expand Down

0 comments on commit a0cdd1b

Please sign in to comment.