mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 19:54:32 +00:00
- Tighten Cluster Environment screen layout; switch Service/Prod to kubectx context selection; keep namespace and key controls on one line; ensure Repair button remains reachable. - Add UI layout regression test to render with large mock data and assert key widgets remain visible and console is scrollable. - Make kubeconfig generation deterministic under tests by avoiding overwriting cert-based kubeconfigs; write token sidecar kubeconfig when needed. - Update common-services init scripts and add k3s/Helm deployment bits (svc-check, Kong/CertMgr tasks).
133 lines
3.6 KiB
Bash
133 lines
3.6 KiB
Bash
#!/usr/bin/env bash
|
|
# Shared helpers for common core init scripts (ArgoCD, OpenBao, OpenTofu, Garage).
|
|
# Responsibilities:
|
|
# - handle [-c|--config] early so prole_cfg.sh loads the right prole.cfg
|
|
# - parse standard actions/options
|
|
# - resolve and apply namespaces consistently
|
|
|
|
# Actions supported by all common core scripts
|
|
COMMON_CORE_ACTIONS="start|stop|status|restart|initialize|update|reload"
|
|
|
|
# Parse -c/--config before loading prole_cfg.sh so PROLE_CONF is set in time.
|
|
# Sets:
|
|
# COMMON_CORE_CONFIG_PATH - path to prole.cfg (if provided)
|
|
# COMMON_CORE_ARGS - original arguments minus -c/--config
|
|
common_core_preparse_config() {
|
|
COMMON_CORE_CONFIG_PATH=""
|
|
COMMON_CORE_ARGS=()
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-c|--config)
|
|
shift
|
|
if [[ -z "${1:-}" ]]; then
|
|
echo "ERROR: -c/--config requires a file path" >&2
|
|
exit 2
|
|
fi
|
|
COMMON_CORE_CONFIG_PATH="$1"
|
|
;;
|
|
-c=*|--config=*)
|
|
COMMON_CORE_CONFIG_PATH="${1#*=}"
|
|
;;
|
|
*)
|
|
COMMON_CORE_ARGS+=("$1")
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ -n "$COMMON_CORE_CONFIG_PATH" ]]; then
|
|
if [[ ! -f "$COMMON_CORE_CONFIG_PATH" ]]; then
|
|
echo "ERROR: config file not found: $COMMON_CORE_CONFIG_PATH" >&2
|
|
exit 2
|
|
fi
|
|
local cfg_dir
|
|
cfg_dir=$(cd "$(dirname "$COMMON_CORE_CONFIG_PATH")" && pwd)
|
|
PROLE_CONF="$cfg_dir"
|
|
export PROLE_CONF
|
|
fi
|
|
}
|
|
|
|
# Parse standard options and action.
|
|
# Sets (always):
|
|
# COMMON_CORE_ACTION
|
|
# COMMON_CORE_NAMESPACE
|
|
# COMMON_CORE_HELP (0/1)
|
|
# COMMON_CORE_PARSE_ERROR (empty or message)
|
|
common_core_parse_args() {
|
|
COMMON_CORE_ACTION=""
|
|
COMMON_CORE_NAMESPACE=""
|
|
COMMON_CORE_HELP=0
|
|
COMMON_CORE_PARSE_ERROR=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-m|--mode)
|
|
shift
|
|
prole_set_mode "${1:-}"
|
|
;;
|
|
-m=*|--mode=*)
|
|
prole_set_mode "${1#*=}"
|
|
;;
|
|
-n|--namespace)
|
|
shift
|
|
if [[ -z "${1:-}" ]]; then
|
|
COMMON_CORE_PARSE_ERROR="--namespace requires a value"
|
|
break
|
|
fi
|
|
COMMON_CORE_NAMESPACE="$1"
|
|
;;
|
|
-n=*|--namespace=*)
|
|
COMMON_CORE_NAMESPACE="${1#*=}"
|
|
;;
|
|
start|stop|status|restart|initialize|update|reload)
|
|
COMMON_CORE_ACTION="$1"
|
|
;;
|
|
-h|--help)
|
|
COMMON_CORE_HELP=1
|
|
;;
|
|
--)
|
|
shift
|
|
break
|
|
;;
|
|
*)
|
|
if [[ -z "$COMMON_CORE_ACTION" && "$1" != -* ]]; then
|
|
COMMON_CORE_ACTION="$1"
|
|
else
|
|
COMMON_CORE_PARSE_ERROR="Unknown argument: $1"
|
|
break
|
|
fi
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
if [[ -z "$COMMON_CORE_ACTION" && "$COMMON_CORE_HELP" -eq 0 && -z "$COMMON_CORE_PARSE_ERROR" ]]; then
|
|
COMMON_CORE_PARSE_ERROR="Action is required (${COMMON_CORE_ACTIONS//|/, })"
|
|
fi
|
|
}
|
|
|
|
common_core_usage() {
|
|
local prog="${1:-$0}"
|
|
echo "Usage: ${prog##*/} [${COMMON_CORE_ACTIONS//|/|}] [-n namespace] [--mode k3d|k3s|k8s] [-c conf/prole.cfg]" >&2
|
|
}
|
|
|
|
# Resolve namespace with precedence: CLI override -> SERVICE_NAMESPACE -> NAMESPACE -> provided default
|
|
common_core_resolve_namespace() {
|
|
local default_ns="${1:-default}"
|
|
local ns="${COMMON_CORE_NAMESPACE:-}"
|
|
[[ -z "$ns" && -n "${SERVICE_NAMESPACE:-}" ]] && ns="$SERVICE_NAMESPACE"
|
|
[[ -z "$ns" && -n "${NAMESPACE:-}" ]] && ns="$NAMESPACE"
|
|
[[ -z "$ns" ]] && ns="$default_ns"
|
|
echo "$ns"
|
|
}
|
|
|
|
# Apply a resolved namespace to both NAMESPACE and SERVICE_NAMESPACE for consistency
|
|
common_core_apply_namespace() {
|
|
local ns="$1"
|
|
if [[ -n "$ns" ]]; then
|
|
NAMESPACE="$ns"
|
|
SERVICE_NAMESPACE="$ns"
|
|
export NAMESPACE SERVICE_NAMESPACE
|
|
fi
|
|
}
|