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

mantle/aws: ami f39 changes #3586

Closed
wants to merge 3 commits into from
Closed
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
20 changes: 19 additions & 1 deletion mantle/platform/api/aws/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package aws
import (
"fmt"
"net/url"
"os"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -331,14 +332,29 @@ func (a *API) CreateImportRole(bucket string) error {

func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, description string, architecture string) (string, error) {
var awsArch string
var bootmode string
if architecture == "" {
architecture = runtime.GOARCH
}
volumeType, set := os.LookupEnv("MANTLE_AWS_VOLUME_TYPE")
if !set {
volumeType = "gp3"
}
imdsSupport, set := os.LookupEnv("MANTLE_AWS_IMDS_SUPPORT")
if !set {
imdsSupport = "v2.0"
}
bootmode, set = os.LookupEnv("MANTLE_AWS_BOOT_MODE_x86_64")

switch architecture {
case "amd64", "x86_64":
awsArch = ec2.ArchitectureTypeX8664
if !set {
bootmode = "uefi-preferred"
}
case "arm64", "aarch64":
awsArch = ec2.ArchitectureTypeArm64
bootmode = "uefi"
default:
return "", fmt.Errorf("unsupported ec2 architecture %q", architecture)
}
Expand All @@ -349,14 +365,15 @@ func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, d
Architecture: aws.String(awsArch),
VirtualizationType: aws.String("hvm"),
RootDeviceName: aws.String("/dev/xvda"),
ImdsSupport: aws.String(imdsSupport),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is passing in an empty string here the same thing as not passing a value for ImdsSupport at all?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe instead of an empty string we should just default to v2.0 in the code above?

BlockDeviceMappings: []*ec2.BlockDeviceMapping{
{
DeviceName: aws.String("/dev/xvda"),
Ebs: &ec2.EbsBlockDevice{
SnapshotId: aws.String(snapshotID),
DeleteOnTermination: aws.Bool(true),
VolumeSize: aws.Int64(int64(diskSizeGiB)),
VolumeType: aws.String("gp2"),
VolumeType: aws.String(volumeType),
},
},
{
Expand All @@ -366,6 +383,7 @@ func (a *API) CreateHVMImage(snapshotID string, diskSizeGiB uint, name string, d
},
EnaSupport: aws.Bool(true),
SriovNetSupport: aws.String("simple"),
BootMode: aws.String(bootmode),
})
}

Expand Down
14 changes: 12 additions & 2 deletions src/cosalib/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import sys

from cosalib.cmdlib import (
retry_stop,
flatten_image_yaml,
retry_boto_exception,
retry_callback
retry_callback,
retry_stop
)
from tenacity import (
retry,
Expand Down Expand Up @@ -111,6 +112,15 @@ def aws_run_ore_replicate(build, args):

@retry(reraise=True, stop=stop_after_attempt(3))
def aws_run_ore(build, args):
# set environment variables before setting up the ore command
image_yaml = flatten_image_yaml(
'/usr/lib/coreos-assembler/image-default.yaml',
flatten_image_yaml('src/config/image.yaml')
)
os.environ["MANTLE_AWS_IMDS_SUPPORT"] = image_yaml['aws-imds-support']
os.environ["MANTLE_AWS_VOLUME_TYPE"] = image_yaml['aws-volume-type']
os.environ["MANTLE_AWS_BOOT_MODE_x86_64"] = image_yaml['aws-boot-mode-x86-64']

# First add the ore command to run before any options
ore_args = ['ore', 'aws', 'upload']

Expand Down
5 changes: 5 additions & 0 deletions src/image-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ squashfs-compression: zstd
vmware-hw-version: 13
vmware-os-type: rhel7_64Guest
vmware-secure-boot: true

# Defaults for AWS
aws-imds-support: "v2.0"
aws-volume-type: "gp3"
aws-boot-mode-x86-64: "uefi-preferred"