Skip to content

Commit

Permalink
Merge pull request eksctl-io#73 from leakingtapan/volume-type
Browse files Browse the repository at this point in the history
Implement support for storage class parameter - volume type
  • Loading branch information
k8s-ci-robot authored Oct 22, 2018
2 parents 09bb8b8 + 17b9e2f commit 6aa96a3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 17 deletions.
35 changes: 20 additions & 15 deletions pkg/cloud/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,41 @@ import (
"k8s.io/apimachinery/pkg/util/wait"
)

// AWS volume types
const (
// DefaultVolumeSize represents the default volume size.
// TODO: what should be the default size?
DefaultVolumeSize int64 = 1 * 1024 * 1024 * 1024

// VolumeNameTagKey is the key value that refers to the volume's name.
VolumeNameTagKey = "com.amazon.aws.csi.volume"

// VolumeTypeIO1 represents a provisioned IOPS SSD type of volume.
VolumeTypeIO1 = "io1"

// VolumeTypeGP2 represents a general purpose SSD type of volume.
VolumeTypeGP2 = "gp2"

// VolumeTypeSC1 represents a cold HDD (sc1) type of volume.
VolumeTypeSC1 = "sc1"

// VolumeTypeST1 represents a throughput-optimized HDD type of volume.
VolumeTypeST1 = "st1"
)

// AWS provisioning limits.
// Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html
const (
// MinTotalIOPS represents the minimum Input Output per second.
MinTotalIOPS int64 = 100

MinTotalIOPS = 100
// MaxTotalIOPS represents the maximum Input Output per second.
MaxTotalIOPS int64 = 20000
MaxTotalIOPS = 20000
)

// Defaults
const (
// DefaultVolumeSize represents the default volume size.
DefaultVolumeSize int64 = 100 * 1024 * 1024 * 1024
// DefaultVolumeType specifies which storage to use for newly created Volumes.
DefaultVolumeType = VolumeTypeGP2
)

// Tags
const (
// VolumeNameTagKey is the key value that refers to the volume's name.
VolumeNameTagKey = "com.amazon.aws.csi.volume"
)

var (
// ErrMultiDisks is an error that is returned when multiple
// disks are found with the same volume name.
Expand Down Expand Up @@ -95,7 +100,7 @@ type DiskOptions struct {
CapacityBytes int64
Tags map[string]string
VolumeType string
IOPSPerGB int64
IOPSPerGB int
AvailabilityZone string
}

Expand Down Expand Up @@ -177,7 +182,7 @@ func (c *cloud) CreateDisk(ctx context.Context, volumeName string, diskOptions *
createType = diskOptions.VolumeType
case VolumeTypeIO1:
createType = diskOptions.VolumeType
iops = capacityGiB * diskOptions.IOPSPerGB
iops = capacityGiB * int64(diskOptions.IOPSPerGB)
if iops < MinTotalIOPS {
iops = MinTotalIOPS
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package driver

import (
"context"
"strconv"

csi "github.com/container-storage-interface/spec/lib/go/csi/v0"
"github.com/golang/glog"
Expand Down Expand Up @@ -75,16 +76,28 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)

// create a new volume
zone := pickAvailabilityZone(req.GetAccessibilityRequirements())
volumeParams := req.GetParameters()
volumeType := volumeParams["type"]
iopsPerGB := 0
if volumeType == cloud.VolumeTypeIO1 {
iopsPerGB, err = strconv.Atoi(volumeParams["iopsPerGB"])
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Could not parse invalid iopsPerGB: %v", err)
}
}

opts := &cloud.DiskOptions{
CapacityBytes: volSizeBytes,
AvailabilityZone: zone,
Tags: map[string]string{cloud.VolumeNameTagKey: volName},
VolumeType: volumeType,
IOPSPerGB: iopsPerGB,
AvailabilityZone: zone,
}
disk, err = d.cloud.CreateDisk(ctx, volName, opts)
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not create volume %q: %v", volName, err)
}
fsType := req.GetParameters()["fsType"]
fsType := volumeParams["fsType"]
disk.FsType = fsType
return newCreateVolumeResponse(disk), nil
}
Expand Down
33 changes: 33 additions & 0 deletions pkg/driver/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,39 @@ func TestCreateVolume(t *testing.T) {
Attributes: map[string]string{"fsType": defaultFsType},
},
},
{
name: "success with volume type io1",
req: &csi.CreateVolumeRequest{
Name: "vol-test",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: map[string]string{
"type": cloud.VolumeTypeIO1,
"iopsPerGB": "5",
},
},
expVol: &csi.Volume{
CapacityBytes: stdVolSize,
Id: "vol-test",
Attributes: map[string]string{"fsType": ""},
},
},
{
name: "success with volume type sc1",
req: &csi.CreateVolumeRequest{
Name: "vol-test",
CapacityRange: stdCapRange,
VolumeCapabilities: stdVolCap,
Parameters: map[string]string{
"type": cloud.VolumeTypeSC1,
},
},
expVol: &csi.Volume{
CapacityBytes: stdVolSize,
Id: "vol-test",
Attributes: map[string]string{"fsType": ""},
},
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 6aa96a3

Please sign in to comment.