Skip to content

Commit

Permalink
image,manifest: add support for KernelOptionsAppend in bootc
Browse files Browse the repository at this point in the history
This commit adds support to include KernelOptionsAppend to a
BootcDiskImage. This is important for cloud support.
  • Loading branch information
mvo5 authored and achilleas-k committed Mar 26, 2024
1 parent 4de1cbe commit 58ef1ae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion pkg/image/bootc_disk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/manifest/raw_bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/manifest/raw_bootc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 58ef1ae

Please sign in to comment.