Skip to content

Commit

Permalink
Fix unwanted reboot from install config in upgrade/reset (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Itxaka authored Dec 5, 2023
1 parent a89ebf2 commit 6e1d761
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions internal/agent/hooks/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (

type Lifecycle struct{}

func (s Lifecycle) Run(c config.Config, spec v1.Spec) error {
if spec.ShouldReboot() || c.Install.Reboot {
func (s Lifecycle) Run(_ config.Config, spec v1.Spec) error {
if spec.ShouldReboot() {
time.Sleep(5)
utils.Reboot()
}

if spec.ShouldShutdown() || c.Install.Poweroff {
if spec.ShouldShutdown() {
time.Sleep(5)
utils.PowerOFF()
}
Expand Down
33 changes: 18 additions & 15 deletions internal/agent/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,16 @@ func ManualInstall(c, sourceImgURL, device string, reboot, poweroff, strictValid
}

cliConf := generateInstallConfForCLIArgs(sourceImgURL)
cliConfManualArgs := generateInstallConfForManualCLIArgs(device, reboot, poweroff)

cc, err := config.Scan(collector.Directories(configSource),
collector.Readers(strings.NewReader(cliConf)),
collector.Readers(strings.NewReader(cliConf), strings.NewReader(cliConfManualArgs)),
collector.MergeBootLine,
collector.StrictValidation(strictValidations), collector.NoLogs)
if err != nil {
return err
}

if reboot {
// Override from flags!
cc.Install.Reboot = true
}

if poweroff {
// Override from flags!
cc.Install.Poweroff = true
}
if device != "" {
// Override from flags!
cc.Install.Device = device
}

return RunInstall(cc)
}

Expand Down Expand Up @@ -350,3 +338,18 @@ func generateInstallConfForCLIArgs(sourceImageURL string) string {
uri: %s
`, sourceImageURL)
}

// generateInstallConfForManualCLIArgs creates a kairos configuration for flags passed via manual install
func generateInstallConfForManualCLIArgs(device string, reboot, poweroff bool) string {
cfg := fmt.Sprintf(`install:
reboot: %t
poweroff: %t
`, reboot, poweroff)

if device != "" {
cfg += fmt.Sprintf(`
device: %s
`, device)
}
return cfg
}

0 comments on commit 6e1d761

Please sign in to comment.