Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for storage class parameter - fsType #67

Merged
merged 1 commit into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": defaultFsType},
},
expVol: &csi.Volume{
CapacityBytes: stdVolSize,
Id: "vol-test",
Attributes: map[string]string{"fsType": defaultFsType},
},
},
}
Expand Down
13 changes: 12 additions & 1 deletion pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ import (
"google.golang.org/grpc/status"
)

const (
// default file system type to be used when it is not provided
defaultFsType = "ext4"
)

func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
glog.V(4).Infof("NodeStageVolume: called with args %#v", req)
volumeID := req.GetVolumeId()
Expand Down Expand Up @@ -72,10 +77,16 @@ 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
attributes := req.GetVolumeAttributes()
fsType, exists := attributes["fsType"]
if !exists || fsType == "" {
fsType = defaultFsType
}

// 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