mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 18:44:33 +00:00
- install.py: Major update including configuration variable expansion, improved k3s/k3d handling, and enhanced installation logic. - etc/ scripts: Significant refactoring of initialization scripts (Kerberos, Port Forwards, Garage Store, etc.). - Port Forwards: Transitioned from XML to port-mappings.conf for managing kubectl port-forwards. - Status Reporting: Improved status checking for common services. - Infrastructure: Updated Ansible inventory and rsyslog role configurations. - Tests: Added a comprehensive suite of tests for 'etc' initialization scripts in prole/tests/etc/. - Documentation: Added prole-db-documentation-mcp-architecture.md. - General: Updated Dockerfiles and various helper scripts.
209 lines
6.3 KiB
Bash
Executable File
209 lines
6.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -u
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
# shellcheck disable=SC1090
|
|
source "$SCRIPT_DIR/prole_cfg.sh"
|
|
|
|
usage() {
|
|
cat <<EOF
|
|
Usage: init_common_services.sh [-n|--namespace NS] [-k|--kerberos] <update|start|status>
|
|
|
|
Deploys common infrastructure services (OpenBao, OpenTofu, registry if available)
|
|
into the given Kubernetes namespace. Use -k to include the Kerberos/KDC service.
|
|
EOF
|
|
}
|
|
|
|
NS=""
|
|
ACTION="update"
|
|
ENABLE_KERBEROS=0
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
-m|--mode)
|
|
shift
|
|
prole_set_mode "${1:-}"
|
|
shift
|
|
;;
|
|
-m=*|--mode=*)
|
|
prole_set_mode "${1#*=}"
|
|
shift
|
|
;;
|
|
-n|--namespace)
|
|
shift
|
|
NS="${1:-}"
|
|
shift
|
|
;;
|
|
-n=*|--namespace=*)
|
|
NS="${1#*=}"
|
|
shift
|
|
;;
|
|
-k|--kerberos)
|
|
ENABLE_KERBEROS=1
|
|
shift
|
|
;;
|
|
update|start|status)
|
|
ACTION="$1"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
usage
|
|
exit 2
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$NS" ]; then
|
|
NS="${SERVICE_NAMESPACE:-${NAMESPACE:-}}"
|
|
fi
|
|
if [ -z "$NS" ]; then
|
|
NS="default"
|
|
fi
|
|
|
|
prole_ensure_kubeconfig >/dev/null 2>&1 || true
|
|
|
|
if [ -x "$SCRIPT_DIR/init_service_layer.sh" ]; then
|
|
if [[ "$ENABLE_KERBEROS" == "1" ]]; then
|
|
"$SCRIPT_DIR/init_service_layer.sh" -n "$NS" -k "$ACTION"
|
|
else
|
|
"$SCRIPT_DIR/init_service_layer.sh" -n "$NS" "$ACTION"
|
|
fi
|
|
exit $?
|
|
fi
|
|
|
|
if [[ -n "${COMMON_SERVICES_INIT_LOG:-}" ]]; then
|
|
mkdir -p "$(dirname "$COMMON_SERVICES_INIT_LOG")"
|
|
exec > >(tee -a "$COMMON_SERVICES_INIT_LOG") 2>&1
|
|
fi
|
|
|
|
OPENBAO_NAME=${OPENBAO_NAME:-openbao}
|
|
OPENTOFU_NAME=${OPENTOFU_NAME:-opentofu}
|
|
REGISTRY_NAME=${REGISTRY_NAME:-registry}
|
|
GARAGE_NAME=${GARAGE_NAME:-garage}
|
|
OPENTOFU_CONFIGMAP=${OPENTOFU_CONFIGMAP:-opentofu-nginx}
|
|
OPENTOFU_SECRET=${OPENTOFU_SECRET:-opentofu-admin}
|
|
OPENBAO_KRB5_CONFIGMAP=${OPENBAO_KRB5_CONFIGMAP:-prole-krb5-conf}
|
|
GARAGE_CONFIGMAP=${GARAGE_CONFIGMAP:-garage-config}
|
|
GARAGE_SECRET_NAME=${GARAGE_SECRET_NAME:-garage-secrets}
|
|
|
|
find_namespaces() {
|
|
local kind="$1"
|
|
local name="$2"
|
|
kubectl get "$kind" -A --no-headers 2>/dev/null | awk -v n="$name" '$2==n {print $1}' | sort -u
|
|
}
|
|
|
|
collect_other_namespaces() {
|
|
local name="$1"
|
|
shift
|
|
local kinds=("$@")
|
|
local found=""
|
|
local kind
|
|
for kind in "${kinds[@]}"; do
|
|
found+=$(find_namespaces "$kind" "$name")
|
|
found+=$'\n'
|
|
done
|
|
printf '%s\n' "$found" | awk -v target="$NS" 'NF && $1 != target {print $1}' | sort -u
|
|
}
|
|
|
|
migrate_common_services() {
|
|
local old_ns
|
|
|
|
for old_ns in $(collect_other_namespaces "$OPENBAO_NAME" statefulset deployment service); do
|
|
echo "Found OpenBao in namespace '$old_ns'; removing before deploy to '$NS' ..."
|
|
kubectl delete -n "$old_ns" statefulset "$OPENBAO_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" deploy "$OPENBAO_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" svc "$OPENBAO_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" configmap "$OPENBAO_KRB5_CONFIGMAP" --ignore-not-found >/dev/null 2>&1 || true
|
|
done
|
|
|
|
for old_ns in $(collect_other_namespaces "$OPENTOFU_NAME" deployment service); do
|
|
echo "Found OpenTofu in namespace '$old_ns'; removing before deploy to '$NS' ..."
|
|
if [ -x "$SCRIPT_DIR/init_opentofu.sh" ]; then
|
|
"$SCRIPT_DIR/init_opentofu.sh" -n "$old_ns" stop || true
|
|
else
|
|
kubectl delete -n "$old_ns" deploy "$OPENTOFU_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" svc "$OPENTOFU_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
fi
|
|
kubectl delete -n "$old_ns" configmap "$OPENTOFU_CONFIGMAP" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" secret "$OPENTOFU_SECRET" --ignore-not-found >/dev/null 2>&1 || true
|
|
done
|
|
|
|
for old_ns in $(collect_other_namespaces "$REGISTRY_NAME" deployment service); do
|
|
echo "Found registry in namespace '$old_ns'; removing before deploy to '$NS' ..."
|
|
if [ -x "$SCRIPT_DIR/init_registry.sh" ]; then
|
|
"$SCRIPT_DIR/init_registry.sh" -n "$old_ns" stop || true
|
|
else
|
|
kubectl delete -n "$old_ns" deploy "$REGISTRY_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" svc "$REGISTRY_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
fi
|
|
done
|
|
|
|
for old_ns in $(collect_other_namespaces "$GARAGE_NAME" statefulset service); do
|
|
echo "Found Garage in namespace '$old_ns'; removing before deploy to '$NS' ..."
|
|
kubectl delete -n "$old_ns" statefulset "$GARAGE_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" svc "$GARAGE_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" configmap "$GARAGE_CONFIGMAP" --ignore-not-found >/dev/null 2>&1 || true
|
|
kubectl delete -n "$old_ns" secret "$GARAGE_SECRET_NAME" --ignore-not-found >/dev/null 2>&1 || true
|
|
done
|
|
}
|
|
|
|
echo "Deploying common services (namespace=$NS, action=$ACTION)"
|
|
|
|
rc=0
|
|
|
|
case "$ACTION" in
|
|
start|update|reload|initialize|restart)
|
|
migrate_common_services
|
|
;;
|
|
esac
|
|
|
|
if [ -x "$SCRIPT_DIR/init_openbao.sh" ]; then
|
|
"$SCRIPT_DIR/init_openbao.sh" -n "$NS" "$ACTION" || rc=$?
|
|
else
|
|
echo "WARN: init_openbao.sh not found; skipping OpenBao."
|
|
fi
|
|
|
|
if [ -x "$SCRIPT_DIR/init_opentofu.sh" ]; then
|
|
"$SCRIPT_DIR/init_opentofu.sh" -n "$NS" "$ACTION" || rc=$?
|
|
else
|
|
echo "WARN: init_opentofu.sh not found; skipping OpenTofu."
|
|
fi
|
|
|
|
if [ -x "$SCRIPT_DIR/init_registry.sh" ]; then
|
|
"$SCRIPT_DIR/init_registry.sh" -n "$NS" "$ACTION" || rc=$?
|
|
else
|
|
echo "WARN: init_registry.sh not found; registry deploy skipped."
|
|
fi
|
|
|
|
if [ -x "$SCRIPT_DIR/init_garage_store.sh" ]; then
|
|
garage_action="$ACTION"
|
|
case "$garage_action" in
|
|
update|reload|initialize) garage_action="start" ;;
|
|
esac
|
|
NAMESPACE="$NS" SERVICE_NAMESPACE="$NS" GARAGE_NAMESPACE="$NS" \
|
|
"$SCRIPT_DIR/init_garage_store.sh" "$garage_action" || rc=$?
|
|
else
|
|
echo "WARN: init_garage_store.sh not found; garage deploy skipped."
|
|
fi
|
|
|
|
if [[ "$ENABLE_KERBEROS" == "1" ]]; then
|
|
if [ -x "$SCRIPT_DIR/init_kdc.sh" ]; then
|
|
kdc_action="$ACTION"
|
|
case "$kdc_action" in
|
|
stop) kdc_action="cleanup" ;;
|
|
status) kdc_action="status" ;;
|
|
*) kdc_action="update" ;;
|
|
esac
|
|
SERVICE_NAMESPACE="$NS" PROLE_KDC_NAMESPACE="$NS" \
|
|
"$SCRIPT_DIR/init_kdc.sh" "$kdc_action" || rc=$?
|
|
else
|
|
echo "WARN: init_kdc.sh not found; kerberos deploy skipped."
|
|
fi
|
|
fi
|
|
|
|
exit "$rc"
|