From 42c68dd0bde8d9b79bf283825b5982a11f7052be Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Thu, 22 Oct 2026 15:09:58 -0600 Subject: [PATCH] feat: add guarded storage management commands --- jeannie | 12 +----- lib/jeannie/commands.sh | 95 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 10 deletions(-) diff --git a/jeannie b/jeannie index a723290..582c993 100755 --- a/jeannie +++ b/jeannie @@ -116,7 +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. - storage status Inspect Kubernetes, OpenEBS, and Pimox storage (read-only). + storage {status|cleanup|snapshot|expand|rebalance} Manage and inspect storage safely. platform [all|calico|metrics|dns|metallb|ingress|storage|argocd|security|logging|monitoring|tools] Deploy one platform component or the full platform stack. edge Deploy/check the OCI edge stack only. @@ -258,15 +258,7 @@ case "${1:-}" in gitops_status ;; storage) - case "${2:-status}" in - status) - storage_status - ;; - *) - echo "Usage: ./jeannie storage status" >&2 - exit 1 - ;; - esac + storage_manage "${@:2}" ;; platform) record_change_journal "platform" "$@" diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 45e1b86..27c0504 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -3295,6 +3295,101 @@ storage_status() { check_pimox_storage || printf '%s\n' 'Pimox storage check failed or is unavailable.' } +storage_manage() { + local action="${1:-status}" + shift || true + local kubeconfig="${KUBECONFIG_PATH}" + local pvc_ref="" + local size="" + local snapshot_name="" + local yes=false + local namespace + local pvc + local current + local current_bytes + local requested_bytes + + case "${action}" in + status) + storage_status + ;; + cleanup) + require_debian_server "storage cleanup" + echo "Running the existing worker disk cleanup tool..." + "${REPO_ROOT}/scripts/workers" disk-cleanup + ;; + snapshot) + while (($# > 0)); do + case "$1" in + --pvc) pvc_ref="${2:-}"; shift 2 ;; + --name) snapshot_name="${2:-}"; shift 2 ;; + --yes) yes=true; shift ;; + *) echo "Usage: ./jeannie storage snapshot --pvc NAMESPACE/PVC --name SNAPSHOT [--yes]" >&2; return 2 ;; + esac + done + if [[ ! "${pvc_ref}" =~ ^([^/]+)/([^/]+)$ || -z "${snapshot_name}" ]]; then + echo "Usage: ./jeannie storage snapshot --pvc NAMESPACE/PVC --name SNAPSHOT [--yes]" >&2 + return 2 + fi + namespace="${BASH_REMATCH[1]}" + pvc="${BASH_REMATCH[2]}" + if ! kubectl --kubeconfig "${kubeconfig}" get crd volumesnapshots.snapshot.storage.k8s.io >/dev/null 2>&1; then + echo "VolumeSnapshot CRD is not installed; no snapshot was created." >&2 + return 1 + fi + if [[ "${yes}" != true ]]; then + echo "Would snapshot ${namespace}/${pvc} as ${snapshot_name}. Re-run with --yes to apply." + return 0 + fi + kubectl --kubeconfig "${kubeconfig}" -n "${namespace}" get pvc "${pvc}" >/dev/null + kubectl --kubeconfig "${kubeconfig}" -n "${namespace}" apply -f - < 0)); do + case "$1" in + --pvc) pvc_ref="${2:-}"; shift 2 ;; + --size) size="${2:-}"; shift 2 ;; + --yes) yes=true; shift ;; + *) echo "Usage: ./jeannie storage expand --pvc NAMESPACE/PVC --size SIZE [--yes]" >&2; return 2 ;; + esac + done + if [[ ! "${pvc_ref}" =~ ^([^/]+)/([^/]+)$ ]]; then + echo "Usage: ./jeannie storage expand --pvc NAMESPACE/PVC --size SIZE [--yes]" >&2 + return 2 + fi + namespace="${BASH_REMATCH[1]}" + pvc="${BASH_REMATCH[2]}" + if [[ ! "${size}" =~ ^[0-9]+(Mi|Gi|Ti)$ ]]; then + echo "Usage: ./jeannie storage expand --pvc NAMESPACE/PVC --size SIZE [--yes]" >&2 + return 2 + fi + current="$(kubectl --kubeconfig "${kubeconfig}" -n "${namespace}" get pvc "${pvc}" -o jsonpath='{.spec.resources.requests.storage}')" + if [[ "${yes}" != true ]]; then + echo "Would request expansion of ${namespace}/${pvc}: ${current} -> ${size}. Re-run with --yes to apply." + return 0 + fi + kubectl --kubeconfig "${kubeconfig}" -n "${namespace}" patch pvc "${pvc}" --type merge -p "{\"spec\":{\"resources\":{\"requests\":{\"storage\":\"${size}\"}}}}" + ;; + rebalance) + echo "Storage rebalance is plan-only: OpenEBS LocalPV volumes are node-local and cannot be moved safely by a generic command." + kubectl --kubeconfig "${kubeconfig}" get pv -o wide 2>/dev/null || true + echo "Use an explicit migration plan after identifying the owning workload and a target node." + ;; + *) + echo "Usage: ./jeannie storage {status|cleanup|snapshot|expand|rebalance}" >&2 + return 2 + ;; + esac +} + cert_check() { "${REPO_ROOT}/scripts/cert-check" }