AWS: extend target options with the AMI boot mode

Add an optional `BootMode` field to the AWS target options.
This allows to signal to worker the intended boot mode to use when
registering the AMI in AWS. If not specified, the default behavior is
preserved, specifically that the boot mode will be determined by the
default boot mode of the instance provisioned from the AMI.

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-05-16 14:14:07 +02:00 committed by Achilleas Koutsou
parent e13f0a1ae2
commit 403b1e4692
3 changed files with 19 additions and 2 deletions

View file

@ -20,6 +20,7 @@ func main() {
var imageName string
var shareWith string
var arch string
var bootMode string
flag.StringVar(&accessKeyID, "access-key-id", "", "access key ID")
flag.StringVar(&secretAccessKey, "secret-access-key", "", "secret access key")
flag.StringVar(&sessionToken, "session-token", "", "session token")
@ -30,6 +31,7 @@ func main() {
flag.StringVar(&imageName, "name", "", "AMI name")
flag.StringVar(&shareWith, "account-id", "", "account id to share image with")
flag.StringVar(&arch, "arch", "", "arch (x86_64 or aarch64)")
flag.StringVar(&bootMode, "boot-mode", "", "boot mode (legacy-bios, uefi, uefi-preferred)")
flag.Parse()
a, err := awscloud.New(region, accessKeyID, secretAccessKey, sessionToken)
@ -50,7 +52,13 @@ func main() {
if shareWith != "" {
share = append(share, shareWith)
}
ami, err := a.Register(imageName, bucketName, keyName, share, arch, nil)
var bootModePtr *string
if bootMode != "" {
bootModePtr = &bootMode
}
ami, err := a.Register(imageName, bucketName, keyName, share, arch, bootModePtr)
if err != nil {
println(err.Error())
return

View file

@ -511,7 +511,7 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
break
}
ami, err := a.Register(jobTarget.ImageName, bucket, targetOptions.Key, targetOptions.ShareWithAccounts, common.CurrentArch(), nil)
ami, err := a.Register(jobTarget.ImageName, bucket, targetOptions.Key, targetOptions.ShareWithAccounts, common.CurrentArch(), targetOptions.BootMode)
if err != nil {
targetResult.TargetError = clienterrors.WorkerClientError(clienterrors.ErrorImportingImage, err.Error(), nil)
break

View file

@ -13,6 +13,15 @@ type AWSTargetOptions struct {
Bucket string `json:"bucket"`
Key string `json:"key"`
ShareWithAccounts []string `json:"shareWithAccounts"`
// Boot mode of the AMI (optional)
// Supported values:
// - ec2.BootModeValuesLegacyBios
// - ec2.BootModeValuesUefi
// - ec2.BootModeValuesUefiPreferred
// If not provided, then the Boot mode will be determined by the default
// boot mode of the instance provisioned from the AMI.
BootMode *string `json:"bootMode,omitempty"`
}
func (AWSTargetOptions) isTargetOptions() {}