From faae6a7c3b9af1411503326335dbbe6de234256c Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Wed, 9 Oct 2019 16:03:30 +0300 Subject: [PATCH 1/2] Add env vars for Slack and Teams URLs --- cmd/flagger/main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/flagger/main.go b/cmd/flagger/main.go index 5556a940..44c4810d 100644 --- a/cmd/flagger/main.go +++ b/cmd/flagger/main.go @@ -286,10 +286,10 @@ func startLeaderElection(ctx context.Context, run func(), ns string, kubeClient func initNotifier(logger *zap.SugaredLogger) (client notifier.Interface) { provider := "slack" - notifierURL := slackURL + notifierURL := fromEnv("SLACK_URL", slackURL) if msteamsURL != "" { provider = "msteams" - notifierURL = msteamsURL + notifierURL = fromEnv("MSTEAMS_URL", msteamsURL) } notifierFactory := notifier.NewFactory(notifierURL, slackUser, slackChannel) @@ -304,3 +304,10 @@ func initNotifier(logger *zap.SugaredLogger) (client notifier.Interface) { } return } + +func fromEnv(envVar string, defaultVal string) string { + if os.Getenv(envVar) != "" { + return os.Getenv(envVar) + } + return defaultVal +} From 1cb09890fb9dd1261339b307880143d8cc3d37cc Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Wed, 9 Oct 2019 16:04:27 +0300 Subject: [PATCH 2/2] Add env to chart options to be used for Slack and Teams URLs --- charts/flagger/templates/deployment.yaml | 4 ++++ charts/flagger/values.yaml | 13 +++++++++++++ cmd/flagger/main.go | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/charts/flagger/templates/deployment.yaml b/charts/flagger/templates/deployment.yaml index 34fb7075..73a1ebb1 100644 --- a/charts/flagger/templates/deployment.yaml +++ b/charts/flagger/templates/deployment.yaml @@ -102,6 +102,10 @@ spec: - --spider - http://localhost:8080/healthz timeoutSeconds: 5 + {{- if .Values.env }} + env: +{{ toYaml .Values.env | indent 12 }} + {{- end }} resources: {{ toYaml .Values.resources | indent 12 }} {{- with .Values.nodeSelector }} diff --git a/charts/flagger/values.yaml b/charts/flagger/values.yaml index c13f37e6..9128fbb2 100644 --- a/charts/flagger/values.yaml +++ b/charts/flagger/values.yaml @@ -32,6 +32,19 @@ msteams: # MS Teams incoming webhook URL url: +#env: +#- name: SLACK_URL +# valueFrom: +# secretKeyRef: +# name: slack +# key: url +#- name: MSTEAMS_URL +# valueFrom: +# secretKeyRef: +# name: msteams +# key: url +env: [] + leaderElection: enabled: false replicaCount: 1 diff --git a/cmd/flagger/main.go b/cmd/flagger/main.go index 44c4810d..529c9b32 100644 --- a/cmd/flagger/main.go +++ b/cmd/flagger/main.go @@ -287,7 +287,7 @@ func startLeaderElection(ctx context.Context, run func(), ns string, kubeClient func initNotifier(logger *zap.SugaredLogger) (client notifier.Interface) { provider := "slack" notifierURL := fromEnv("SLACK_URL", slackURL) - if msteamsURL != "" { + if msteamsURL != "" || os.Getenv("MSTEAMS_URL") != "" { provider = "msteams" notifierURL = fromEnv("MSTEAMS_URL", msteamsURL) }