Skip to content
This repository has been archived by the owner on May 12, 2022. It is now read-only.

Commit

Permalink
Slack channel handling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven E. Newton committed Apr 24, 2019
1 parent 0300a73 commit e6836dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions ankh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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{}
Expand All @@ -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")
Expand All @@ -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{}
Expand All @@ -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")

Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion slack/slack.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package slack

import (
"errors"
"fmt"
"os/user"
"strings"

ankh "github.com/appnexus/ankh/context"
"github.com/appnexus/ankh/util"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e6836dd

Please sign in to comment.