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 committed Mar 22, 2024
1 parent 592b14d commit b7d10d1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
13 changes: 8 additions & 5 deletions pkg/image/bootc_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
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
5 changes: 4 additions & 1 deletion pkg/manifest/raw_bootc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
}
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 b7d10d1

Please sign in to comment.