feat: add gitops diff and refresh commands
This commit is contained in:
parent
ecc64082b2
commit
d980c0b044
|
|
@ -31,6 +31,7 @@ var allowedCommands = map[string]bool{
|
||||||
"start-cluster": true, "cleanup-debian-k8s": true,
|
"start-cluster": true, "cleanup-debian-k8s": true,
|
||||||
"status": true, "capacity": true, "capacity-advisor": true,
|
"status": true, "capacity": true, "capacity-advisor": true,
|
||||||
"capacity-limits": true, "recover-plan": true, "gitops-status": true,
|
"capacity-limits": true, "recover-plan": true, "gitops-status": true,
|
||||||
|
"gitops": true,
|
||||||
"storage": true,
|
"storage": true,
|
||||||
"mesh": true,
|
"mesh": true,
|
||||||
"platform": true, "edge": true, "edge-cache-flush": true,
|
"platform": true, "edge": true, "edge-cache-flush": true,
|
||||||
|
|
|
||||||
|
|
@ -117,3 +117,9 @@ func TestMeshCommandIsRemotelyEnabled(t *testing.T) {
|
||||||
t.Fatal("mesh must be exposed through the remote API")
|
t.Fatal("mesh must be exposed through the remote API")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGitopsCommandIsRemotelyEnabled(t *testing.T) {
|
||||||
|
if !allowedCommands["gitops"] {
|
||||||
|
t.Fatal("gitops must be exposed through the remote API")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
4
jeannie
4
jeannie
|
|
@ -116,6 +116,7 @@ Observability And GitOps
|
||||||
dex-secret {ensure|file} Generate/check SOPS-encrypted Dex bootstrap secrets.
|
dex-secret {ensure|file} Generate/check SOPS-encrypted Dex bootstrap secrets.
|
||||||
gitea-runner-secret {migrate|apply|file} Convert/apply the Gitea runner SOPS secret.
|
gitea-runner-secret {migrate|apply|file} Convert/apply the Gitea runner SOPS secret.
|
||||||
gitops-status Print focused Argo CD health and sync status.
|
gitops-status Print focused Argo CD health and sync status.
|
||||||
|
gitops {diff [APP]|refresh APP|--all} Inspect drift or request an Argo CD refresh.
|
||||||
storage {status|cleanup|snapshot|expand|rebalance} Manage and inspect storage safely.
|
storage {status|cleanup|snapshot|expand|rebalance} Manage and inspect storage safely.
|
||||||
mesh doctor [--json] Run read-only Kubernetes, Calico, SSH, and Tailscale checks.
|
mesh doctor [--json] Run read-only Kubernetes, Calico, SSH, and Tailscale checks.
|
||||||
platform [all|calico|metrics|dns|metallb|ingress|storage|argocd|security|logging|monitoring|tools]
|
platform [all|calico|metrics|dns|metallb|ingress|storage|argocd|security|logging|monitoring|tools]
|
||||||
|
|
@ -258,6 +259,9 @@ case "${1:-}" in
|
||||||
gitops-status)
|
gitops-status)
|
||||||
gitops_status
|
gitops_status
|
||||||
;;
|
;;
|
||||||
|
gitops)
|
||||||
|
gitops_manage "${@:2}"
|
||||||
|
;;
|
||||||
storage)
|
storage)
|
||||||
storage_manage "${@:2}"
|
storage_manage "${@:2}"
|
||||||
;;
|
;;
|
||||||
|
|
|
||||||
|
|
@ -3258,6 +3258,24 @@ gitops_status() {
|
||||||
"${REPO_ROOT}/scripts/gitops-status"
|
"${REPO_ROOT}/scripts/gitops-status"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gitops_manage() {
|
||||||
|
require_debian_server "gitops"
|
||||||
|
case "${1:-}" in
|
||||||
|
diff)
|
||||||
|
shift
|
||||||
|
"${REPO_ROOT}/scripts/gitops-diff" "$@"
|
||||||
|
;;
|
||||||
|
refresh)
|
||||||
|
shift
|
||||||
|
"${REPO_ROOT}/scripts/gitops-refresh" "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Usage: ./jeannie gitops {diff [APP]|refresh APP|--all}" >&2
|
||||||
|
return 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
storage_status() {
|
storage_status() {
|
||||||
require_debian_server "storage"
|
require_debian_server "storage"
|
||||||
local kubeconfig="${KUBECONFIG_PATH}"
|
local kubeconfig="${KUBECONFIG_PATH}"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
NAMESPACE="${ARGOCD_NAMESPACE:-argocd}"
|
||||||
|
KUBECONFIG_PATH="${KUBECONFIG_PATH:-${LAB_KUBECONFIG_PATH:-${KUBECONFIG:-/home/jv/.kube/config}}}"
|
||||||
|
APP="${1:-}"
|
||||||
|
|
||||||
|
if [[ -n "${APP}" && ! "${APP}" =~ ^[A-Za-z0-9._-]+$ ]]; then
|
||||||
|
echo "invalid Argo CD application name: ${APP}" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "${APP}" ]]; then
|
||||||
|
payload="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${NAMESPACE}" get application "${APP}" -o json)"
|
||||||
|
else
|
||||||
|
payload="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${NAMESPACE}" get applications.argoproj.io -o json)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
python3 - "${payload}" <<'PY'
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
document = json.loads(sys.argv[1])
|
||||||
|
items = document.get("items", [document] if document.get("kind") == "Application" else [])
|
||||||
|
if not items:
|
||||||
|
print("No Argo CD Applications found.")
|
||||||
|
raise SystemExit(0)
|
||||||
|
|
||||||
|
drift = False
|
||||||
|
for app in items:
|
||||||
|
metadata = app.get("metadata", {})
|
||||||
|
spec = app.get("spec", {})
|
||||||
|
status = app.get("status", {})
|
||||||
|
name = metadata.get("name", "unknown")
|
||||||
|
sync = status.get("sync", {}).get("status", "Unknown")
|
||||||
|
health = status.get("health", {}).get("status", "Unknown")
|
||||||
|
revision = status.get("sync", {}).get("revision", "")
|
||||||
|
path = spec.get("source", {}).get("path", "")
|
||||||
|
resources = status.get("resources", [])
|
||||||
|
changed = [
|
||||||
|
f"{item.get('kind','?')}/{item.get('name','?')}:{item.get('status','?')}"
|
||||||
|
for item in resources
|
||||||
|
if item.get("status") not in (None, "Synced") or item.get("health", {}).get("status") not in (None, "Healthy")
|
||||||
|
]
|
||||||
|
if sync != "Synced" or changed:
|
||||||
|
drift = True
|
||||||
|
print(f"{name}: sync={sync} health={health} revision={revision or '-'} path={path or '-'}")
|
||||||
|
if changed:
|
||||||
|
print(" resources: " + ", ".join(changed))
|
||||||
|
conditions = status.get("conditions", [])
|
||||||
|
for condition in conditions[-3:]:
|
||||||
|
message = condition.get("message")
|
||||||
|
if message:
|
||||||
|
print(f" condition: {message}")
|
||||||
|
print(f"Drift detected: {'yes' if drift else 'no'}")
|
||||||
|
PY
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
NAMESPACE="${ARGOCD_NAMESPACE:-argocd}"
|
||||||
|
KUBECONFIG_PATH="${KUBECONFIG_PATH:-${LAB_KUBECONFIG_PATH:-${KUBECONFIG:-/home/jv/.kube/config}}}"
|
||||||
|
if [[ $# -ne 1 ]]; then
|
||||||
|
echo "Usage: ./jeannie gitops refresh APP|--all" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
target="$1"
|
||||||
|
if [[ "${target}" != "--all" && ! "${target}" =~ ^[A-Za-z0-9._-]+$ ]]; then
|
||||||
|
echo "invalid Argo CD application name: ${target}" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
mapfile -t apps < <(
|
||||||
|
if [[ "${target}" == "--all" ]]; then
|
||||||
|
kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${NAMESPACE}" get applications.argoproj.io \
|
||||||
|
-o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}'
|
||||||
|
else
|
||||||
|
printf '%s\n' "${target}"
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
if [[ ${#apps[@]} -eq 0 ]]; then
|
||||||
|
echo "No Argo CD applications found." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
for app in "${apps[@]}"; do
|
||||||
|
[[ -n "${app}" ]] || continue
|
||||||
|
kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${NAMESPACE}" get application "${app}" >/dev/null
|
||||||
|
kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${NAMESPACE}" patch application "${app}" \
|
||||||
|
--type merge -p '{"metadata":{"annotations":{"argocd.argoproj.io/refresh":"hard"}}}' >/dev/null
|
||||||
|
echo "Requested hard refresh for ${NAMESPACE}/${app}."
|
||||||
|
done
|
||||||
Loading…
Reference in New Issue