Featured image of post Configuring Slack notifications for ArgoCD and Remark42

Configuring Slack notifications for ArgoCD and Remark42

In a previous post: ArgoCD email notifications with Gmail, I set up email notifications for ArgoCD. Recently, in the process of setting up Remark42, I learned that both services support Slack notifications as well.

Personally, I think there are a few advantages to using Slack notifications over email:

  1. Faster: Slack notifications are usually faster than emails.
  2. Channel separation: You can create a separate channel for notifications. For example, having one for production and another for staging environment.
  3. Slack bots: They are easy to create, and have a nice UI to configure them.

This will be a post about setting up a Slack bot, and configuring ArgoCD and Remark42 to send notifications with it.

Slack bot

First step is to create a Slack channel. I have created one for all my homelab related stuff. If you don’t have one yet, head over to Slack and create one.

Next, create a Slack app here: Create an App. Example:
Create App
Name and workspace

Go to “OAuth & Permissions” section and add the following scopes:
Go Scopes

Install the app to your workspace.
Install Confirm install

Copy the “Bot User OAuth Token” from the “OAuth & Permissions” section. This will be used by ArgoCD and Remark42 to interact with the bot.
OAuth Token

Lastly, on Slack, invite the bot to the channel you want to receive notifications in. I have invited mine to “production” and “staging” channels in my workspace.
Invite

ArgoCD configuration

Official docs: Slack

First, if you haven’t already, install ArgoCD notifications controller.

1
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/notifications_catalog/install.yaml

Then deploy this secret to your ArgoCD namespace:

1
2
3
4
5
6
7
apiVersion: v1
kind: Secret
metadata:
  name: argocd-notifications-secret
  namespace: argocd
stringData:
  slack-token: <YOUR_SLACK_BOT_TOKEN>

To let notifications controller use the token, add the followig to argocd-notifications-cm configmap data:

1
2
  service.slack: |
    token: $slack-token    

In the same configmap, also add the following “defaultTriggers” field. Since I want to use the same set of triggers for multiple applications, I find this to be a easy way to set up.

1
2
3
4
5
6
7
defaultTriggers: |
  - on-sync-running
  - on-sync-succeeded
  - on-sync-failed
  - on-health-degraded
  - on-deployed
  - on-sync-status-unknown  

To use these triggers, edit an ArgoCD application manifest and add the following:

1
2
3
4
metadata:
  annotations:
    # add this:
    notifications.argoproj.io/subscribe.slack: <slack-channel>

For the slack channel, I used “production” and “staging” as mentioned earlier.

Optional: edit the default templates specified in the same configmap, as shown in the official docs.

Now test it by syncing an application. You should see a notification in the specified Slack channel.
Sync an app
Message

Remark42 configuration

Official docs: Notification

For Remark42, essentially we just need three environment variables to be set. Since I’m using Kustomize, I declared them like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
configMapGenerator:
- name: blog-cm
  literals:
  # ...
  - NOTIFY_ADMINS=slack
  - NOTIFY_SLACK_CHAN=production
secretGenerator:
- name: remark42
  literals:
  # ...
  - NOTIFY_SLACK_TOKEN=<YOUR_SLACK_BOT_TOKEN>

And in the deployment manifest, I added the following to the environment variables:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
- name: NOTIFY_ADMINS
  valueFrom:
    configMapKeyRef:
      name: blog-cm
      key: NOTIFY_ADMINS
- name: NOTIFY_SLACK_CHAN
  valueFrom:
    configMapKeyRef:
      name: blog-cm
      key: NOTIFY_SLACK_CHAN
- name: NOTIFY_SLACK_TOKEN
  valueFrom:
    secretKeyRef:
      name: remark42
      key: NOTIFY_SLACK_TOKEN

Test it by posting a comment. You should see a notification in the specified Slack channel.
Comment
Message

Built with Hugo
Theme Stack designed by Jimmy