From 28c53324506629d105f77ebf951f67af24ab728e Mon Sep 17 00:00:00 2001 From: Alexei Tighineanu Date: Sat, 25 Jun 2022 21:08:05 +0200 Subject: [PATCH] added notification when uncordoning (#587) * added notification when uncordoning when reboot & uncordoning is succ essful -> notification will be se nt * added uncordon message tmpl added message template for announcing successful uncor- doning and reboot. * added proper documentation about new flag added readme note about new flag --- README.md | 3 ++- cmd/kured/main.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3687f11..3b281c9 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,7 @@ Flags: --lock-annotation string annotation in which to record locking node (default "weave.works/kured-node-lock") --lock-release-delay duration hold lock after reboot by this duration (default: 0, disabled) --lock-ttl duration expire lock annotation after this duration (default: 0, disabled) + --message-template-uncordon string message template used to notify about a node being successfully uncordoned (default "Node %s rebooted & uncordoned successfully!") --message-template-drain string message template used to notify about a node being drained (default "Draining node %s") --message-template-reboot string message template used to notify about a node being rebooted (default "Rebooting node %s") --notify-url url for reboot notifications (cannot use with --slack-hook-url flags) @@ -275,7 +276,7 @@ about draining and rebooting nodes across a list of technologies. ![Notification](img/slack-notification.png) -Alternatively you can use the `--message-template-drain` and `--message-template-reboot` to customize the text of the message, e.g. +Alternatively you can use the `--message-template-drain`, `--message-template-reboot` and `--message-template-uncordon` to customize the text of the message, e.g. ```cli --message-template-drain="Draining node %s part of *my-cluster* in region *xyz*" diff --git a/cmd/kured/main.go b/cmd/kured/main.go index b930cb6..89b0016 100644 --- a/cmd/kured/main.go +++ b/cmd/kured/main.go @@ -66,6 +66,7 @@ var ( slackChannel string messageTemplateDrain string messageTemplateReboot string + messageTemplateUncordon string podSelectors []string rebootCommand string logFormat string @@ -166,6 +167,8 @@ func NewRootCommand() *cobra.Command { "slack channel for reboot notfications") rootCmd.PersistentFlags().StringVar(¬ifyURL, "notify-url", "", "notify URL for reboot notfications") + rootCmd.PersistentFlags().StringVar(&messageTemplateUncordon, "message-template-uncordon", "Node %s rebooted & uncordoned successfully!", + "message template used to notify about a node being successfully uncordoned") rootCmd.PersistentFlags().StringVar(&messageTemplateDrain, "message-template-drain", "Draining node %s", "message template used to notify about a node being drained") rootCmd.PersistentFlags().StringVar(&messageTemplateReboot, "message-template-reboot", "Rebooting node %s", @@ -635,6 +638,12 @@ func rebootAsRequired(nodeID string, rebootCommand []string, sentinelCommand []s if err != nil { log.Errorf("Unable to uncordon %s: %v, will continue to hold lock and retry uncordon", node.GetName(), err) continue + } else { + if notifyURL != "" { + if err := shoutrrr.Send(notifyURL, fmt.Sprintf(messageTemplateUncordon, nodeID)); err != nil { + log.Warnf("Error notifying: %v", err) + } + } } } // If we're holding the lock we know we've tried, in a prior run, to reboot