diff --git a/README.md b/README.md index b70261c..b3abe33 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Flags: --prometheus-url string Prometheus instance to probe for active alerts --reboot-days strings only reboot on these days (default [su,mo,tu,we,th,fr,sa]) --reboot-sentinel string path to file whose existence signals need to reboot (default "/var/run/reboot-required") + --slack-channel string slack channel for reboot notfications --slack-hook-url string slack hook URL for reboot notfications --slack-username string slack username for reboot notfications (default "kured") --start-time string only reboot after this time of day (default "0:00") diff --git a/cmd/kured/main.go b/cmd/kured/main.go index af5ab6c..387e609 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -37,6 +37,7 @@ var ( rebootSentinel string slackHookURL string slackUsername string + slackChannel string podSelectors []string rebootDays []string @@ -81,6 +82,8 @@ func main() { "slack hook URL for reboot notfications") rootCmd.PersistentFlags().StringVar(&slackUsername, "slack-username", "kured", "slack username for reboot notfications") + rootCmd.PersistentFlags().StringVar(&slackChannel, "slack-channel", "", + "slack channel for reboot notfications") rootCmd.PersistentFlags().StringArrayVar(&podSelectors, "blocking-pod-selector", nil, "label selector identifying pods whose presence should prevent reboots") @@ -227,7 +230,7 @@ func drain(nodeID string) { log.Infof("Draining node %s", nodeID) if slackHookURL != "" { - if err := slack.NotifyDrain(slackHookURL, slackUsername, nodeID); err != nil { + if err := slack.NotifyDrain(slackHookURL, slackUsername, slackChannel, nodeID); err != nil { log.Warnf("Error notifying slack: %v", err) } } @@ -252,7 +255,7 @@ func commandReboot(nodeID string) { log.Infof("Commanding reboot") if slackHookURL != "" { - if err := slack.NotifyReboot(slackHookURL, slackUsername, nodeID); err != nil { + if err := slack.NotifyReboot(slackHookURL, slackUsername, slackChannel, nodeID); err != nil { log.Warnf("Error notifying slack: %v", err) } } diff --git a/kured-ds.yaml b/kured-ds.yaml index c33993d..d8e160e 100644 --- a/kured-ds.yaml +++ b/kured-ds.yaml @@ -59,5 +59,6 @@ spec: # - --reboot-sentinel=/var/run/reboot-required # - --slack-hook-url=https://hooks.slack.com/... # - --slack-username=prod +# - --slack-channel=alerting # - --start-time=0:00 # - --time-zone=UTC diff --git a/pkg/notifications/slack/slack.go b/pkg/notifications/slack/slack.go index 9af0b11..30ac4c5 100644 --- a/pkg/notifications/slack/slack.go +++ b/pkg/notifications/slack/slack.go @@ -15,12 +15,14 @@ var ( type body struct { Text string `json:"text,omitempty"` Username string `json:"username,omitempty"` + Channel string `json:"channel,omitempty"` } -func notify(hookURL, username, message string) error { +func notify(hookURL, username, channel, message string) error { msg := body{ Text: message, Username: username, + Channel: channel, } var buf bytes.Buffer @@ -41,10 +43,10 @@ func notify(hookURL, username, message string) error { return nil } -func NotifyDrain(hookURL, username, nodeID string) error { - return notify(hookURL, username, fmt.Sprintf("Draining node %s", nodeID)) +func NotifyDrain(hookURL, username, channel, nodeID string) error { + return notify(hookURL, username, channel, fmt.Sprintf("Draining node %s", nodeID)) } -func NotifyReboot(hookURL, username, nodeID string) error { - return notify(hookURL, username, fmt.Sprintf("Rebooting node %s", nodeID)) +func NotifyReboot(hookURL, username, channel, nodeID string) error { + return notify(hookURL, username, channel, fmt.Sprintf("Rebooting node %s", nodeID)) }