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

only save/use iops for io1 volumes #37

Merged
merged 2 commits into from
Aug 14, 2017
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
2 changes: 1 addition & 1 deletion pkg/apis/ark/v1/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/backup/volume_snapshot_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
)

func TestVolumeSnapshotAction(t *testing.T) {
iops := 1000
iops := int64(1000)

tests := []struct {
name string
Expand Down
23 changes: 15 additions & 8 deletions pkg/cloudprovider/aws/block_storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand All @@ -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},
}
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/azure/block_storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloudprovider/gcp/block_storage_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloudprovider/snapshot_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/cloudprovider/storage_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/restore/restorers/pv_restorer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

func TestPVRestorerPrepare(t *testing.T) {
iops := 1000
iops := int64(1000)

tests := []struct {
name string
Expand Down
4 changes: 2 additions & 2 deletions pkg/util/test/fake_snapshot_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down