From 1204d70075aef2fcb71cf28a2768feb244171f5f 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 | 4 ++++ pkg/image/bootc_disk_test.go | 12 +++++++++++- pkg/manifest/raw_bootc.go | 6 +++++- pkg/manifest/raw_bootc_test.go | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/pkg/image/bootc_disk.go b/pkg/image/bootc_disk.go index 2d9a8776f1..a2c27eb9ea 100644 --- a/pkg/image/bootc_disk.go +++ b/pkg/image/bootc_disk.go @@ -23,6 +23,9 @@ type BootcDiskImage struct { ContainerSource *container.SourceSpec + // Customizations + KernelOptionsAppend []string + // "Users" is a bit misleading as only root and its ssh key is supported // right now because that is all that bootc gives us by default but that // will most likely change over time. @@ -54,6 +57,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 5491e706fb..dfe4c2da75 100644 --- a/pkg/manifest/raw_bootc.go +++ b/pkg/manifest/raw_bootc.go @@ -29,6 +29,8 @@ type RawBootcImage struct { // with the image itself PartitionTable *disk.PartitionTable + KernelOptionsAppend []string + // "Users" is a bit misleading as only root and its ssh key is supported // right now because that is all that bootc gives us by default but that // will most likely change over time. @@ -100,7 +102,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) {