85 lines
2.7 KiB
Bash
Executable File
85 lines
2.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
NAMESPACE="${ARGOCD_NAMESPACE:-argocd}"
|
|
LOG_PATTERN="${GITOPS_LOG_PATTERN:-error|failed|denied|timeout|authentication|unauthorized}"
|
|
|
|
section() {
|
|
printf '\n== %s ==\n' "$1"
|
|
}
|
|
|
|
have() {
|
|
command -v "$1" >/dev/null 2>&1
|
|
}
|
|
|
|
kubectl_ok() {
|
|
have kubectl && kubectl version --client >/dev/null 2>&1
|
|
}
|
|
|
|
print_if_available() {
|
|
local description="$1"
|
|
shift
|
|
|
|
if "$@"; then
|
|
return 0
|
|
fi
|
|
|
|
printf '%s unavailable or returned no data.\n' "$description"
|
|
}
|
|
|
|
if ! kubectl_ok; then
|
|
echo "kubectl is required for gitops-status." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if ! kubectl get namespace "$NAMESPACE" >/dev/null 2>&1; then
|
|
echo "Argo CD namespace '$NAMESPACE' was not found or the Kubernetes API is unreachable." >&2
|
|
exit 1
|
|
fi
|
|
|
|
section "Argo CD Applications"
|
|
if ! kubectl -n "$NAMESPACE" get applications.argoproj.io \
|
|
-o custom-columns='NAME:.metadata.name,SYNC:.status.sync.status,HEALTH:.status.health.status,REVISION:.status.sync.revision,PATH:.spec.source.path' \
|
|
--no-headers 2>/dev/null; then
|
|
echo "No Argo CD Applications were found."
|
|
fi
|
|
|
|
section "Out Of Sync Or Degraded"
|
|
apps_report="$(
|
|
kubectl -n "$NAMESPACE" get applications.argoproj.io \
|
|
-o custom-columns='NAME:.metadata.name,SYNC:.status.sync.status,HEALTH:.status.health.status,MESSAGE:.status.conditions[-1].message' \
|
|
--no-headers 2>/dev/null || true
|
|
)"
|
|
|
|
if [ -z "$apps_report" ]; then
|
|
echo "No application status data available."
|
|
else
|
|
printf '%s\n' "$apps_report" | awk '$2 != "Synced" || $3 != "Healthy" { print }'
|
|
fi
|
|
|
|
section "Repository Secrets"
|
|
print_if_available "Repository secrets" \
|
|
kubectl -n "$NAMESPACE" get secrets -l argocd.argoproj.io/secret-type=repository \
|
|
-o custom-columns='NAME:.metadata.name,TYPE:.metadata.labels.argocd\.argoproj\.io/secret-type' \
|
|
--no-headers
|
|
|
|
section "Recent Argo CD Warnings"
|
|
print_if_available "Argo CD events" \
|
|
sh -c "kubectl -n '$NAMESPACE' get events --sort-by=.lastTimestamp 2>/dev/null | tail -40"
|
|
|
|
section "Recent Repo Server Errors"
|
|
if kubectl -n "$NAMESPACE" get deployment argocd-repo-server >/dev/null 2>&1; then
|
|
kubectl -n "$NAMESPACE" logs deployment/argocd-repo-server --tail=120 2>/dev/null |
|
|
grep -Ei "$LOG_PATTERN" || echo "No recent repo-server errors matched '$LOG_PATTERN'."
|
|
else
|
|
echo "argocd-repo-server deployment not found."
|
|
fi
|
|
|
|
section "Recent Application Controller Errors"
|
|
if kubectl -n "$NAMESPACE" get statefulset argocd-application-controller >/dev/null 2>&1; then
|
|
kubectl -n "$NAMESPACE" logs statefulset/argocd-application-controller --tail=120 2>/dev/null |
|
|
grep -Ei "$LOG_PATTERN" || echo "No recent application-controller errors matched '$LOG_PATTERN'."
|
|
else
|
|
echo "argocd-application-controller statefulset not found."
|
|
fi
|