Skip to content

Commit d596638

Browse files
authored
Merge pull request #872 from L3o-pold/feature/add-alerting-http-proxy
Add alerting http proxy option
2 parents 37abdbb + b82fd5e commit d596638

File tree

22 files changed

+109
-26
lines changed

22 files changed

+109
-26
lines changed

artifacts/flagger/crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@ spec:
11811181
address:
11821182
description: Hook URL address of this provider
11831183
type: string
1184+
proxy:
1185+
description: Http/s proxy of this provider
1186+
type: string
11841187
secretRef:
11851188
description: Kubernetes secret reference containing the provider address
11861189
type: object

charts/flagger/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ Parameter | Description | Default
125125
`configTracking.enabled` | If `true`, flagger will track changes in Secrets and ConfigMaps referenced in the target deployment | `true`
126126
`eventWebhook` | If set, Flagger will publish events to the given webhook | None
127127
`slack.url` | Slack incoming webhook | None
128+
`slack.proxyUrl` | Slack proxy url | None
128129
`slack.channel` | Slack channel | None
129130
`slack.user` | Slack username | `flagger`
130131
`msteams.url` | Microsoft Teams incoming webhook | None
132+
`msteams.proxyUrl` | Microsoft Teams proxy url | None
131133
`podMonitor.enabled` | If `true`, create a PodMonitor for [monitoring the metrics](https://docs.flagger.app/usage/monitoring#metrics) | `false`
132134
`podMonitor.namespace` | Namespace where the PodMonitor is created | the same namespace
133135
`podMonitor.interval` | Interval at which metrics should be scraped | `15s`

charts/flagger/crds/crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,9 @@ spec:
11811181
address:
11821182
description: Hook URL address of this provider
11831183
type: string
1184+
proxy:
1185+
description: Http/s proxy of this provider
1186+
type: string
11841187
secretRef:
11851188
description: Kubernetes secret reference containing the provider address
11861189
type: object

charts/flagger/templates/deployment.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ spec:
9090
{{- if .Values.slack.url }}
9191
- -slack-url={{ .Values.slack.url }}
9292
{{- end }}
93+
{{- if .Values.slack.proxyUrl }}
94+
- -slack-proxy-url={{ .Values.slack.proxyUrl }}
95+
{{- end }}
9396
{{- if .Values.slack.user }}
9497
- -slack-user={{ .Values.slack.user }}
9598
{{- end }}
@@ -99,6 +102,9 @@ spec:
99102
{{- if .Values.msteams.url }}
100103
- -msteams-url={{ .Values.msteams.url }}
101104
{{- end }}
105+
{{- if .Values.msteams.proxyUrl }}
106+
- -msteams-proxy-url={{ .Values.msteams.proxyUrl }}
107+
{{- end }}
102108
{{- if .Values.leaderElection.enabled }}
103109
- -enable-leader-election=true
104110
- -leader-election-namespace={{ .Release.Namespace }}

charts/flagger/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ slack:
5555
channel:
5656
# incoming webhook https://api.slack.com/incoming-webhooks
5757
url:
58+
proxy:
5859

5960
msteams:
6061
# MS Teams incoming webhook URL
@@ -72,11 +73,21 @@ podMonitor:
7273
# secretKeyRef:
7374
# name: slack
7475
# key: url
76+
#- name: SLACK_PROXY_URL
77+
# valueFrom:
78+
# secretKeyRef:
79+
# name: slack
80+
# key: proxy-url
7581
#- name: MSTEAMS_URL
7682
# valueFrom:
7783
# secretKeyRef:
7884
# name: msteams
7985
# key: url
86+
#- name: MSTEAMS_PROXY_URL
87+
# valueFrom:
88+
# secretKeyRef:
89+
# name: msteams
90+
# key: proxy-url
8091
#- name: EVENT_WEBHOOK_URL
8192
# valueFrom:
8293
# secretKeyRef:

cmd/flagger/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ var (
6363
logLevel string
6464
port string
6565
msteamsURL string
66+
msteamsProxyURL string
6667
includeLabelPrefix string
6768
slackURL string
69+
slackProxyURL string
6870
slackUser string
6971
slackChannel string
7072
eventWebhook string
@@ -93,10 +95,12 @@ func init() {
9395
flag.StringVar(&logLevel, "log-level", "debug", "Log level can be: debug, info, warning, error.")
9496
flag.StringVar(&port, "port", "8080", "Port to listen on.")
9597
flag.StringVar(&slackURL, "slack-url", "", "Slack hook URL.")
98+
flag.StringVar(&slackProxyURL, "slack-proxy-url", "", "Slack proxy URL.")
9699
flag.StringVar(&slackUser, "slack-user", "flagger", "Slack user name.")
97100
flag.StringVar(&slackChannel, "slack-channel", "", "Slack channel.")
98101
flag.StringVar(&eventWebhook, "event-webhook", "", "Webhook for publishing flagger events")
99102
flag.StringVar(&msteamsURL, "msteams-url", "", "MS Teams incoming webhook URL.")
103+
flag.StringVar(&msteamsProxyURL, "msteams-proxy-url", "", "MS Teams proxy URL.")
100104
flag.StringVar(&includeLabelPrefix, "include-label-prefix", "", "List of prefixes of labels that are copied when creating primary deployments or daemonsets. Use * to include all.")
101105
flag.IntVar(&threadiness, "threadiness", 2, "Worker concurrency.")
102106
flag.BoolVar(&zapReplaceGlobals, "zap-replace-globals", false, "Whether to change the logging level of the global zap logger.")
@@ -349,11 +353,13 @@ func startLeaderElection(ctx context.Context, run func(), ns string, kubeClient
349353
func initNotifier(logger *zap.SugaredLogger) (client notifier.Interface) {
350354
provider := "slack"
351355
notifierURL := fromEnv("SLACK_URL", slackURL)
356+
notifierProxyURL := fromEnv("SLACK_PROXY_URL", slackProxyURL)
352357
if msteamsURL != "" || os.Getenv("MSTEAMS_URL") != "" {
353358
provider = "msteams"
354359
notifierURL = fromEnv("MSTEAMS_URL", msteamsURL)
360+
notifierProxyURL = fromEnv("MSTEAMS_PROXY_URL", msteamsProxyURL)
355361
}
356-
notifierFactory := notifier.NewFactory(notifierURL, slackUser, slackChannel)
362+
notifierFactory := notifier.NewFactory(notifierURL, notifierProxyURL, slackUser, slackChannel)
357363

358364
var err error
359365
client, err = notifierFactory.Notifier(provider)

docs/gitbook/usage/alerting.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Once the webhook has been generated. Flagger can be configured to send Slack not
2020
```bash
2121
helm upgrade -i flagger flagger/flagger \
2222
--set slack.url=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK \
23+
--set slack.proxy-url=my-http-proxy.com \ # optional http/s proxy
2324
--set slack.channel=general \
2425
--set slack.user=flagger
2526
```
@@ -41,7 +42,8 @@ Flagger can be configured to send notifications to Microsoft Teams:
4142

4243
```bash
4344
helm upgrade -i flagger flagger/flagger \
44-
--set msteams.url=https://outlook.office.com/webhook/YOUR/TEAMS/WEBHOOK
45+
--set msteams.url=https://outlook.office.com/webhook/YOUR/TEAMS/WEBHOOK \
46+
--set msteams.proxy-url=my-http-proxy.com # optional http/s proxy
4547
```
4648

4749
Similar to Slack, Flagger alerts on canary analysis events:
@@ -71,6 +73,8 @@ spec:
7173
username: flagger
7274
# webhook address (ignored if secretRef is specified)
7375
address: https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
76+
# optional http/s proxy
77+
proxy: http://my-http-proxy.com
7478
# secret containing the webhook address (optional)
7579
secretRef:
7680
name: on-call-url

kustomize/base/flagger/crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,9 @@ spec:
11771177
address:
11781178
description: Hook URL address of this provider
11791179
type: string
1180+
proxy:
1181+
description: Http/s proxy of this provider
1182+
type: string
11801183
secretRef:
11811184
description: Kubernetes secret reference containing the provider address
11821185
type: object

pkg/apis/flagger/v1beta1/alert.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ type AlertProviderSpec struct {
6464
// +optional
6565
Address string `json:"address,omitempty"`
6666

67+
// HTTP/S address of the proxy
68+
// +optional
69+
Proxy string `json:"proxy,omitempty"`
70+
6771
// Secret reference containing the provider webhook URL
6872
// +optional
6973
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"`

pkg/controller/events.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,13 @@ func (c *Controller) alert(canary *flaggerv1.Canary, message string, metadata bo
149149
if provider.Spec.Channel != "" {
150150
channel = provider.Spec.Channel
151151
}
152+
proxy := ""
153+
if provider.Spec.Proxy != "" {
154+
proxy = provider.Spec.Proxy
155+
}
152156

153157
// create notifier based on provider type
154-
f := notifier.NewFactory(url, username, channel)
158+
f := notifier.NewFactory(url, proxy, username, channel)
155159
n, err := f.Notifier(provider.Spec.Type)
156160
if err != nil {
157161
c.logger.With("canary", fmt.Sprintf("%s.%s", canary.Name, canary.Namespace)).

0 commit comments

Comments
 (0)