chore: handle grub option - "wipe"

This PR ensures that we can handle third grub option - "wipe". We will use it in 1.4.

For #6842

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
This commit is contained in:
Dmitriy Matrenichev 2023-02-28 16:20:40 +03:00
parent 594f27d878
commit bfba3677b0
No known key found for this signature in database
GPG Key ID: D3363CF894E68892
5 changed files with 28 additions and 7 deletions

View File

@ -19,6 +19,8 @@ func FlipBootLabel(e BootLabel) (BootLabel, error) {
return BootB, nil
case BootB:
return BootA, nil
case BootReset:
fallthrough
default:
return "", fmt.Errorf("invalid entry: %s", e)
}
@ -26,13 +28,14 @@ func FlipBootLabel(e BootLabel) (BootLabel, error) {
// ParseBootLabel parses the given human-readable boot label to a grub.BootLabel.
func ParseBootLabel(name string) (BootLabel, error) {
if strings.HasPrefix(name, string(BootA)) {
switch {
case strings.HasPrefix(name, string(BootA)):
return BootA, nil
}
if strings.HasPrefix(name, string(BootB)) {
case strings.HasPrefix(name, string(BootB)):
return BootB, nil
case strings.HasPrefix(name, "Reset"):
return BootReset, nil
default:
return "", fmt.Errorf("could not parse boot entry from name: %s", name)
}
return "", fmt.Errorf("could not parse boot entry from name: %s", name)
}

View File

@ -13,6 +13,9 @@ const (
// BootB is a bootloader label.
BootB BootLabel = "B"
// BootReset is a bootloader label.
BootReset BootLabel = "Reset"
// ConfigPath is the path to the grub config.
ConfigPath = constants.BootMountPoint + "/grub/grub.cfg"
)

View File

@ -106,6 +106,10 @@ func parseEntries(conf []byte) (map[BootLabel]MenuEntry, error) {
return nil, err
}
if bootEntry == BootReset {
continue
}
entries[bootEntry] = MenuEntry{
Name: name,
Linux: linux,

View File

@ -77,6 +77,10 @@ func TestParseBootLabel(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, grub.BootB, label)
label, err = grub.ParseBootLabel("Reset Talos installation and return to maintenance mode\n")
assert.NoError(t, err)
assert.Equal(t, grub.BootReset, label)
_, err = grub.ParseBootLabel("C - v3")
assert.Error(t, err)
}
@ -94,7 +98,7 @@ func TestWrite(t *testing.T) {
tempFile, _ := os.CreateTemp("", "talos-test-grub-*.cfg")
defer os.Remove(tempFile.Name())
t.Cleanup(func() { require.NoError(t, os.Remove(tempFile.Name())) })
config := grub.NewConfig("cmdline A")

View File

@ -20,3 +20,10 @@ menuentry "B - v2" {
linux /B/vmlinuz cmdline B
initrd /B/initramfs.xz
}
menuentry "Reset Talos installation and return to maintenance mode" {
set gfxmode=auto
set gfxpayload=text
linux /A/vmlinuz cmdline A talos.experimental.wipe=system:EPHEMERAL,STATE
initrd /A/initramfs.xz
}