Skip to content

Commit

Permalink
Add error to reboot interface
Browse files Browse the repository at this point in the history
Without this, impossible to bubble up errors to main

Signed-off-by: Jean-Philippe Evrard <[email protected]>
  • Loading branch information
evrardjp committed Oct 19, 2024
1 parent a2c2631 commit 4fe8ce6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
6 changes: 5 additions & 1 deletion cmd/kured/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,11 @@ func rebootAsRequired(nodeID string, rebooter reboot.Rebooter, checker checkers.
}
}
log.Infof("Triggering reboot for node %v", nodeID)
rebooter.Reboot()

err = rebooter.Reboot()
if err != nil {
log.Fatalf("Unable to reboot node: %v", err)
}
for {
log.Infof("Waiting for reboot")
time.Sleep(time.Minute)
Expand Down
5 changes: 3 additions & 2 deletions pkg/reboot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ type CommandRebooter struct {
}

// Reboot triggers the reboot command
func (c CommandRebooter) Reboot() {
func (c CommandRebooter) Reboot() error {
log.Infof("Invoking command: %s", c.RebootCommand)
if err := util.NewCommand(c.RebootCommand[0], c.RebootCommand[1:]...).Run(); err != nil {
log.Fatalf("Error invoking reboot command: %v", err)
return fmt.Errorf("error invoking reboot command %s: %v", c.RebootCommand, err)
}
return nil
}

// NewCommandRebooter is the constructor to create a CommandRebooter from a string not
Expand Down
2 changes: 1 addition & 1 deletion pkg/reboot/reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// The Reboot method does not expect any return, yet should
// most likely be refactored in the future to return an error
type Rebooter interface {
Reboot()
Reboot() error
}

// NewRebooter validates the rebootMethod, rebootCommand, and rebootSignal input,
Expand Down
11 changes: 4 additions & 7 deletions pkg/reboot/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"os"
"syscall"

log "github.com/sirupsen/logrus"
)

// SignalRebooter holds context-information for a signal reboot.
Expand All @@ -14,20 +12,19 @@ type SignalRebooter struct {
}

// Reboot triggers the reboot signal
func (c SignalRebooter) Reboot() {
log.Infof("Invoking signal: %v", c.Signal)

func (c SignalRebooter) Reboot() error {
process, err := os.FindProcess(1)
if err != nil {
log.Fatalf("Not running on Unix: %v", err)
return fmt.Errorf("not running on Unix: %v", err)
}

err = process.Signal(syscall.Signal(c.Signal))
// Either PID does not exist, or the signal does not work. Hoping for
// a decent enough error.
if err != nil {
log.Fatalf("Signal of SIGRTMIN+5 failed: %v", err)
return fmt.Errorf("signal of SIGRTMIN+5 failed: %v", err)
}
return nil
}

// NewSignalRebooter is the constructor which sets the signal number.
Expand Down

0 comments on commit 4fe8ce6

Please sign in to comment.