mirror of
https://github.com/dredx/prole.git
synced 2026-09-27 16:14:31 +00:00
- Consolidated and split initialization scripts in etc/:
- Removed init_prole-db.sh and init_authority.sh.
- Added init_kdc.sh for in-cluster MIT Kerberos KDC (prole-authority).
- Added init_ollama.sh for Ollama AI service integration.
- Added init_service_layer.sh for high-level service orchestration.
- Added init_k3s_registry.sh for private registry management.
- Major updates to install.py:
- Support for new Ollama and KDC configuration.
- Improved prole.cfg rendering and namespace handling.
- Updated unattended install flags.
- Infrastructure and Deployment:
- Updated K3s Ansible role with private registry support (registries.yaml template).
- Added prole-authority Dockerfile.
- Updated OpenBao Kerberos ConfigMap and other K8s manifests.
- Configuration:
- Updated prole.cfg with new sections for Ollama and Monitoring.
- Refined environment variable exports in env.sh and prole_cfg.sh.
185 lines
5.6 KiB
Bash
Executable File
185 lines
5.6 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] <update|start|status>
|
|
|
|
Deploys common infrastructure services (OpenBao, OpenTofu, registry if available)
|
|
into the given Kubernetes namespace.
|
|
EOF
|
|
}
|
|
|
|
NS=""
|
|
ACTION="update"
|
|
|
|
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
|
|
;;
|
|
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
|
|
"$SCRIPT_DIR/init_service_layer.sh" -n "$NS" "$ACTION"
|
|
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
|
|
|
|
exit "$rc"
|