From e6836ddbca66bd0c9e64800c530086a21d8d2965 Mon Sep 17 00:00:00 2001 From: "Steven E. Newton" Date: Wed, 24 Apr 2019 11:57:25 -0400 Subject: [PATCH] Slack channel handling fixes --- ankh/main.go | 12 ++++++------ slack/slack.go | 6 +++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ankh/main.go b/ankh/main.go index 4da5e0c4..c304acce 100644 --- a/ankh/main.go +++ b/ankh/main.go @@ -306,7 +306,7 @@ func main() { dryRun := cmd.BoolOpt("dry-run", false, "Perform a dry-run and don't actually apply anything to a cluster") chart := cmd.StringOpt("chart", "", "Limits the apply command to only the specified chart") chartPath := cmd.StringOpt("chart-path", "", "Use a local chart directory instead of a remote, versioned chart") - slackChannel := cmd.StringOpt("s slack", "", "Send slack message to specified slack channel about application update") + slackChannels := cmd.StringOpt("s slack", "", "Send slack message to specified slack channel about application update") slackMessageOverride := cmd.StringOpt("m slack-message", "", "Override the default slack message being sent") createJiraTicket := cmd.BoolOpt("j jira-ticket", false, "Create a JIRA ticket to track update") filter := cmd.StringsOpt("filter", []string{}, "Kubernetes object kinds to include for the action. The entries in this list are case insensitive. Any object whose `kind:` does not match this filter will be excluded from the action") @@ -320,7 +320,7 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Apply - ctx.SlackChannels = strings.Split(*slackChannel, ","); + ctx.SlackChannels = strings.Split(*slackChannels, ","); ctx.SlackMessageOverride = *slackMessageOverride ctx.CreateJiraTicket = *createJiraTicket filters := []string{} @@ -341,7 +341,7 @@ func main() { dryRun := cmd.BoolOpt("dry-run", false, "Perform a dry-run and don't actually deploy anything to a cluster") chart := cmd.StringOpt("chart", "", "Limits the deploy command to only the specified chart") chartPath := cmd.StringOpt("chart-path", "", "Use a local chart directory instead of a remote, versioned chart") - slackChannel := cmd.StringOpt("s slack", "", "Send slack message to specified slack channel about application update") + slackChannels := cmd.StringOpt("s slack", "", "Send slack message to specified slack channel(s) about application update") slackMessageOverride := cmd.StringOpt("m slack-message", "", "Override the default slack message being sent") createJiraTicket := cmd.BoolOpt("j jira-ticket", false, "Create a JIRA ticket to track update") filter := cmd.StringsOpt("filter", []string{}, "Kubernetes object kinds to include for the action. The entries in this list are case insensitive. Any object whose `kind:` does not match this filter will be excluded from the action") @@ -355,7 +355,7 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Apply - ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel) + ctx.SlackChannels = append(ctx.SlackChannels, strings.Split(*slackChannels, ",")...) ctx.SlackMessageOverride = *slackMessageOverride ctx.CreateJiraTicket = *createJiraTicket filters := []string{} @@ -376,7 +376,7 @@ func main() { dryRun := cmd.BoolOpt("dry-run", false, "Perform a dry-run and don't actually rollback anything to a cluster") chart := cmd.StringOpt("chart", "", "Limits the rollback command to only the specified chart") chartPath := cmd.StringOpt("chart-path", "", "Use a local chart directory instead of a remote, versioned chart") - slackChannel := cmd.StringOpt("s slack", "", "Send slack message to specified slack channel about application update") + slackChannels := cmd.StringOpt("s slack", "", "Send slack message to specified slack channel about application update") slackMessageOverride := cmd.StringOpt("m slack-message", "", "Override the default slack message being sent") createJiraTicket := cmd.BoolOpt("j jira-ticket", false, "Create a JIRA ticket to track update") @@ -389,7 +389,7 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Rollback - ctx.AnkhConfig.Slack.Channels = append(ctx.AnkhConfig.Slack.Channels, *slackChannel) + ctx.AnkhConfig.Slack.Channels = append(ctx.AnkhConfig.Slack.Channels, strings.Split(*slackChannels, ",")...) ctx.SlackMessageOverride = *slackMessageOverride ctx.CreateJiraTicket = *createJiraTicket diff --git a/slack/slack.go b/slack/slack.go index a5829e9f..95f7a2a4 100644 --- a/slack/slack.go +++ b/slack/slack.go @@ -1,8 +1,10 @@ package slack import ( + "errors" "fmt" "os/user" + "strings" ankh "github.com/appnexus/ankh/context" "github.com/appnexus/ankh/util" @@ -61,15 +63,17 @@ func PingSlackChannel(ctx *ankh.ExecutionContext) error { channels[ch] = channelId } + var errs []string for name, id := range channels { if !ctx.DryRun { _, _, err = api.PostMessage(id, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams)) + errs = append(errs, err.Error()) } else { ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, name) } } - return err + return errors.New(strings.Join(errs, "\n")) } func getSlackChannelIDByName(api *slack.Client, channelName string) (string, error) {