diff --git a/pkg/imager/profile/output.go b/pkg/imager/profile/output.go index 7d70dadbf..938c4015d 100644 --- a/pkg/imager/profile/output.go +++ b/pkg/imager/profile/output.go @@ -157,6 +157,11 @@ func (o *Output) FillDefaults(arch, version string, secureboot bool) { } func (o *Output) selectBootloader(current BootloaderKind, arch, version string, secureboot bool) BootloaderKind { + // If already set, return the current value, secureboot shouldn't allow changing it. + if current != BootLoaderKindNone && !secureboot { + return current + } + useSDBoot := quirks.New(version).UseSDBootForUEFI() switch { @@ -171,10 +176,6 @@ func (o *Output) selectBootloader(current BootloaderKind, arch, version string, return BootLoaderKindGrub default: // Default to dual-boot if not overridden. - if current == BootLoaderKindNone { - return BootLoaderKindDualBoot - } - - return current + return BootLoaderKindDualBoot } } diff --git a/pkg/imager/profile/output_test.go b/pkg/imager/profile/output_test.go index 27065bb80..48b1a4a39 100644 --- a/pkg/imager/profile/output_test.go +++ b/pkg/imager/profile/output_test.go @@ -23,7 +23,7 @@ func createOutputWithDefaults(kind profile.OutputKind, arch, version string, sec return out } -func createOutputWithOverride(kind profile.OutputKind, bootloader profile.BootloaderKind, arch, version string, secureBoot bool) profile.Output { +func createOutputWithOverride(kind profile.OutputKind, bootloader profile.BootloaderKind, secureBoot bool) profile.Output { out := profile.Output{ Kind: kind, } @@ -34,14 +34,12 @@ func createOutputWithOverride(kind profile.OutputKind, bootloader profile.Bootlo Bootloader: bootloader, } case profile.OutKindISO: - if quirks.New(version).ISOSupportsSettingBootloader() { - out.ISOOptions = &profile.ISOOptions{ - Bootloader: bootloader, - } + out.ISOOptions = &profile.ISOOptions{ + Bootloader: bootloader, } } - out.FillDefaults(arch, version, secureBoot) + out.FillDefaults("amd64", "v1.12.0", secureBoot) return out } @@ -108,65 +106,37 @@ func TestBootloaderOverride(t *testing.T) { t.Parallel() tests := []struct { - arch string - version string - secureBoot bool - override profile.BootloaderKind - wantImage profile.BootloaderKind + name string + secureBoot bool + override profile.BootloaderKind + expectedBootloader profile.BootloaderKind }{ - // Talos < 1.10: GRUB is forced, overrides are ignored - {"amd64", "1.9.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub}, - {"amd64", "1.9.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindGrub}, // forced to GRUB - {"amd64", "1.9.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindGrub}, // forced to GRUB - {"amd64", "1.9.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - {"arm64", "1.9.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub}, - {"arm64", "1.9.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindGrub}, // forced to GRUB - {"arm64", "1.9.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - - // Talos 1.10-1.11: amd64 respects override, arm64 forced to sd-boot - {"amd64", "1.10.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub}, - {"amd64", "1.10.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindSDBoot}, - {"amd64", "1.10.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindDualBoot}, - {"amd64", "1.10.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - {"arm64", "1.10.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // arm64 >= 1.10 forces sd-boot - {"arm64", "1.10.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - {"amd64", "1.11.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub}, - {"amd64", "1.11.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindDualBoot}, - {"amd64", "1.11.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - {"arm64", "1.11.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // arm64 >= 1.10 forces sd-boot - {"arm64", "1.11.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - - // Talos >= 1.12: amd64 respects override, arm64 forced to sd-boot - {"amd64", "1.12.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub}, - {"amd64", "1.12.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindSDBoot}, - {"amd64", "1.12.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindDualBoot}, - {"amd64", "1.12.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot - {"arm64", "1.12.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // arm64 >= 1.10 forces sd-boot - {"arm64", "1.12.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot + { + "non-secureboot override to sd-boot", + false, + profile.BootLoaderKindSDBoot, + profile.BootLoaderKindSDBoot, + }, + { + "secureboot override to grub", + true, + profile.BootLoaderKindGrub, + profile.BootLoaderKindSDBoot, + }, } for _, tt := range tests { - name := tt.arch + "-" + tt.version + "-override-" + tt.override.String() - if tt.secureBoot { - name += "-secureboot" - } - - t.Run(name, func(t *testing.T) { + t.Run(tt.name, func(t *testing.T) { t.Parallel() // Test Image output with override - img := createOutputWithOverride(profile.OutKindImage, tt.override, tt.arch, tt.version, tt.secureBoot) + img := createOutputWithOverride(profile.OutKindImage, tt.override, tt.secureBoot) require.NotNil(t, img.ImageOptions) - require.Equal(t, tt.wantImage, img.ImageOptions.Bootloader) + require.Equal(t, tt.expectedBootloader, img.ImageOptions.Bootloader) // Test ISO output with override - iso := createOutputWithOverride(profile.OutKindISO, tt.override, tt.arch, tt.version, tt.secureBoot) - if quirks.New(tt.version).ISOSupportsSettingBootloader() { - require.NotNil(t, iso.ISOOptions) - require.Equal(t, tt.wantImage, iso.ISOOptions.Bootloader) - } else { - require.Nil(t, iso.ISOOptions) - } + iso := createOutputWithOverride(profile.OutKindISO, tt.override, tt.secureBoot) + require.Equal(t, tt.expectedBootloader, iso.ISOOptions.Bootloader) }) } } diff --git a/pkg/xfs/opentree/opentree_other.go b/pkg/xfs/opentree/opentree_other.go new file mode 100644 index 000000000..3522b8cfb --- /dev/null +++ b/pkg/xfs/opentree/opentree_other.go @@ -0,0 +1,11 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +//go:build !linux + +// Package opentree provides a simple interface to create and manage a subfilesystem +// using the `open_tree` syscall. It allows for creating a new subfilesystem +// by cloning an existing filesystem tree and provides a method to close the filesystem +// when it is no longer needed. +package opentree