mirror of
https://github.com/kubereboot/kured.git
synced 2026-05-06 16:36:49 +00:00
Without this patch, we use WriterLevel, which spawns go routines. As we do it at every call of the util commands, we spawn goroutines at every check. This is a problem as it leads to memory management issues. This fixes it by using a buffer for stdout and stderr, then logging the results after the command was executed. To make sure the logging happened at the same place, I inlined the code from utils. This results in duplicated the code. However, this is not a big problem as: - It makes the code more readable - The implementation between checkers and rebooters _ARE_ different -- One definitely NEEDS privileges, while the other does not... Which could lead to later improvements. Removing a "utils" package is not really a big deal (it is kinda a win in itself, as it is an anti-pattern), as the test coverage was kept. Partial-Fix: #1004 Fixes: #1013 Signed-off-by: Jean-Philippe Evrard <open-source@a.spamming.party>
36 lines
1.4 KiB
Go
36 lines
1.4 KiB
Go
package internal
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/kubereboot/kured/pkg/checkers"
|
|
"github.com/kubereboot/kured/pkg/reboot"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// NewRebooter validates the rebootMethod, rebootCommand, and rebootSignal input,
|
|
// then chains to the right constructor.
|
|
func NewRebooter(rebootMethod string, rebootCommand string, rebootSignal int) (reboot.Rebooter, error) {
|
|
switch {
|
|
case rebootMethod == "command":
|
|
log.Infof("Reboot command: %s", rebootCommand)
|
|
return reboot.NewCommandRebooter(rebootCommand)
|
|
case rebootMethod == "signal":
|
|
log.Infof("Reboot signal: %d", rebootSignal)
|
|
return reboot.NewSignalRebooter(rebootSignal)
|
|
default:
|
|
return nil, fmt.Errorf("invalid reboot-method configured %s, expected signal or command", rebootMethod)
|
|
}
|
|
}
|
|
|
|
// NewRebootChecker validates the rebootSentinelCommand, rebootSentinelFile input,
|
|
// then chains to the right constructor.
|
|
func NewRebootChecker(rebootSentinelCommand string, rebootSentinelFile string) (checkers.Checker, error) {
|
|
// An override of rebootSentinelCommand means a privileged command
|
|
if rebootSentinelCommand != "" {
|
|
log.Infof("Sentinel checker is (privileged) user provided command: %s", rebootSentinelCommand)
|
|
return checkers.NewCommandChecker(rebootSentinelCommand, 1, true)
|
|
}
|
|
log.Infof("Sentinel checker is (unprivileged) testing for the presence of: %s", rebootSentinelFile)
|
|
return checkers.NewFileRebootChecker(rebootSentinelFile)
|
|
}
|