Setup Notification with “Argo CD Notifications” with helm installation Argo CD

Add notification on your argocd to tell you about app status via telegram

Fauzan R
btech-engineering
4 min readNov 15, 2022

--

argocd send notification to telegram

Argo CD Notifications

Argo CD Notifications continuously monitors Argo CD applications and provides a flexible way to notify users about important changes in the application state. Using a flexible mechanism of triggers and templates you can configure when the notification should be sent as well as notification content. Argo CD Notifications includes the catalog of useful triggers and templates. So you can just use them instead of reinventing new ones. — Argo Docs

We can use ArgoCD Notification as part of Continuous Monitoring on our CICD Stack. In this article we’ll try to create notification from argocd to telegram, if you read the documentation you will find another notification-service such as Telegram, Teams, Slack and Etc.

In this scenario we will monitor fruit-apple app as sample app in development cluster.

Demo

Flow monitoring and Notification

Flow Notification

Before config argocd, you must have bot and add bot to group for notification. The bot will send notification in this group, and id group telegram will use as subscript. You can see reference to create bot telegram via BotFather.

Install Argo CD Notification

in this section, I recommend you use the ArgoCD Notification bundle on Helm ArgoCD. And for article i using argocd installation with helm chart.

ArgoCD Installation

On values.yaml Helm Chart ArgoCD, scroll down to “notification” section. Enable this module and add URL of argocd.

notifications:
enabled: true
name: notifications-controller

# -- Argo CD dashboard url; used in place of {{.context.argocdUrl}} in templates
argocdUrl: "https://argocd.mydomain"

Add telegram bot token to secret in section notification.secret.item

notifications:
secret:
# -- Whether helm chart creates controller secret
create: true
# -- Generic key:value pairs to be inserted into the secret
## Can be used for templates, notification services etc. Some examples given below.
## For more information: https://argocd-notifications.readthedocs.io/en/stable/services/overview/
items:
telegram-token: "xxxxxxx:xxxxxxxxxxx"

For application log format we must set to json and log level info/error/debug/warn

notifications:  
logFormat: "json"
logLevel: "info"

And the section notifier add telegram token from variable secret.

notifications:
notifiers:
service.telegram: |
token: $telegram-token

We’ll use the default from helm chart for template message notification, but we must delete slack or email message template.

notifications:
templates:
template.app-deployed: |
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} is now running new version of deployments manifests.
template.app-health-degraded: |
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} Application {{.app.metadata.name}} has degraded.
Application details: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}.
template.app-sync-failed: |
message: |
{{if eq .serviceType "slack"}}:exclamation:{{end}} The sync operation of application {{.app.metadata.name}} has failed at {{.app.status.operationState.finishedAt}} with the following error: {{.app.status.operationState.message}}
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .
template.app-sync-succeeded: |
message: |
{{if eq .serviceType "slack"}}:white_check_mark:{{end}} Application {{.app.metadata.name}} has been successfully synced at {{.app.status.operationState.finishedAt}}.
Sync operation details are available at: {{.context.argocdUrl}}/applications/{{.app.metadata.name}}?operation=true .

For trigger we can used default from helm chart

triggers: 
trigger.on-deployed: |
- description: Application is synced and healthy. Triggered once per commit.
oncePer: app.status.sync.revision
send:
- app-deployed
when: app.status.operationState.phase in ['Succeeded'] and app.status.health.status == 'Healthy'
trigger.on-health-degraded: |
- description: Application has degraded
send:
- app-health-degraded
when: app.status.health.status == 'Degraded'
trigger.on-sync-failed: |
- description: Application syncing has failed
send:
- app-sync-failed
when: app.status.operationState.phase in ['Error', 'Failed'
trigger.on-sync-succeeded: |
- description: Application syncing has succeeded
send:
- app-sync-succeeded
when: app.status.operationState.phase in ['Succeeded']

Argo Manifest

On Argo Manifest, we can add in the annotation for subscribing notification app. we can use channel or group id as subscriber.

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: "fruit-apple-development"
labels:
app.kubernetes.io/instance: "fruit-development"
finalizers:
- resources-finalizer.argocd.argoproj.io
annotations:
notifications.argoproj.io/subscribe.on-sync-succeeded.telegram: "-xxxxx" #group or channel id
notifications.argoproj.io/subscribe.on-sync-failed.telegram: "-xxxxxx"
notifications.argoproj.io/subscribe.on-health-degraded.telegram: "-xxxxx"
notifications.argoproj.io/subscribe.on-deployed.telegram: "-xxxxxx"

spec:
project: application
source:
repoURL: https://your-git-repository.git
targetRevision: HEAD
path: "application/development/apple"
helm:
releaseName: "fruit-apple"
valueFiles:
- values.yaml
destination:
server: https://kubernetes.local
namespace: "fruit"
syncPolicy:
syncOptions:
- CreateNamespace=true
- ApplyOutOfSyncOnly=true
automated:
selfHeal: true
prune: true

Then apply for new configuration by push to the repository, i assume that you have done with argocd setup as GitOps. If i want to apply new configuration i just push it into git and automatically update on cluster.

git add . && git commit -m "Apply argocd notification"
git push origin master

Result

notification when a new deployment applied
notification when sync are succesfully

Closing

You can be using your custom service notification supported by argocd, you can read the official documentation for reference. Thanks

By Fauzan Rafi, Research Team Btech

--

--