From dd38cc843bd15f5b6e03f9b6860e917cac1bd4f6 Mon Sep 17 00:00:00 2001 From: Vignesh Goutham Ganesh <72776369+vignesh-goutham@users.noreply.github.com> Date: Wed, 27 Mar 2024 16:09:32 -0500 Subject: [PATCH] Image builder CLI changes to support rhel-9 raw image building (#3032) --- projects/aws/image-builder/GIT_TAG | 2 +- projects/aws/image-builder/README.md | 2 +- projects/aws/image-builder/builder/builder.go | 6 ++++- projects/aws/image-builder/builder/types.go | 4 +++ projects/aws/image-builder/cmd/build.go | 25 ++++++++++++++----- projects/aws/image-builder/cmd/build_test.go | 19 ++++++++++++-- .../kubernetes-sigs/image-builder/Makefile | 12 ++++++--- 7 files changed, 56 insertions(+), 14 deletions(-) diff --git a/projects/aws/image-builder/GIT_TAG b/projects/aws/image-builder/GIT_TAG index 5aff472ddf..b043aa648f 100644 --- a/projects/aws/image-builder/GIT_TAG +++ b/projects/aws/image-builder/GIT_TAG @@ -1 +1 @@ -v0.4.1 +v0.5.0 diff --git a/projects/aws/image-builder/README.md b/projects/aws/image-builder/README.md index 53a4d59709..2c79eeac77 100644 --- a/projects/aws/image-builder/README.md +++ b/projects/aws/image-builder/README.md @@ -1,5 +1,5 @@ ## **Image Builder Tool** -![Version](https://img.shields.io/badge/version-v0.4.1-blue) +![Version](https://img.shields.io/badge/version-v0.5.0-blue) ![Build Status](https://codebuild.us-west-2.amazonaws.com/badges?uuid=eyJlbmNyeXB0ZWREYXRhIjoiRHQ0UnNzTElaQyt5eDI5OG9XYUhYQW85WXE5RzI3Sjd5YWFwK2d2aHBVb2R4dS8xek5aeUcrVHJFN05JR2JnbWx2aGRURlAxdDZrNFQwMFRaMzY4MWU0PSIsIml2UGFyYW1ldGVyU3BlYyI6InIxUHNId1RQcCs3SzlFWWQiLCJtYXRlcmlhbFNldFNlcmlhbCI6MX0%3D&branch=main) Image Builder Tool is a cli that builds EKS-A compatible Kubernetes node images. The tool is based on upstream diff --git a/projects/aws/image-builder/builder/builder.go b/projects/aws/image-builder/builder/builder.go index d1887b31dc..a4f3584f26 100644 --- a/projects/aws/image-builder/builder/builder.go +++ b/projects/aws/image-builder/builder/builder.go @@ -203,7 +203,11 @@ func (b *BuildOptions) BuildImage() { case Ubuntu: buildCommand = fmt.Sprintf("make -C %s local-build-raw-ubuntu-%s", imageBuilderProjectPath, b.OsVersion) case RedHat: - buildCommand = fmt.Sprintf("make -C %s local-build-raw-redhat-%s", imageBuilderProjectPath, b.OsVersion) + if b.Firmware == EFI { + buildCommand = fmt.Sprintf("make -C %s local-build-raw-redhat-%s-efi", imageBuilderProjectPath, b.OsVersion) + } else { + buildCommand = fmt.Sprintf("make -C %s local-build-raw-redhat-%s", imageBuilderProjectPath, b.OsVersion) + } commandEnvVars = append(commandEnvVars, fmt.Sprintf("%s=%s", rhelUsernameEnvVar, b.BaremetalConfig.RhelUsername), fmt.Sprintf("%s=%s", rhelPasswordEnvVar, b.BaremetalConfig.RhelPassword), diff --git a/projects/aws/image-builder/builder/types.go b/projects/aws/image-builder/builder/types.go index 4e33440abf..e6c924b9d7 100644 --- a/projects/aws/image-builder/builder/types.go +++ b/projects/aws/image-builder/builder/types.go @@ -30,6 +30,10 @@ var SupportedRedHatVersions = []string{ "9", } +var SupportedRedHatEfiVersions = []string{ + "9", +} + var SupportedFirmwares = []string{ BIOS, EFI, diff --git a/projects/aws/image-builder/cmd/build.go b/projects/aws/image-builder/cmd/build.go index c289016da8..8e2f29e2a9 100644 --- a/projects/aws/image-builder/cmd/build.go +++ b/projects/aws/image-builder/cmd/build.go @@ -51,7 +51,7 @@ func init() { buildCmd.Flags().StringVar(&additionalFilesConfigFile, "files-config", "", "Path to Config file specifying additional files to be copied into EKS-A node image") buildCmd.Flags().StringVar(&bo.ReleaseChannel, "release-channel", "1-27", "EKS-D Release channel for node image. Can be 1-24, 1-25, 1-26, 1-27 or 1-28") buildCmd.Flags().BoolVar(&bo.Force, "force", false, "Force flag to clean up leftover files from previous execution") - buildCmd.Flags().StringVar(&bo.Firmware, "firmware", "", "Desired firmware for image build. EFI is only supported for Ubuntu OVA and Raw builds.") + buildCmd.Flags().StringVar(&bo.Firmware, "firmware", "", "Desired firmware for image build. EFI is only supported for Ubuntu OVA & Raw, and Redhat 9 RAW builds.") buildCmd.Flags().StringVar(&bo.EKSAReleaseVersion, "eksa-release", "", "The EKS-A CLI version to build images for") buildCmd.Flags().StringVar(&bo.ManifestTarball, "manifest-tarball", "", "Path to Image Builder built EKS-D/A manifest tarball") buildCmd.Flags().IntVar(&bo.AnsibleVerbosity, "ansible-verbosity", 0, "Verbosity level for the Ansible tasks run during image building, should be in the range 0-6") @@ -94,7 +94,7 @@ func ValidateInputs(bo *builder.BuildOptions) error { bo.OsVersion = "8" } - if bo.Hypervisor != builder.Nutanix && bo.Hypervisor != builder.CloudStack && bo.Os == builder.RedHat && bo.OsVersion != "8" { + if bo.Hypervisor != builder.Nutanix && bo.Hypervisor != builder.CloudStack && bo.Hypervisor != builder.Baremetal && bo.Os == builder.RedHat && bo.OsVersion != "8" { log.Fatalf("Invalid OS version for RedHat. Please choose 8") } @@ -102,7 +102,7 @@ func ValidateInputs(bo *builder.BuildOptions) error { log.Fatal(err.Error()) } - if err = validateFirmware(bo.Firmware, bo.Os, bo.Hypervisor); err != nil { + if err = validateFirmware(bo.Firmware, bo.Os, bo.OsVersion, bo.Hypervisor); err != nil { log.Fatal(err.Error()) } @@ -382,7 +382,7 @@ func validateOSVersion(os, osVersion string) error { return nil } -func validateFirmware(firmware, os, hypervisor string) error { +func validateFirmware(firmware, os, osVersion, hypervisor string) error { if firmware == "" { return nil } @@ -391,8 +391,21 @@ func validateFirmware(firmware, os, hypervisor string) error { return fmt.Errorf("%s is not a firmware. Please select one of %s", firmware, strings.Join(builder.SupportedFirmwares, ",")) } - if firmware == builder.EFI && (os != builder.Ubuntu || !builder.SliceContains([]string{builder.VSphere, builder.Baremetal}, hypervisor)) { - return fmt.Errorf("EFI firmware is only supported for Ubuntu OVA and Raw builds.") + if firmware == builder.EFI { + if os == builder.Ubuntu && !builder.SliceContains([]string{builder.VSphere, builder.Baremetal}, hypervisor) { + return fmt.Errorf("For Ubuntu, EFI firmware is only supported for OVA and Raw builds") + } + if os == builder.RedHat { + if hypervisor != builder.Baremetal { + return fmt.Errorf("For RedHat, EFI firmware is only supported for Raw builds") + } + if !builder.SliceContains(builder.SupportedRedHatEfiVersions, osVersion) { + return fmt.Errorf("Only RedHat version 9 supports EFI firmware") + } + } + if !builder.SliceContains([]string{builder.RedHat, builder.Ubuntu}, os) { + return fmt.Errorf("EFI firmware is only support for Ubuntu and Redhat OS") + } } if firmware == builder.BIOS && os == builder.Ubuntu && hypervisor == builder.Baremetal { diff --git a/projects/aws/image-builder/cmd/build_test.go b/projects/aws/image-builder/cmd/build_test.go index a2b876a318..c2b60560c6 100644 --- a/projects/aws/image-builder/cmd/build_test.go +++ b/projects/aws/image-builder/cmd/build_test.go @@ -173,6 +173,7 @@ func TestValidateFirmware(t *testing.T) { testName: "Ubuntu ova with efi", buildOptions: builder.BuildOptions{ Os: "ubuntu", + OsVersion: "22", Hypervisor: "vsphere", Firmware: "efi", }, @@ -182,6 +183,7 @@ func TestValidateFirmware(t *testing.T) { testName: "Ubuntu raw with efi", buildOptions: builder.BuildOptions{ Os: "ubuntu", + OsVersion: "22", Hypervisor: "baremetal", Firmware: "efi", }, @@ -191,6 +193,7 @@ func TestValidateFirmware(t *testing.T) { testName: "Ubuntu raw with bios", buildOptions: builder.BuildOptions{ Os: "ubuntu", + OsVersion: "20", Hypervisor: "baremetal", Firmware: "bios", }, @@ -200,15 +203,17 @@ func TestValidateFirmware(t *testing.T) { testName: "Redhat raw with efi", buildOptions: builder.BuildOptions{ Os: "redhat", + OsVersion: "9", Hypervisor: "baremetal", Firmware: "efi", }, - wantErr: "EFI firmware is only supported for Ubuntu OVA and Raw builds.", + wantErr: "", }, { testName: "Redhat raw with no bios", buildOptions: builder.BuildOptions{ Os: "redhat", + OsVersion: "8", Hypervisor: "baremetal", Firmware: "", }, @@ -223,11 +228,21 @@ func TestValidateFirmware(t *testing.T) { }, wantErr: "bad is not a firmware. Please select one of bios,efi", }, + { + testName: "Redhat raw with unsupported efi version", + buildOptions: builder.BuildOptions{ + Os: "redhat", + OsVersion: "8", + Hypervisor: "baremetal", + Firmware: "efi", + }, + wantErr: "Only RedHat version 9 supports EFI firmware", + }, } for _, tt := range testCases { t.Run(tt.testName, func(t *testing.T) { - err := validateFirmware(tt.buildOptions.Firmware, tt.buildOptions.Os, tt.buildOptions.Hypervisor) + err := validateFirmware(tt.buildOptions.Firmware, tt.buildOptions.Os, tt.buildOptions.OsVersion, tt.buildOptions.Hypervisor) if tt.wantErr == "" { assert.NoError(t, err) } else { diff --git a/projects/kubernetes-sigs/image-builder/Makefile b/projects/kubernetes-sigs/image-builder/Makefile index ede6cac545..b4073ff3d7 100644 --- a/projects/kubernetes-sigs/image-builder/Makefile +++ b/projects/kubernetes-sigs/image-builder/Makefile @@ -187,7 +187,7 @@ DEFAULT_REDHAT_VERSION=8 ALLOWED_BOTTLEROCKET_VERSIONS=1 DEFAULT_BOTTLEROCKET_VERSION=1 -ALLOWED_EFI_OS_FORMATS=ubuntu-ova +ALLOWED_EFI_OS_FORMATS=ubuntu-ova redhat-raw # run image os/format validation before running release target(s) RELEASE_TARGETS=validate-supported-image-all @@ -426,8 +426,8 @@ validate-supported-image-%: elif [ -n "$(IMAGE_OS_FIRMWARE)" ] && [[ "$(IMAGE_OS_FIRMWARE)" != "efi" ]]; then \ echo "efi is the only supported custom firmware"; \ exit 1; \ - elif [ -n "$(IMAGE_OS_FIRMWARE)" ] && [[ "$(ALLOWED_EFI_OS_FORMATS)" != *"$(IMAGE_OS)-$(IMAGE_FORMAT)" ]]; then \ - echo "EFI is only supported for Ubuntu OVAs"; \ + elif [ -n "$(IMAGE_OS_FIRMWARE)" ] && [[ "$(ALLOWED_EFI_OS_FORMATS)" != *"$(IMAGE_OS)-$(IMAGE_FORMAT)"* ]]; then \ + echo "EFI is only supported for Ubuntu OVAs and Redhat RAW builds"; \ exit 1; \ fi @@ -464,6 +464,10 @@ local-build-ova-rhel-8: local-build-ova-redhat-8 local-build-raw-rhel-8: local-build-raw-redhat-8 @echo Done building $@ +.PHONY: local-build-raw-rhel-9-efi +local-build-raw-rhel-9: local-build-raw-redhat-9-efi + @echo Done building $@ + .PHONY: local-build-qemu-rhel-8 local-build-qemu-rhel-8: local-build-cloudstack-redhat-8 @echo Done building $@ @@ -520,9 +524,11 @@ release-ova-redhat-8: build-raw-ubuntu-2004: build-raw-ubuntu-2204: build-raw-redhat-8: +build-raw-redhat-9-efi: release-raw-ubuntu-2004: release-raw-ubuntu-2204: release-raw-redhat-8: +release-raw-redhat-9-efi: build-cloudstack-redhat-8: build-cloudstack-redhat-9: