mirror of
https://github.com/kubereboot/kured.git
synced 2026-02-14 09:29:51 +00:00
adding option to skip rebooting during weekends
This commit is contained in:
@@ -70,6 +70,7 @@ Flags:
|
||||
--reboot-sentinel string path to file whose existence signals need to reboot (default "/var/run/reboot-required")
|
||||
--slack-hook-url string slack hook URL for reboot notfications
|
||||
--slack-username string slack username for reboot notfications (default "kured")
|
||||
--no-weekends-reboot bool option to not restart during weekends (default "false")
|
||||
```
|
||||
|
||||
### Reboot Sentinel File & Period
|
||||
|
||||
@@ -26,15 +26,16 @@ var (
|
||||
version = "unreleased"
|
||||
|
||||
// Command line flags
|
||||
period time.Duration
|
||||
dsNamespace string
|
||||
dsName string
|
||||
lockAnnotation string
|
||||
prometheusURL string
|
||||
alertFilter *regexp.Regexp
|
||||
rebootSentinel string
|
||||
slackHookURL string
|
||||
slackUsername string
|
||||
period time.Duration
|
||||
dsNamespace string
|
||||
dsName string
|
||||
lockAnnotation string
|
||||
prometheusURL string
|
||||
alertFilter *regexp.Regexp
|
||||
rebootSentinel string
|
||||
slackHookURL string
|
||||
slackUsername string
|
||||
noWeekendReboot bool
|
||||
|
||||
// Metrics
|
||||
rebootRequiredGauge = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
@@ -73,6 +74,7 @@ func main() {
|
||||
"slack hook URL for reboot notfications")
|
||||
rootCmd.PersistentFlags().StringVar(&slackUsername, "slack-username", "kured",
|
||||
"slack username for reboot notfications")
|
||||
rootCmd.PersistentFlags().BoolVar(&noWeekendReboot, "no-weekends-reboot", false, "if true no reboots will be performed during weekends")
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -122,6 +124,11 @@ func rebootRequired() bool {
|
||||
func rebootBlocked() bool {
|
||||
if prometheusURL != "" {
|
||||
alertNames, err := alerts.PrometheusActiveAlerts(prometheusURL, alertFilter)
|
||||
weekday := time.Now().Weekday()
|
||||
if noWeekendReboot && (int(weekday) == 0 || int(weekday) == 6) {
|
||||
log.Warnf("Reboot blocked: day of week: %v",weekday)
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
log.Warnf("Reboot blocked: prometheus query error: %v", err)
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user