Skip to content

ArgoCD — alert when an application drifts from git state

Someone ran `kubectl edit` directly on the cluster — the manifest diverges from git. ArgoCD shows OutOfSync, but auto-sync is off. The manifest drifts further, divergence accumulates.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/argocd-drift
# */10 * * * * root /opt/argocd-drift.sh

ARGO=${ARGOCD_URL:-https://argocd.internal}
TOKEN=${ARGOCD_TOKEN}

OOS=$(curl -fsS -H "Authorization: Bearer $TOKEN" "$ARGO/api/v1/applications" \
  | jq -r '[.items[] | select(.status.sync.status != "Synced") | .metadata.name]')

COUNT=$(echo "$OOS" | jq 'length')

if [ "${COUNT:-0}" -gt 0 ]; then
  NAMES=$(echo "$OOS" | jq -r '.[]' | head -10 | tr '\n' ',')
  curl -fsS "$HEARTBEAT_URL" --data-urlencode "out_of_sync=$COUNT,apps=$NAMES"
  exit 2
fi
echo "OK (all apps Synced)"

Same thing in Enterno.io

Wrap in an Enterno heartbeat — a daily "what drifted yesterday" report helps the team quickly restore the GitOps invariant.

Set up API monitor → ← All recipes

Related recipes