Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
Merge pull request #810 from bgilbert/pv
Browse files Browse the repository at this point in the history
Don't create PV AMIs in regions that don't support them
  • Loading branch information
bgilbert authored Feb 9, 2018
2 parents 0b3be93 + 43b1219 commit 5cb6ac8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
38 changes: 23 additions & 15 deletions cmd/plume/prerelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func awsUploadToPartition(spec *channelSpec, part *awsPartitionSpec, imageName,
return nil, nil, fmt.Errorf("couldn't tag images: %v", err)
}

postprocess := func(imageID string) (map[string]string, error) {
postprocess := func(imageID string, pv bool) (map[string]string, error) {
if len(part.LaunchPermissions) > 0 {
if err := api.GrantLaunchPermission(imageID, part.LaunchPermissions); err != nil {
return nil, err
Expand All @@ -436,7 +436,11 @@ func awsUploadToPartition(spec *channelSpec, part *awsPartitionSpec, imageName,
foundBucketRegion := false
for _, region := range part.Regions {
if region != part.BucketRegion {
destRegions = append(destRegions, region)
if pv && !aws.RegionSupportsPV(region) {
plog.Debugf("%v doesn't support PV AMIs; skipping", region)
} else {
destRegions = append(destRegions, region)
}
} else {
foundBucketRegion = true
}
Expand All @@ -460,12 +464,12 @@ func awsUploadToPartition(spec *channelSpec, part *awsPartitionSpec, imageName,
return amis, nil
}

hvmAmis, err := postprocess(hvmImageID)
hvmAmis, err := postprocess(hvmImageID, false)
if err != nil {
return nil, nil, fmt.Errorf("processing HVM images: %v", err)
}

pvAmis, err := postprocess(pvImageID)
pvAmis, err := postprocess(pvImageID, true)
if err != nil {
return nil, nil, fmt.Errorf("processing PV images: %v", err)
}
Expand All @@ -475,7 +479,7 @@ func awsUploadToPartition(spec *channelSpec, part *awsPartitionSpec, imageName,

type amiListEntry struct {
Region string `json:"name"`
PvAmi string `json:"pv"`
PvAmi string `json:"pv,omitempty"`
HvmAmi string `json:"hvm"`
}

Expand Down Expand Up @@ -524,21 +528,25 @@ func awsUploadAmiLists(ctx context.Context, bucket *storage.Bucket, spec *channe
for _, entry := range amis.Entries {
hvmRecords = append(hvmRecords,
fmt.Sprintf("%v=%v", entry.Region, entry.HvmAmi))
pvRecords = append(pvRecords,
fmt.Sprintf("%v=%v", entry.Region, entry.PvAmi))
if entry.PvAmi != "" {
pvRecords = append(pvRecords,
fmt.Sprintf("%v=%v", entry.Region, entry.PvAmi))
}

if err := upload(fmt.Sprintf("hvm_%v.txt", entry.Region),
entry.HvmAmi+"\n"); err != nil {
return err
}
if err := upload(fmt.Sprintf("pv_%v.txt", entry.Region),
entry.PvAmi+"\n"); err != nil {
return err
}
// compatibility
if err := upload(fmt.Sprintf("%v.txt", entry.Region),
entry.PvAmi+"\n"); err != nil {
return err
if entry.PvAmi != "" {
if err := upload(fmt.Sprintf("pv_%v.txt", entry.Region),
entry.PvAmi+"\n"); err != nil {
return err
}
// compatibility
if err := upload(fmt.Sprintf("%v.txt", entry.Region),
entry.PvAmi+"\n"); err != nil {
return err
}
}
}
hvmAll := strings.Join(hvmRecords, "|") + "\n"
Expand Down
4 changes: 3 additions & 1 deletion cmd/plume/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ func doAWS(ctx context.Context, client *http.Client, src *storage.Bucket, spec *
}
}
}
publish(imageName)
if aws.RegionSupportsPV(region) {
publish(imageName)
}
publish(imageName + "-hvm")
}
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/plume/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var (
"us-west-2",
"eu-west-1",
"eu-west-2",
"eu-west-3",
"eu-central-1",
"ap-south-1",
"ap-southeast-1",
Expand All @@ -152,6 +153,7 @@ var (
BucketRegion: "cn-north-1",
Regions: []string{
"cn-north-1",
"cn-northwest-1",
},
},
}
Expand Down Expand Up @@ -188,6 +190,7 @@ var (
Regions: []string{
"us-west-1",
"us-west-2",
"eu-west-3", // no PV
},
},
awsPartitionSpec{
Expand Down
22 changes: 22 additions & 0 deletions platform/api/aws/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package aws

import (
"errors"
"fmt"
"net/url"
"strings"
Expand All @@ -29,6 +30,10 @@ import (
"github.com/aws/aws-sdk-go/service/iam"
)

var (
NoRegionPVSupport = errors.New("Region does not support PV")
)

type EC2ImageType string

const (
Expand Down Expand Up @@ -62,6 +67,12 @@ var akis = map[string]string{
"ca-central-1": "aki-320ebd56",

"us-gov-west-1": "aki-1de98d3e",
"cn-north-1": "aki-9e8f1da7",
}

func RegionSupportsPV(region string) bool {
_, ok := akis[region]
return ok
}

func (e *EC2ImageFormat) Set(s string) error {
Expand Down Expand Up @@ -352,6 +363,9 @@ func (a *API) CreateHVMImage(snapshotID string, name string, description string)
}

func (a *API) CreatePVImage(snapshotID string, name string, description string) (string, error) {
if !RegionSupportsPV(a.opts.Region) {
return "", NoRegionPVSupport
}
params := registerImageParams(snapshotID, name, description, "sd", EC2ImageTypePV)
params.KernelId = aws.String(akis[a.opts.Region])
return a.createImage(params)
Expand Down Expand Up @@ -439,6 +453,14 @@ func (a *API) CopyImage(sourceImageID string, regions []string) (map[string]stri
return nil, err
}

if *image.VirtualizationType == ec2.VirtualizationTypeParavirtual {
for _, region := range regions {
if !RegionSupportsPV(region) {
return nil, NoRegionPVSupport
}
}
}

describeSnapshotRes, err := a.ec2.DescribeSnapshots(&ec2.DescribeSnapshotsInput{
SnapshotIds: []*string{image.BlockDeviceMappings[0].Ebs.SnapshotId},
})
Expand Down

0 comments on commit 5cb6ac8

Please sign in to comment.