Cleanup checkers

Without this, the checkers are only shell calls: test -f
sentinelFile, or sentinelCommand.

This changes the behaviour of existing code to test file for
sentinelFile checker, and to keep the sentinel command as
a command.

However, to avoid having validation in the root loop, it moves
to use a constructor to cleanup the code.

Signed-off-by: Jean-Philippe Evrard <open-source@a.spamming.party>
This commit is contained in:
Jean-Philippe Evrard
2024-10-19 15:51:04 +02:00
parent 36e6c8b4d8
commit f43ed1484e
3 changed files with 62 additions and 50 deletions
+3 -14
View File
@@ -28,8 +28,6 @@ import (
"k8s.io/client-go/rest"
kubectldrain "k8s.io/kubectl/pkg/drain"
"github.com/google/shlex"
shoutrrr "github.com/containrrr/shoutrrr"
"github.com/kubereboot/kured/pkg/alerts"
"github.com/kubereboot/kured/pkg/daemonsetlock"
@@ -744,20 +742,11 @@ func root(cmd *cobra.Command, args []string) {
var checker checkers.Checker
// An override of rebootsentinelcommand means a privileged command
if rebootSentinelCommand != "" {
log.Infof("Sentinel checker is user provided command: %s", rebootSentinelCommand)
cmd, err := shlex.Split(rebootSentinelCommand)
if err != nil {
log.Fatalf("Error parsing provided sentinel command: %v", err)
}
checker = checkers.NsEnterRebootChecker{
CustomCheckCommand: cmd,
NamespacePid: 1,
}
log.Infof("Sentinel checker is (privileged) user provided command: %s", rebootSentinelCommand)
checker = checkers.NewCommandChecker(rebootSentinelCommand)
} else {
log.Infof("Sentinel checker is (unprivileged) testing for the presence of: %s", rebootSentinelFile)
checker = checkers.UnprivilegedRebootChecker{
CheckCommand: []string{"test", "-f", rebootSentinelFile},
}
checker = checkers.NewFileRebootChecker(rebootSentinelFile)
}
go rebootAsRequired(nodeID, rebooter, checker, window, lockTTL, lockReleaseDelay)