Argo Notifications with Argo CD
Argo CD notifications help to monitor and get alerts when Argo CD sync successfully or fails. It helps us to notify users with important changes in the application state. There are two components in Argo Notifications: Triggers and Templates.
- Triggers define the condition when the notification should be sent. We define a trigger, if that trigger is actual, we send a notification.
- Template: The notification template is used to customize the notification message that will be sent.
- Subscription: The subscription to Argo CD application events can be defined using notifications.argoproj.io/subscribe.<trigger>.<service>: <recipient> annotation.
With the help of these triggers and templates, we can configure when the message should be sent and what should be sent.
For now, Let’s make use of slack to send notifications for Argo CD.
Slack as notification channel
Step 1: Create a Slack Application
Before installing the Argo notifications, Let's create a slack channel. We need to create a slack application then we need to generate a token for the same. To create and generate a token refer to 1–7 steps from this link:
https://argocd-notifications.readthedocs.io/en/stable/services/slack/
Step 2: Install Argo Notifications
Argo CD notification will be in the same namespace where we installed ArgoCD. To know more about Argo CD please refer to this article.
- Install Argo CD notification
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/v1.1.0/manifests/install.yaml
- Install Triggers and templates:
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj-labs/argocd-notifications/v1.1.0/catalog/install.yaml
If we use kubectl get pods -n argocd, a notification controller will be installed.
Step 3: Create Slack Secret
For the previously created token, we need to make that a secret. We can use a sealed secret for the same. To know more about a sealed secret.
- Create a SealedSecret for slack using this command:
kubectl --namespace argocd \
create secret \
generic argocd-notifications-secret\
--dry-run=client \
--from-literal=slack-token=<token-generated>\
--output json \
| kubeseal \
| tee argocd-notifications-secret.yaml
- Create a secret and verify using this command:
kubectl create \
--filename argocd-notifications-secret.yaml -n argocdkubectl get secret argocd-notifications-secret \
--output yaml -n argocd
If you run kubectl get secret -n argocd, your secret should be applied and visible.
Step 4: Modify argocd-notifications-cm
configmap for slack token
Now we need to change the config map of Argo notifications. If we list configmap in namespace argocd.
kubectl get configmap -n argocd
The output will be:
Open this config map file and edit it using the command:
kubectl edit -n argocd cm argocd-notifications-cm
Edit the data like this to add slack-token that we created previously.
apiVersion: v1
kind: ConfigMap
metadata:
name: argocd-notifications-cm
data:
service.slack: |
token: $slack-token
...
Make changes like this and save the file.
After this, we need to patch the file with the channel. We can patch the application with triggers with the following command. Run this command in the terminal.
kubectl patch app $APP_NAME -n $NAMESPACE -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-sync-succeeded.slack":"<your-channel-name>"}}}' --type merge kubectl patch app $APP_NAME -n $NAMESPACE -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-sync-failed.slack":"<your-channel-name>"}}}' --type merge kubectl patch app $APP_NAME -n $NAMESPACE -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-sync-status-unknown.slack":"<your-channel-name>"}}}' --type merge kubectl patch app $APP_NAME -n $NAMESPACE -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-health-degraded.slack":"<your-channel-name>"}}}' --type merge kubectl patch app $APP_NAME -n $NAMESPACE -p '{"metadata": {"annotations": {"notifications.argoproj.io/subscribe.on-deployed.slack":"<your-channel-name>"}}}' --type merge
Step 5: Output will be
If we sync the Argo app which was patched earlier, we get a notification to slack like this. We already patched for application Sync Successful, Failed, Unknown, health degraded Notification.
Conclusion:
This is all about the Argo Notification. We can also use the CURL command in the post-sync method. But curl can be vulnerable to its better to use notifications that are built-in.
Hope this article helped you all !!!
If you liked this article, please consider donating whatever amount you can using this link. It would mean a lot.