Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/osbuild: clean up genMountsForBootupd #685

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pkg/osbuild/bootupd_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"sort"

"github.com/osbuild/images/internal/common"
"github.com/osbuild/images/pkg/disk"
)

Expand Down Expand Up @@ -85,19 +86,19 @@ func genMountsForBootupd(source string, pt *disk.PartitionTable) ([]Mount, error
if part.Payload == nil {
continue
}
// TODO: support things like LVM here via supporting "disk.Container"
mnt, ok := part.Payload.(disk.Mountable)
if !ok {
return nil, fmt.Errorf("type %v not supported by bootupd handling yet", mnt)
}

partNum := idx + 1
mount, err := genOsbuildMount(source, mnt)
if err != nil {
return nil, err
// TODO: support things like LVM here via supporting "disk.Container"
switch payload := part.Payload.(type) {
case disk.Mountable:
mount, err := genOsbuildMount(source, payload)
if err != nil {
return nil, err
}
mount.Partition = common.ToPtr(idx + 1)
mounts = append(mounts, *mount)
default:
return nil, fmt.Errorf("type %T not supported by bootupd handling yet", part.Payload)
}
mount.Partition = &partNum
mounts = append(mounts, *mount)
}
// this must be sorted in so that mounts do not shadow each other
sort.Slice(mounts, func(i, j int) bool {
Expand Down
13 changes: 13 additions & 0 deletions pkg/osbuild/bootupd_stage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,19 @@ func TestGenBootupdDevicesMountsMissingRoot(t *testing.T) {
assert.EqualError(t, err, "required mounts for bootupd stage [/ /boot /boot/efi] missing")
}

func TestGenBootupdDevicesMountsUnexpectedEntity(t *testing.T) {
filename := "fake-disk.img"
pt := &disk.PartitionTable{
Partitions: []disk.Partition{
{
Payload: &disk.LVMVolumeGroup{},
},
},
}
_, _, err := osbuild.GenBootupdDevicesMounts(filename, pt)
assert.EqualError(t, err, "type *disk.LVMVolumeGroup not supported by bootupd handling yet")
}

var fakePt = &disk.PartitionTable{
UUID: "D209C89E-EA5E-4FBD-B161-B461CCE297E0",
Type: "gpt",
Expand Down
Loading