From b7d10d18ebe7005c5471a897f2124d9ce4e1ecd0 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 22 Mar 2024 09:01:54 +0100 Subject: [PATCH] image,manifest: add support for `KernelOptionsAppend` in bootc This commit adds support to include KernelOptionsAppend to a BootcDiskImage. This is important for cloud support. --- pkg/image/bootc_disk.go | 13 ++++++++----- pkg/image/bootc_disk_test.go | 12 +++++++++++- pkg/manifest/raw_bootc.go | 5 ++++- pkg/manifest/raw_bootc_test.go | 2 ++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/pkg/image/bootc_disk.go b/pkg/image/bootc_disk.go index 2c277a027a..f8010c3e7f 100644 --- a/pkg/image/bootc_disk.go +++ b/pkg/image/bootc_disk.go @@ -19,14 +19,16 @@ type BootcDiskImage struct { Platform platform.Platform PartitionTable *disk.PartitionTable - // This is a bit of a lie, only root and it's ssh key is supported - // today because that is all that bootc gives us by default but - // that will most likely change over time. - Users []users.User - Filename string ContainerSource *container.SourceSpec + + // Customizations + KernelOptionsAppend []string + // "Users" is a bit of a lie, only root and it's ssh key is + // supported today because that is all that bootc gives us by + // default but that will most likely change over time. + Users []users.User } func NewBootcDiskImage(container container.SourceSpec) *BootcDiskImage { @@ -53,6 +55,7 @@ func (img *BootcDiskImage) InstantiateManifestFromContainers(m *manifest.Manifes baseImage := manifest.NewRawBootcImage(buildPipeline, containers, img.Platform) baseImage.PartitionTable = img.PartitionTable baseImage.Users = img.Users + baseImage.KernelOptionsAppend = img.KernelOptionsAppend // In BIB, we export multiple images from the same pipeline so we use the // filename as the basename for each export and set the extensions based on diff --git a/pkg/image/bootc_disk_test.go b/pkg/image/bootc_disk_test.go index 92c8a33e68..9301d17556 100644 --- a/pkg/image/bootc_disk_test.go +++ b/pkg/image/bootc_disk_test.go @@ -38,6 +38,8 @@ func makeFakeDigest(t *testing.T) string { type bootcDiskImageTestOpts struct { ImageFormat platform.ImageFormat BIOS bool + + KernelOptionsAppend []string } func makeFakePlatform(opts *bootcDiskImageTestOpts) platform.Platform { @@ -67,6 +69,7 @@ func makeBootcDiskImageOsbuildManifest(t *testing.T, opts *bootcDiskImageTestOpt require.NotNil(t, img) img.Platform = makeFakePlatform(opts) img.PartitionTable = testdisk.MakeFakePartitionTable("/", "/boot", "/boot/efi") + img.KernelOptionsAppend = opts.KernelOptionsAppend m := &manifest.Manifest{} runi := &runner.Fedora{} @@ -129,7 +132,10 @@ func TestBootcDiskImageInstantiateVmdk(t *testing.T) { } func TestBootcDiskImageUsesBootcInstallToFs(t *testing.T) { - osbuildManifest := makeBootcDiskImageOsbuildManifest(t, nil) + opts := &bootcDiskImageTestOpts{ + KernelOptionsAppend: []string{"karg1", "karg2"}, + } + osbuildManifest := makeBootcDiskImageOsbuildManifest(t, opts) // check that bootc.install-to-filesystem is part of the "image" pipeline imagePipeline := findPipelineFromOsbuildManifest(t, osbuildManifest, "image") @@ -147,6 +153,10 @@ func TestBootcDiskImageUsesBootcInstallToFs(t *testing.T) { "filename": "fake-disk.raw", } assert.Equal(t, expectedDiskOpts, devicesDiskOpts) + + // ensure options got passed + bootcOpts := bootcStage["options"].(map[string]interface{}) + assert.Equal(t, []interface{}{"karg1", "karg2"}, bootcOpts["kernel-args"]) } func TestBootcDiskImageExportPipelines(t *testing.T) { diff --git a/pkg/manifest/raw_bootc.go b/pkg/manifest/raw_bootc.go index a519701607..4209a1e4cc 100644 --- a/pkg/manifest/raw_bootc.go +++ b/pkg/manifest/raw_bootc.go @@ -29,6 +29,7 @@ type RawBootcImage struct { // with the image itself PartitionTable *disk.PartitionTable + KernelOptionsAppend []string // This is a bit of a lie, only root and it's ssh key is supported // today because that is all that bootc gives us by default. Users []users.User @@ -98,7 +99,9 @@ func (p *RawBootcImage) serialize() osbuild.Pipeline { if len(p.containerSpecs) != 1 { panic(fmt.Errorf("expected a single container input got %v", p.containerSpecs)) } - opts := &osbuild.BootcInstallToFilesystemOptions{} + opts := &osbuild.BootcInstallToFilesystemOptions{ + Kargs: p.KernelOptionsAppend, + } if len(p.Users) == 1 && p.Users[0].Key != nil { opts.RootSSHAuthorizedKeys = []string{*p.Users[0].Key} } diff --git a/pkg/manifest/raw_bootc_test.go b/pkg/manifest/raw_bootc_test.go index c69cd8f15a..d144654ebb 100644 --- a/pkg/manifest/raw_bootc_test.go +++ b/pkg/manifest/raw_bootc_test.go @@ -49,6 +49,7 @@ func TestRawBootcImageSerialize(t *testing.T) { rawBootcPipeline := manifest.NewRawBootcImage(build, nil, nil) rawBootcPipeline.PartitionTable = testdisk.MakeFakePartitionTable("/", "/boot", "/boot/efi") rawBootcPipeline.Users = []users.User{{Name: "root", Key: common.ToPtr("some-ssh-key")}} + rawBootcPipeline.KernelOptionsAppend = []string{"karg1", "karg2"} rawBootcPipeline.SerializeStart(nil, []container.Spec{{Source: "foo"}}, nil) imagePipeline := rawBootcPipeline.Serialize() @@ -58,6 +59,7 @@ func TestRawBootcImageSerialize(t *testing.T) { require.NotNil(t, bootcInst) opts := bootcInst.Options.(*osbuild.BootcInstallToFilesystemOptions) assert.Equal(t, []string{"some-ssh-key"}, opts.RootSSHAuthorizedKeys) + assert.Equal(t, []string{"karg1", "karg2"}, opts.Kargs) } func TestRawBootcImageSerializeMountsValidated(t *testing.T) {