If you are using Argo CD for GitOps-style deployment of Kubernetes applications, then you should get notified about the real-time application changes to various environments. In such cases, Argo CD Notifications can be used for providing updates about application deployments or any status change for better collaboration.
With argoCD Notifications, we can continuously monitor CD pipeline. And with slack, team members can check the status of CD pipeline anytime, anywhere.
In this guide we will learn how to configure argocd to send notifications to slack on events.
Based on various scenarios, Argo CD Notifications provides a series of triggers to notify users. Examples of use-case in Argo CD when these triggers can be fired:
- Application created
- Application deleted
- Application deployed
- Application health degraded
- Application sync failed
- App sync running
- App sync status unknown
- App sync succeeded
Prerequisites
Before proceeding, please know that the guide assumes that you have ArgoCD installed and running. If not, checkout How to Deploy and Configure Argocd in Kubernetes first.
Creating a Slack Application
Create a Slack app using the below URL.
1
| https://api.slack.com/apps?new_app=1
|
Click on Create New App
. Choose From Scratch
.
Fill in the App name
, such as Argocd Notifications
and select your Slack workspace as below.
Once application is created navigate to OAuth & Permissions
in the left sidebar and in that page, scroll down to Scopes
.
Now, add a scope for this Bot (Argocd Notifications
), so select Two scopes for the time being.
chat:write
chat:write.customize
Once Scope is configured, Scroll back to the top (OAuth Tokens for Your Workspace
), click Install to Workspace button and confirm the Installation.
Once installation is completed copy the Bot User OAuth Token
.
Creating a slack channel
Create a Slack channel, either public or private, based on your requirement. If you have a channel or a workspace for tracking all the deployment changes, ignore this sentense.
Next, Browse your argocd channel and add the bot you created in the previous step, in this case, the bot name is Argocd Notifications
.
If you forget to add this, you will NOT receive notifications.
After adding the Bot to the Slack channel. We need to make some changes to our ArgoCD configuration files.
ArgoCD Config Changes
Assuming your slack token is — xoxp-yyy-zzz
In your argocd configuration, look for the Secret argocd-notifications-secret
.
1
2
3
4
5
6
| apiVersion: v1
kind: Secret
metadata:
name: argocd-notifications-secret
stringData:
slack-token: "xoxp-yyy-zzz"
|
Save the file above as argocd-notifications-secret.yaml
.
Now Apply:
1
| kubectl apply -f argocd-notifications-secret.yaml
|
Finally, use the OAuth token to configure the Slack integration.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
| apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.slack: |
token: $slack-token # use as it is
defaultTriggers: |
- on-deployed
trigger.on-deployed: |
- description: Application is synced and healthy. Triggered once per commit.
oncePer: app.status.operationState.syncResult.revision
send:
- app-deployed
when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy' and app.status.sync.status == 'Synced'
template.app-deployed: |
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} is now running new version of deployments manifests.
slack:
attachments: |
[{
"title": "{{ .app.metadata.name}}",
"title_link":"{{.context.argocdUrl}}/applications/{{.app.metadata.name}}",
"color": "#18be52",
"fields": [
{
"title": "Sync Status",
"value": "{{.app.status.sync.status}}",
"short": true
},
{
"title": "Repository",
"value": "{{.app.spec.source.repoURL}}",
"short": true
},
{
"title": "Revision",
"value": "{{.app.status.sync.revision}}",
"short": true
}
{{range $index, $c := .app.status.conditions}}
{{if not $index}},{{end}}
{{if $index}},{{end}}
{
"title": "{{$c.type}}",
"value": "{{$c.message}}",
"short": true
}
{{end}}
]
}]
|
Save the file above as argocd-notifications-cm.yaml
.
Now Apply;
1
| kubectl apply -f argocd-notifications-cm.yaml
|
For these changes to apply, please restart your argocd server applications:
1
| kubectl rollout restart deploy -n argocd
|
Create a Slack integration Notification subscriptions
The subscription to Argo CD application events can be defined using notifications.argoproj.io/subscribe.<trigger>.<service>: <recipient>
annotation. For example, the following annotation subscribes two Slack channels to notifications about every successful synchronization of the Argo CD application:
1
2
3
4
5
6
| apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
annotations:
notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my-channel1;my-channel2
Annotation key consists of following parts:
|
on-sync-succeeded
- trigger nameslack
- notification service namemy-channel1;my-channel2
- a semicolon separated list of recipients
This is an example of a citizixapp
application:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: stage-citizixapp
namespace: argocd
annotations:
notifications.argoproj.io/subscribe.on-deployed.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-health-degraded.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-sync-succeeded.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-sync-failed.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-sync-status-unknown.slack: argocd-notifications
spec:
destination:
name: in-cluster
namespace: stage
project: main-cluster-apps
source:
path: citizixapp/stage/main-957c4ac
repoURL: https://github.com/etowett/argo-k8s-releases
targetRevision: main
syncPolicy:
automated:
prune: true
|
You can create subscriptions for all applications of the Argo CD project by adding the same annotation to AppProject
CRD:
1
2
3
4
5
| apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
annotations:
notifications.argoproj.io/subscribe.on-sync-succeeded.slack: my-channel1;my-channel2
|
If your applications are part of an application project (like main-cluster-apps
in my case), you can just annotate that project then for all applications belonging to it, notifications will be sent on the specified events. Take a look at the yaml below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
name: main-cluster-apps
namespace: argocd
# Finalizer that ensures that project is not deleted until it is not referenced by any application
finalizers:
- resources-finalizer.argocd.argoproj.io
annotations:
notifications.argoproj.io/subscribe.on-deployed.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-health-degraded.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-sync-succeeded.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-sync-failed.slack: argocd-notifications
notifications.argoproj.io/subscribe.on-sync-status-unknown.slack: argocd-notifications
spec:
description: Project for argocd local cluster citizix-releases related resources
# Allow manifests to deploy from kubernetes Git repo
sourceRepos:
- "https://github.com/etowett/citizix-releases.git"
# Permit applications to deploy to any namespace in local argocd cluster
destinations:
- namespace: "*"
server: "https://kubernetes.default.svc"
# Allow to deploy any resource
clusterResourceWhitelist:
- group: "*"
kind: "*"
|
Testing
Now deploy your service and test the notification.