diff --git a/README.md b/README.md index d0e7b13c..27b62342 100644 --- a/README.md +++ b/README.md @@ -263,6 +263,7 @@ When invoked, Ankh will operate over both the `haste-server` and `myservice` cha | format | string | Optional. Format of slack message that will be used. See available variables below. | | rollbackFormat | string | Optional. Format of message for rollbacks that will be used. See available variables below. | | pretext | string | Optional. Pretext for slack message. Default is `A new release notification has been received`. | +| channels | []string | Optional. Channel[s} to post the message to. | ##### `Slack Message Variables` | Variable | Description diff --git a/ankh/main.go b/ankh/main.go index 019e271f..607ddf96 100644 --- a/ankh/main.go +++ b/ankh/main.go @@ -299,7 +299,7 @@ func reconcileMissingConfigs(ctx *ankh.ExecutionContext, ankhFile *ankh.AnkhFile } // we should finally have a tag value - if len(ctx.SlackChannels) > 0 { + if len(ctx.AnkhConfig.Slack.Channels) > 0 { ctx.SlackDeploymentVersion = *chart.Tag } } @@ -414,7 +414,8 @@ func execute(ctx *ankh.ExecutionContext) { executeContext(ctx, &rootAnkhFile) } - if len(ctx.SlackChannels) > 0 { + if len(ctx.AnkhConfig.Slack.Channels) > 0 { + ctx.Logger.Debugf("Pinging %d slack channels %+v", len(ctx.AnkhConfig.Slack.Channels), ctx.AnkhConfig.Slack.Channels) if ctx.Mode == ankh.Rollback { ctx.SlackDeploymentVersion = "rollback" } @@ -889,7 +890,9 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Apply - ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel) + if *slackChannel != "" { + ctx.AnkhConfig.Slack.Channels = []string{*slackChannel} + } ctx.SlackMessageOverride = *slackMessageOverride filters := []string{} for _, filter := range *filter { @@ -921,7 +924,7 @@ func main() { ctx.LocalChart = true } ctx.Mode = ankh.Rollback - ctx.SlackChannels = append(ctx.SlackChannels, *slackChannel) + ctx.AnkhConfig.Slack.Channels = append(ctx.AnkhConfig.Slack.Channels, *slackChannel) ctx.SlackMessageOverride = *slackMessageOverride ctx.Filters = []string{"deployment", "statfulset"} diff --git a/context/context.go b/context/context.go index 32fe05d2..7759e6c8 100644 --- a/context/context.go +++ b/context/context.go @@ -53,7 +53,7 @@ type ExecutionContext struct { DataDir string HelmSetValues map[string]string - SlackChannels []string + SlackChannelsOverride []string SlackMessageOverride string SlackDeploymentVersion string @@ -105,12 +105,13 @@ type DockerConfig struct { } type SlackConfig struct { - Token string `yaml:"token"` - Icon string `yaml:"icon-url"` - Username string `yaml:"username"` - Format string `yaml:"format"` - RollbackFormat string `yaml:"rollbackFormat"` - Pretext string `yaml:"pretext"` + Token string `yaml:"token"` + Icon string `yaml:"icon-url"` + Username string `yaml:"username"` + Format string `yaml:"format"` + RollbackFormat string `yaml:"rollbackFormat"` + Pretext string `yaml:"pretext"` + Channels []string `yaml:"channels"` } // AnkhConfig defines the shape of the ~/.ankh/config file used for global diff --git a/helm/helm.go b/helm/helm.go index 9d5adf39..88f4d304 100644 --- a/helm/helm.go +++ b/helm/helm.go @@ -712,7 +712,7 @@ func Publish(ctx *ankh.ExecutionContext) error { resp.Status, resp.StatusCode, upstreamTarballPath) } - ctx.Logger.Debug("Helm registry PUT resp: %+v", resp) + ctx.Logger.Debugf("Helm registry PUT resp: %+v", resp) ctx.Logger.Infof("Finished publishing '%v'", upstreamTarballPath) return nil } diff --git a/slack/slack.go b/slack/slack.go index 52a67e23..c75c8ae3 100644 --- a/slack/slack.go +++ b/slack/slack.go @@ -52,22 +52,22 @@ func PingSlackChannel(ctx *ankh.ExecutionContext) error { Username: username, } - channels := make(map[string]string, len(ctx.SlackChannels)) - for _, ch := range ctx.SlackChannels { + channels := make(map[string]string, len(ctx.AnkhConfig.Slack.Channels)) + for _, ch := range ctx.AnkhConfig.Slack.Channels { channelId, err := getSlackChannelIDByName(api, ch) - if err != nil { - return err - } - channels[ch] = channelId - } + if err != nil { + return err + } + channels[ch] = channelId + } for name, id := range channels { - if !ctx.DryRun { - _, _, err = api.PostMessage(id, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams)) - } else { - ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, name) - } - } + if !ctx.DryRun { + _, _, err = api.PostMessage(id, slack.MsgOptionAttachments(attachment), slack.MsgOptionPostMessageParameters(messageParams)) + } else { + ctx.Logger.Infof("--dry-run set so not sending message '%v' to slack channel %v", messageText, name) + } + } return err }