rishav
rishav

Reputation: 481

Getting periodic slack notifications for disabled auto-sync feature in ArgoCD

We recently had an issue with one of our releases and had to rollback all our services manually. While doing so we had to disable the ‘auto-sync’ feature. After reverting the faulty PR, we forgot to enable the auto-sync again and the apps were out-of-sync for a day. Is there a way we can enable a trigger or an alert that gets triggered after every duration (say one hour) and notify us on slack that the autosync feature is disabled?

We would also like to enable the notification after every PR merge, something like "The commit can not be released because auto-sync is disabled.".

Upvotes: 0

Views: 644

Answers (2)

thiagowfx
thiagowfx

Reputation: 5770

Something like the following works, using the ArgoCD Notifications Controller:

template.auto-sync-disabled: |
  message: |
    Application <{{.context.argocdUrl}}/applications/{{.app.metadata.name}}|`{{.app.metadata.name}}`> auto sync was _disabled_.      

trigger.auto-sync-disabled: |
  - description: Application auto sync is disabled.
    send:
      - auto-sync-disabled
    when: app.status.sync.status == 'Synced' and app.spec.syncPolicy.automated == null

You could also add the following condition to the trigger:

oncePer: app.status.operationState.syncResult.revision

Upvotes: 0

kenske
kenske

Reputation: 2354

The ArgoCD API has a api/v1/applications/{app_name} endpoint. You can fetch the application's settings from there. You then need to check if the spec.syncPolicy object has a key named automated. Here is a example written in bash and jq:

#!/usr/bin/env bash

set -e

USERNAME=admin
PASSWORD=yourpassword
ARGOCD_SERVER=https://yourserver
APP_NAME=yourapp

ARGOCD_TOKEN=$(curl -s $ARGOCD_SERVER/api/v1/session -d '{"username":"admin","password":"'$PASSWORD'"}' | jq -r ".token")

response=$(curl -s "$ARGOCD_SERVER/api/v1/applications/$APP_NAME" -H "Authorization: Bearer $ARGOCD_TOKEN")

echo $response | jq '.spec.syncPolicy | has("automated")'

Upvotes: 0

Related Questions