I'm using the stable/prometheus
helm chart and I've configured a custom values file that further configures alertmanager for the chart deployment. I can install the chart via Helm3 without any issues, however, there's one thing I'm not able to figure out. For the Slack Reciever/slack_configs/api_url
I want to pass that through the set
command so I don't have to keep it hardcoded into file.
I hope I'm on the right path, and here's what I'm thinking of running to access the value.
helm install test-release stable/prometheus -f customALM.yml --set alertmanagerFiles.alertmanager.yml.receivers[0].api_url=https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/xxxxxxxxxxxxxxxxxxxxxxxxxxx
customALM.yml
alertmanagerFiles:
alertmanager.yml:
route:
group_wait: 10s
group_interval: 5m
repeat_interval: 30m
receiver: "slack"
routes:
- receiver: "slack"
group_wait: 10s
match_re:
severity: error|warning
continue: true
receivers:
- name: "slack"
slack_configs:
- api_url: '[howDoIsetThisAtTheCLI?'
channel: 'someChannel'
text: "Text message template etc."
Update 4/8: I'm making progress thanks to willro! I'm able to get a value inserted but it puts it at the root of the alertmanager block. I've tried a few different combinations to access receivers/slack_configs but no luck yet =/
helm install test-release stable/prometheus -f customALM.yml --set alertmanagerFiles.api_url=PleaseInsertPrettyPlease --dry-run
Update 4/9: I've decided to move the receivers block into a separate file that's encrypted and stored securely.
Running the command to change the URL after its been deployed is definitely an option that I want to have.
I'd like to write this answer to give you this option!
You can chain a few commands with SED to edit data on that ConfigMap (it's very similar to what kubectl edit
does!)
For that you will need to use the string deployed on the customALM.yml
. For this example I set the parameter as api_url: ChangeMeLater
before deploying.
Then I deployed the chart with helm install test-release stable/prometheus -f customALM.yml
Lastly we run:
kubectl get cm <CONFIG_MAP_NAME> -o yaml | sed -e "s,<OLD_VALUE>,<NEW_VALUE>,g" | kubectl replace -f -
Explaining what's going on:
kubectl get cm <CONFIG_MAP_NAME> -o yaml |
= gets the deployed configmap in yaml format and pipe it to the next commandsed -e "s,<OLD_VALUE>,<NEW_VALUE>,g" |
= use sed
to replace old_value
for new_value
and pipe it to the next comandkubectl replace -f -
= use the output from the last command and replace the object currently deployed with the same name.I'll leave an example here step by step to elucidate more:
$ helm install test-release stable/prometheus -f customALM.yml
Release "test-release" has been installed. Happy Helming!
...
$ kubectl get cm
NAME DATA AGE
test-release-prometheus-alertmanager 1 44m
test-release-prometheus-server 5 44m
$ kubectl get cm test-release-prometheus-alertmanager -o yaml
apiVersion: v1
data:
alertmanager.yml: |
global: {}
receivers:
- name: slack
slack_configs:
- api_url: ChangeMeLater
channel: someChannel
text: Text message template etc.
route:
group_interval: 5m
group_wait: 10s
receiver: slack
repeat_interval: 30m
routes:
- continue: true
group_wait: 10s
match_re:
severity: error|warning
receiver: slack
kind: ConfigMap
metadata:
creationTimestamp: "2020-04-10T13:41:15Z"
labels:
app: prometheus
chart: prometheus-11.0.6
component: alertmanager
heritage: Helm
release: test-release
name: test-release-prometheus-alertmanager
namespace: default
resourceVersion: "218148"
selfLink: /api/v1/namespaces/default/configmaps/test-release-prometheus-alertmanager
uid: 323fdd40-2f29-4cde-833c-c6300d5688c0
$ kubectl get cm test-release-prometheus-alertmanager -o yaml | sed -e "s,ChangeMeLater,theurl.com/any,g" | kubectl replace -f -
configmap/test-release-prometheus-alertmanager replaced
$ kubectl get cm test-release-prometheus-alertmanager -o yaml
apiVersion: v1
data:
alertmanager.yml: |
global: {}
receivers:
- name: slack
slack_configs:
- api_url: theurl.com/any
channel: someChannel
text: Text message template etc.
route:
group_interval: 5m
group_wait: 10s
receiver: slack
repeat_interval: 30m
routes:
- continue: true
group_wait: 10s
match_re:
severity: error|warning
receiver: slack
kind: ConfigMap
metadata:
creationTimestamp: "2020-04-10T13:41:15Z"
labels:
app: prometheus
chart: prometheus-11.0.6
component: alertmanager
heritage: Helm
release: test-release
name: test-release-prometheus-alertmanager
namespace: default
resourceVersion: "219507"
selfLink: /api/v1/namespaces/default/configmaps/test-release-prometheus-alertmanager
uid: 323fdd40-2f29-4cde-833c-c6300d5688c0
You can see that the command changed the ChangeMeLater
for theurl.com/any
.
I'm still thinking about your first option, but this is a good workaround to have in hand.
If you have any doubt let me know!