feat: add guarded storage management commands
Homelab Main / validate (push) Waiting to run Details
Homelab Main / running-update (push) Blocked by required conditions Details
Homelab Main / debian-ops (push) Blocked by required conditions Details

This commit is contained in:
juvenal.diaz 2026-10-22 15:09:58 -06:00
parent 58b0d1fbf6
commit 42c68dd0bd
2 changed files with 97 additions and 10 deletions

12
jeannie
View File

@ -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" "$@"

View File

@ -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 - <<EOF
apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshot
metadata:
name: ${snapshot_name}
spec:
source:
persistentVolumeClaimName: ${pvc}
EOF
;;
expand)
while (($# > 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"
}