Merge pull request #37 from skriss/iops_fix

only save/use iops for io1 volumes
This commit is contained in:
Andy Goldstein
2017-08-14 15:24:30 -04:00
committed by GitHub
9 changed files with 30 additions and 23 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ type VolumeBackupInfo struct {
// Iops is the optional value of provisioned IOPS for the
// disk/volume in the cloud provider API.
Iops *int `json:"iops"`
Iops *int64 `json:"iops,omitempty"`
}
// +genclient=true
+1 -1
View File
@@ -31,7 +31,7 @@ import (
)
func TestVolumeSnapshotAction(t *testing.T) {
iops := 1000
iops := int64(1000)
tests := []struct {
name string
+15 -8
View File
@@ -21,6 +21,8 @@ import (
"github.com/aws/aws-sdk-go/service/ec2"
"k8s.io/apimachinery/pkg/util/sets"
"github.com/heptio/ark/pkg/cloudprovider"
)
@@ -31,15 +33,20 @@ type blockStorageAdapter struct {
az string
}
func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int) (volumeID string, err error) {
// iopsVolumeTypes is a set of AWS EBS volume types for which IOPS should
// be captured during snapshot and provided when creating a new volume
// from snapshot.
var iopsVolumeTypes = sets.NewString("io1")
func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int64) (volumeID string, err error) {
req := &ec2.CreateVolumeInput{
SnapshotId: &snapshotID,
AvailabilityZone: &op.az,
VolumeType: &volumeType,
}
if iops != nil {
req.SetIops(int64(*iops))
if iopsVolumeTypes.Has(volumeType) && iops != nil {
req.Iops = iops
}
res, err := op.ec2.CreateVolume(req)
@@ -50,7 +57,7 @@ func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID, volumeType s
return *res.VolumeId, nil
}
func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int, error) {
func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int64, error) {
req := &ec2.DescribeVolumesInput{
VolumeIds: []*string{&volumeID},
}
@@ -68,18 +75,18 @@ func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int, err
var (
volumeType string
iops int
iops *int64
)
if vol.VolumeType != nil {
volumeType = *vol.VolumeType
}
if vol.Iops != nil {
iops = int(*vol.Iops)
if iopsVolumeTypes.Has(volumeType) && vol.Iops != nil {
iops = vol.Iops
}
return volumeType, &iops, nil
return volumeType, iops, nil
}
func (op *blockStorageAdapter) IsVolumeReady(volumeID string) (ready bool, err error) {
@@ -39,7 +39,7 @@ type blockStorageAdapter struct {
var _ cloudprovider.BlockStorageAdapter = &blockStorageAdapter{}
func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int) (string, error) {
func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int64) (string, error) {
fullSnapshotName := getFullSnapshotName(op.subscription, op.resourceGroup, snapshotID)
diskName := "restore-" + uuid.NewV4().String()
@@ -68,7 +68,7 @@ func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID, volumeType s
return diskName, nil
}
func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int, error) {
func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int64, error) {
res, err := op.disks.Get(op.resourceGroup, volumeID)
if err != nil {
return "", nil, err
@@ -36,7 +36,7 @@ type blockStorageAdapter struct {
var _ cloudprovider.BlockStorageAdapter = &blockStorageAdapter{}
func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID string, volumeType string, iops *int) (volumeID string, err error) {
func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID string, volumeType string, iops *int64) (volumeID string, err error) {
res, err := op.gce.Snapshots.Get(op.project, snapshotID).Do()
if err != nil {
return "", err
@@ -55,7 +55,7 @@ func (op *blockStorageAdapter) CreateVolumeFromSnapshot(snapshotID string, volum
return disk.Name, nil
}
func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int, error) {
func (op *blockStorageAdapter) GetVolumeInfo(volumeID string) (string, *int64, error) {
res, err := op.gce.Disks.Get(op.project, op.zone, volumeID).Do()
if err != nil {
return "", nil, err
+4 -4
View File
@@ -37,14 +37,14 @@ type SnapshotService interface {
// CreateVolumeFromSnapshot triggers a restore operation to create a new cloud volume from the specified
// snapshot and volume characteristics. Returns the cloud volume ID, or an error if a problem is
// encountered triggering the restore via the cloud API.
CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int) (string, error)
CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int64) (string, error)
// DeleteSnapshot triggers a deletion of the specified Ark snapshot via the cloud API. It returns an
// error if a problem is encountered triggering the deletion via the cloud API.
DeleteSnapshot(snapshotID string) error
// GetVolumeInfo gets the type and IOPS (if applicable) from the cloud API.
GetVolumeInfo(volumeID string) (string, *int, error)
GetVolumeInfo(volumeID string) (string, *int64, error)
}
const (
@@ -67,7 +67,7 @@ func NewSnapshotService(blockStorage BlockStorageAdapter) SnapshotService {
}
}
func (sr *snapshotService) CreateVolumeFromSnapshot(snapshotID string, volumeType string, iops *int) (string, error) {
func (sr *snapshotService) CreateVolumeFromSnapshot(snapshotID string, volumeType string, iops *int64) (string, error) {
volumeID, err := sr.blockStorage.CreateVolumeFromSnapshot(snapshotID, volumeType, iops)
if err != nil {
return "", err
@@ -116,6 +116,6 @@ func (sr *snapshotService) DeleteSnapshot(snapshotID string) error {
return sr.blockStorage.DeleteSnapshot(snapshotID)
}
func (sr *snapshotService) GetVolumeInfo(volumeID string) (string, *int, error) {
func (sr *snapshotService) GetVolumeInfo(volumeID string) (string, *int64, error) {
return sr.blockStorage.GetVolumeInfo(volumeID)
}
+2 -2
View File
@@ -44,11 +44,11 @@ type ObjectStorageAdapter interface {
type BlockStorageAdapter interface {
// CreateVolumeFromSnapshot creates a new block volume, initialized from the provided snapshot,
// and with the specified type and IOPS (if using provisioned IOPS).
CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int) (volumeID string, err error)
CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int64) (volumeID string, err error)
// GetVolumeInfo returns the type and IOPS (if using provisioned IOPS) for a specified block
// volume.
GetVolumeInfo(volumeID string) (string, *int, error)
GetVolumeInfo(volumeID string) (string, *int64, error)
// IsVolumeReady returns whether the specified volume is ready to be used.
IsVolumeReady(volumeID string) (ready bool, err error)
+1 -1
View File
@@ -29,7 +29,7 @@ import (
)
func TestPVRestorerPrepare(t *testing.T) {
iops := 1000
iops := int64(1000)
tests := []struct {
name string
+2 -2
View File
@@ -52,7 +52,7 @@ func (s *FakeSnapshotService) CreateSnapshot(volumeID string) (string, error) {
return s.SnapshottableVolumes[volumeID].SnapshotID, nil
}
func (s *FakeSnapshotService) CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int) (string, error) {
func (s *FakeSnapshotService) CreateVolumeFromSnapshot(snapshotID, volumeType string, iops *int64) (string, error) {
key := api.VolumeBackupInfo{
SnapshotID: snapshotID,
Type: volumeType,
@@ -72,7 +72,7 @@ func (s *FakeSnapshotService) DeleteSnapshot(snapshotID string) error {
return nil
}
func (s *FakeSnapshotService) GetVolumeInfo(volumeID string) (string, *int, error) {
func (s *FakeSnapshotService) GetVolumeInfo(volumeID string) (string, *int64, error) {
if volumeInfo, exists := s.SnapshottableVolumes[volumeID]; !exists {
return "", nil, errors.New("VolumeID not found")
} else {