-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #990 from evrardjp/first_refactors
Cleanup Part 1 - First refactors
- Loading branch information
Showing
19 changed files
with
1,053 additions
and
955 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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) | ||
} | ||
log.Infof("Sentinel checker is (unprivileged) testing for the presence of: %s", rebootSentinelFile) | ||
return checkers.NewFileRebootChecker(rebootSentinelFile) | ||
} |
Oops, something went wrong.