Skip to content

Commit cf014cb

Browse files
committed
fix: only set default bootloader if none is set
Only set a default bootloader if none is set, secureboot still always return `sd-boot`. Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent e9b016f commit cf014cb

File tree

3 files changed

+42
-60
lines changed

3 files changed

+42
-60
lines changed

pkg/imager/profile/output.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (o *Output) FillDefaults(arch, version string, secureboot bool) {
157157
}
158158

159159
func (o *Output) selectBootloader(current BootloaderKind, arch, version string, secureboot bool) BootloaderKind {
160+
// If already set, return the current value, secureboot shouldn't allow changing it.
161+
if current != BootLoaderKindNone && !secureboot {
162+
return current
163+
}
164+
160165
useSDBoot := quirks.New(version).UseSDBootForUEFI()
161166

162167
switch {
@@ -171,10 +176,6 @@ func (o *Output) selectBootloader(current BootloaderKind, arch, version string,
171176
return BootLoaderKindGrub
172177
default:
173178
// Default to dual-boot if not overridden.
174-
if current == BootLoaderKindNone {
175-
return BootLoaderKindDualBoot
176-
}
177-
178-
return current
179+
return BootLoaderKindDualBoot
179180
}
180181
}

pkg/imager/profile/output_test.go

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func createOutputWithDefaults(kind profile.OutputKind, arch, version string, sec
2323
return out
2424
}
2525

26-
func createOutputWithOverride(kind profile.OutputKind, bootloader profile.BootloaderKind, arch, version string, secureBoot bool) profile.Output {
26+
func createOutputWithOverride(kind profile.OutputKind, bootloader profile.BootloaderKind, secureBoot bool) profile.Output {
2727
out := profile.Output{
2828
Kind: kind,
2929
}
@@ -34,14 +34,12 @@ func createOutputWithOverride(kind profile.OutputKind, bootloader profile.Bootlo
3434
Bootloader: bootloader,
3535
}
3636
case profile.OutKindISO:
37-
if quirks.New(version).ISOSupportsSettingBootloader() {
38-
out.ISOOptions = &profile.ISOOptions{
39-
Bootloader: bootloader,
40-
}
37+
out.ISOOptions = &profile.ISOOptions{
38+
Bootloader: bootloader,
4139
}
4240
}
4341

44-
out.FillDefaults(arch, version, secureBoot)
42+
out.FillDefaults("amd64", "v1.12.0", secureBoot)
4543

4644
return out
4745
}
@@ -108,65 +106,37 @@ func TestBootloaderOverride(t *testing.T) {
108106
t.Parallel()
109107

110108
tests := []struct {
111-
arch string
112-
version string
113-
secureBoot bool
114-
override profile.BootloaderKind
115-
wantImage profile.BootloaderKind
109+
name string
110+
secureBoot bool
111+
override profile.BootloaderKind
112+
expectedBootloader profile.BootloaderKind
116113
}{
117-
// Talos < 1.10: GRUB is forced, overrides are ignored
118-
{"amd64", "1.9.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub},
119-
{"amd64", "1.9.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindGrub}, // forced to GRUB
120-
{"amd64", "1.9.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindGrub}, // forced to GRUB
121-
{"amd64", "1.9.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
122-
{"arm64", "1.9.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub},
123-
{"arm64", "1.9.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindGrub}, // forced to GRUB
124-
{"arm64", "1.9.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
125-
126-
// Talos 1.10-1.11: amd64 respects override, arm64 forced to sd-boot
127-
{"amd64", "1.10.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub},
128-
{"amd64", "1.10.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindSDBoot},
129-
{"amd64", "1.10.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindDualBoot},
130-
{"amd64", "1.10.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
131-
{"arm64", "1.10.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // arm64 >= 1.10 forces sd-boot
132-
{"arm64", "1.10.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
133-
{"amd64", "1.11.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub},
134-
{"amd64", "1.11.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindDualBoot},
135-
{"amd64", "1.11.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
136-
{"arm64", "1.11.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // arm64 >= 1.10 forces sd-boot
137-
{"arm64", "1.11.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
138-
139-
// Talos >= 1.12: amd64 respects override, arm64 forced to sd-boot
140-
{"amd64", "1.12.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindGrub},
141-
{"amd64", "1.12.0", false, profile.BootLoaderKindSDBoot, profile.BootLoaderKindSDBoot},
142-
{"amd64", "1.12.0", false, profile.BootLoaderKindDualBoot, profile.BootLoaderKindDualBoot},
143-
{"amd64", "1.12.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
144-
{"arm64", "1.12.0", false, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // arm64 >= 1.10 forces sd-boot
145-
{"arm64", "1.12.0", true, profile.BootLoaderKindGrub, profile.BootLoaderKindSDBoot}, // secureboot forces sd-boot
114+
{
115+
"non-secureboot override to sd-boot",
116+
false,
117+
profile.BootLoaderKindSDBoot,
118+
profile.BootLoaderKindSDBoot,
119+
},
120+
{
121+
"secureboot override to grub",
122+
true,
123+
profile.BootLoaderKindGrub,
124+
profile.BootLoaderKindSDBoot,
125+
},
146126
}
147127

148128
for _, tt := range tests {
149-
name := tt.arch + "-" + tt.version + "-override-" + tt.override.String()
150-
if tt.secureBoot {
151-
name += "-secureboot"
152-
}
153-
154-
t.Run(name, func(t *testing.T) {
129+
t.Run(tt.name, func(t *testing.T) {
155130
t.Parallel()
156131

157132
// Test Image output with override
158-
img := createOutputWithOverride(profile.OutKindImage, tt.override, tt.arch, tt.version, tt.secureBoot)
133+
img := createOutputWithOverride(profile.OutKindImage, tt.override, tt.secureBoot)
159134
require.NotNil(t, img.ImageOptions)
160-
require.Equal(t, tt.wantImage, img.ImageOptions.Bootloader)
135+
require.Equal(t, tt.expectedBootloader, img.ImageOptions.Bootloader)
161136

162137
// Test ISO output with override
163-
iso := createOutputWithOverride(profile.OutKindISO, tt.override, tt.arch, tt.version, tt.secureBoot)
164-
if quirks.New(tt.version).ISOSupportsSettingBootloader() {
165-
require.NotNil(t, iso.ISOOptions)
166-
require.Equal(t, tt.wantImage, iso.ISOOptions.Bootloader)
167-
} else {
168-
require.Nil(t, iso.ISOOptions)
169-
}
138+
iso := createOutputWithOverride(profile.OutKindISO, tt.override, tt.secureBoot)
139+
require.Equal(t, tt.expectedBootloader, iso.ISOOptions.Bootloader)
170140
})
171141
}
172142
}

pkg/xfs/opentree/opentree_other.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
//go:build !linux
6+
7+
// Package opentree provides a simple interface to create and manage a subfilesystem
8+
// using the `open_tree` syscall. It allows for creating a new subfilesystem
9+
// by cloning an existing filesystem tree and provides a method to close the filesystem
10+
// when it is no longer needed.
11+
package opentree

0 commit comments

Comments
 (0)