Skip to content

Commit

Permalink
Image builder CLI changes to support rhel-9 raw image building (#3032)
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesh-goutham authored Mar 27, 2024
1 parent 904f2ad commit dd38cc8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion projects/aws/image-builder/GIT_TAG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.1
v0.5.0
2 changes: 1 addition & 1 deletion projects/aws/image-builder/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 5 additions & 1 deletion projects/aws/image-builder/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 4 additions & 0 deletions projects/aws/image-builder/builder/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ var SupportedRedHatVersions = []string{
"9",
}

var SupportedRedHatEfiVersions = []string{
"9",
}

var SupportedFirmwares = []string{
BIOS,
EFI,
Expand Down
25 changes: 19 additions & 6 deletions projects/aws/image-builder/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -94,15 +94,15 @@ 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")
}

if err = validateOSVersion(bo.Os, bo.OsVersion); err != nil {
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())
}

Expand Down Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
19 changes: 17 additions & 2 deletions projects/aws/image-builder/cmd/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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",
},
Expand All @@ -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: "",
},
Expand All @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions projects/kubernetes-sigs/image-builder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 $@
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dd38cc8

Please sign in to comment.