From d980c0b04409bb3ccff273cb3967e3b422af338f Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Thu, 22 Oct 2026 18:25:28 -0600 Subject: [PATCH] feat: add gitops diff and refresh commands --- cmd/jeannie-server/main.go | 1 + cmd/jeannie-server/main_test.go | 6 ++++ jeannie | 4 +++ lib/jeannie/commands.sh | 18 +++++++++++ scripts/gitops-diff | 56 +++++++++++++++++++++++++++++++++ scripts/gitops-refresh | 34 ++++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100755 scripts/gitops-diff create mode 100755 scripts/gitops-refresh diff --git a/cmd/jeannie-server/main.go b/cmd/jeannie-server/main.go index c69545a..1aafbd0 100644 --- a/cmd/jeannie-server/main.go +++ b/cmd/jeannie-server/main.go @@ -31,6 +31,7 @@ var allowedCommands = map[string]bool{ "start-cluster": true, "cleanup-debian-k8s": true, "status": true, "capacity": true, "capacity-advisor": true, "capacity-limits": true, "recover-plan": true, "gitops-status": true, + "gitops": true, "storage": true, "mesh": true, "platform": true, "edge": true, "edge-cache-flush": true, diff --git a/cmd/jeannie-server/main_test.go b/cmd/jeannie-server/main_test.go index d37216f..58d7f3e 100644 --- a/cmd/jeannie-server/main_test.go +++ b/cmd/jeannie-server/main_test.go @@ -117,3 +117,9 @@ func TestMeshCommandIsRemotelyEnabled(t *testing.T) { 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") + } +} diff --git a/jeannie b/jeannie index e07c907..e27eade 100755 --- a/jeannie +++ b/jeannie @@ -116,6 +116,7 @@ Observability And GitOps dex-secret {ensure|file} Generate/check SOPS-encrypted Dex bootstrap secrets. gitea-runner-secret {migrate|apply|file} Convert/apply the Gitea runner SOPS secret. 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. 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] @@ -258,6 +259,9 @@ case "${1:-}" in gitops-status) gitops_status ;; + gitops) + gitops_manage "${@:2}" + ;; storage) storage_manage "${@:2}" ;; diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 878af70..cdb9b72 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -3258,6 +3258,24 @@ 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() { require_debian_server "storage" local kubeconfig="${KUBECONFIG_PATH}" diff --git a/scripts/gitops-diff b/scripts/gitops-diff new file mode 100755 index 0000000..7c3220e --- /dev/null +++ b/scripts/gitops-diff @@ -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 diff --git a/scripts/gitops-refresh b/scripts/gitops-refresh new file mode 100755 index 0000000..cf3ebdf --- /dev/null +++ b/scripts/gitops-refresh @@ -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