Skip to content

Commit

Permalink
chore: handle grub option - "wipe"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
DmitriyMV committed Feb 28, 2023
1 parent 594f27d commit bfba367
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ 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)
}
}

// 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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit bfba367

Please sign in to comment.