mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 12:03:59 +00:00
Itemized changes:
1. knoe-auth: New cluster-internal KDC and SSO gateway service
- Created etc/init_knoe_auth.sh based on init_kdc.sh with knoe-auth naming
- Namespace defaults to SERVICE_NAMESPACE (knoe-system)
- ConfigMap: knoe-auth-kdc-config, Secret: knoe-auth-secrets
- Legacy cleanup removes old auth/dog/authority deployments
2. Orchestration: knoe-auth initializes before CloudNativePG
- Updated prole.sh to insert init_knoe_auth.sh as step 2 (before CNPG)
- Renumbered all subsequent initialization steps
3. Kong routing: Updated init_kong.sh to route to knoe-auth in SERVICE_NAMESPACE
4. Comment/reference updates for knoe-auth
- Updated init_common_services.sh, init_service_layer.sh, init_kerberos.sh
5. prole-db renamed to knoe-db across the entire codebase
- Renamed prole-db/ directory to knoe-db/
- Renamed all prole-db Kubernetes manifests (deploy/opentofu, k8s/)
- Renamed scripts: docker-root-knoe-db.sh, docker-run-knoe-db.sh, test-cnpg-knoe-db.sh
- Renamed etc/init_prole-db-reset.sh to etc/init_knoe-db-reset.sh
- Renamed etc/prole-db-passwwd.sh to etc/knoe-db-passwwd.sh
- Renamed mock_val counterparts accordingly
- Renamed tests/etc/test_init_prole-db-reset.sh to test_init_knoe-db-reset.sh
- Renamed docs/prole-db-documentation-mcp-architecture.md to knoe-db variant
- Renamed modes/k3d/prole-db/ to modes/k3d/knoe-db/
- Renamed prole-db.iml to knoe-db.iml
6. Configuration updates
- Updated conf/dev, conf/prod, conf/test, conf/service prole.cfg files
- Updated conf/port-mapping.cfg
- Updated etc/prole_cfg.sh and mock_val/prole_cfg.sh
- Updated service/prole.cfg
7. Kubernetes manifests and deploy configuration
- Updated deploy/opentofu/k3s ArgoCD application YAMLs
- Updated kong-configmap.yaml and kustomization.yaml
- Updated k3s/kong-config.yml and prole-resources.yaml
- Updated prole-mssql-db deployment YAMLs
- Updated supabase helm render and deploy scripts
8. Infrastructure and GCP Terraform
- Updated deploy/gcp/terraform: folders, groups, IAM, service-projects
9. Python/installer code updates
- Updated knoe/core: actions, build_context, controller, env, milestones
- Updated knoe/milestone.py
- Updated knoe/ui/screens: cfg, database, database_options, deploy, docker,
navigation, security, services, validate
- Updated knoe.spec, status.py
10. Shell script updates
- Updated etc/: build_db, init_cloudnative_pg, init_cnpg_backup,
init_db_manager, init_forgejo, init_gitlab, init_monitoring, init_openbao,
init_port_forwards, init_postgrest, init_supabase_ports, status
- Updated mock_val/ counterparts for all above scripts
- Updated prole-net/init-prole-dns.sh
- Updated bin/prole-kpf.sh, gitea/deploy.sh, supabase/deploy.sh
11. Test updates
- Updated tests/etc/: test_init_cloudnative_pg*, test_init_cnpg_backup*,
test_init_kdc*, test_init_kerberos*, test_init_kong*, test_prole_cfg*
- Updated tests/installer/: test_actions_helpers, test_cfg_save_kubecontext,
test_controller, test_core_classes, test_milestones, test_milestones_extended,
test_namespace_propagation
- Updated tests/: test_database_options, test_navigation,
test_render_supabase_hostname, test_docker_build_fix,
test_all_prole_home_fixes, silent_install_test, final_test
12. Documentation updates
- Updated docs/: DOCKER-BUILD-FIX, PROLE-CFG-SECRETS, PROLE-HOME-DIRECTORY,
build-system, patent
- Updated scan/network_description.txt
- Updated pom.xml
13. Miscellaneous script updates
- Updated root-level: _adopt_replica_pvcs, _fix_replica_merlin, _import_pi,
_patch_cluster, _prebind_pvcs, _rebind_d002, _rebind_d002b, test_resolve
- Updated scripts/generate_spec.py
Co-authored-by: Junie <junie@jetbrains.com>
264 lines
7.4 KiB
Bash
Executable File
264 lines
7.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
PROLE_HOME=${PROLE_HOME:-$(cd "$SCRIPT_DIR/.." && pwd)}
|
|
|
|
CNPG_TEST_NAMESPACE=${CNPG_TEST_NAMESPACE:-prole-cnpg-test}
|
|
CNPG_CLUSTER_NAME=${CNPG_CLUSTER_NAME:-knoe-db}
|
|
CNPG_OPERATOR_NAMESPACE=${CNPG_OPERATOR_NAMESPACE:-cnpg-system}
|
|
CNPG_CLUSTER_MANIFEST=${CNPG_CLUSTER_MANIFEST:-$PROLE_HOME/k8s/prole/knoe-db.yaml}
|
|
CNPG_USER_SECRET_FILE=${CNPG_USER_SECRET_FILE:-$PROLE_HOME/knoe-db/knoe-db-user-secret.yaml}
|
|
CNPG_WAIT_TIMEOUT=${CNPG_WAIT_TIMEOUT:-300}
|
|
CNPG_FALLBACK_VERSION=${CNPG_FALLBACK_VERSION:-1.27.0}
|
|
|
|
SKIP_BUILD=${SKIP_BUILD:-false}
|
|
IMAGE_REPO=${IMAGE_REPO:-knoe-db}
|
|
IMAGE_LOAD=${IMAGE_LOAD:-}
|
|
IMAGE_LOAD_CMD=${IMAGE_LOAD_CMD:-}
|
|
|
|
log() {
|
|
printf "[%s] %s\n" "$(date +%H:%M:%S)" "$*"
|
|
}
|
|
|
|
require_tool() {
|
|
command -v "$1" >/dev/null 2>&1 || { echo "Missing required tool: $1" >&2; exit 1; }
|
|
}
|
|
|
|
get_latest_cnpg_version() {
|
|
local version=""
|
|
if command -v python3 >/dev/null 2>&1; then
|
|
version=$(python3 - <<'PY'
|
|
import json,sys,urllib.request
|
|
try:
|
|
with urllib.request.urlopen("https://api.github.com/repos/cloudnative-pg/cloudnative-pg/releases/latest", timeout=10) as resp:
|
|
data=json.load(resp)
|
|
tag=data.get("tag_name", "")
|
|
print(tag.lstrip("v"))
|
|
except Exception:
|
|
pass
|
|
PY
|
|
) || true
|
|
fi
|
|
|
|
if [[ -z "$version" ]]; then
|
|
version=$(curl -fsSL "https://api.github.com/repos/cloudnative-pg/cloudnative-pg/releases/latest" 2>/dev/null \
|
|
| sed -n 's/.*"tag_name": *"v\{0,1\}\([^"]*\)".*/\1/p' | head -n1) || true
|
|
fi
|
|
|
|
if [[ -z "$version" ]]; then
|
|
echo "$CNPG_FALLBACK_VERSION"
|
|
else
|
|
echo "$version"
|
|
fi
|
|
}
|
|
|
|
resolve_cnpg_manifest_url() {
|
|
if [[ -n "${CNPG_MANIFEST_URL:-}" ]]; then
|
|
echo "$CNPG_MANIFEST_URL"
|
|
return 0
|
|
fi
|
|
|
|
local version
|
|
version=${CNPG_VERSION:-$(get_latest_cnpg_version)}
|
|
local minor
|
|
minor=$(echo "$version" | awk -F. '{print $1"."$2}')
|
|
echo "https://raw.githubusercontent.com/cloudnative-pg/cloudnative-pg/release-${minor}/releases/cnpg-${version}.yaml"
|
|
}
|
|
|
|
compute_image_tag() {
|
|
local pg_version release
|
|
pg_version=$(tr -d '[:space:]' < "$PROLE_HOME/conf/postgresql/.version" 2>/dev/null || true)
|
|
release=$(tr -d '[:space:]' < "$PROLE_HOME/knoe-db/.version" 2>/dev/null || true)
|
|
|
|
if [[ -z "$pg_version" ]]; then
|
|
pg_version="17.7"
|
|
fi
|
|
|
|
if [[ -z "$release" ]]; then
|
|
release="000"
|
|
fi
|
|
|
|
if [[ "$release" =~ ^[0-9]+$ ]]; then
|
|
release=$(printf "%03d" "$release")
|
|
fi
|
|
|
|
echo "${pg_version}-${release}"
|
|
}
|
|
|
|
ensure_namespace() {
|
|
if ! kubectl get namespace "$CNPG_TEST_NAMESPACE" >/dev/null 2>&1; then
|
|
log "Creating namespace $CNPG_TEST_NAMESPACE"
|
|
kubectl create namespace "$CNPG_TEST_NAMESPACE" >/dev/null
|
|
fi
|
|
}
|
|
|
|
ensure_cnpg_operator() {
|
|
if kubectl get crd clusters.postgresql.cnpg.io >/dev/null 2>&1; then
|
|
log "CNPG CRDs detected; operator install skipped."
|
|
return 0
|
|
fi
|
|
|
|
local url
|
|
url=$(resolve_cnpg_manifest_url)
|
|
log "Installing CloudNative-PG operator from: $url"
|
|
kubectl apply --server-side -f "$url"
|
|
|
|
if kubectl -n "$CNPG_OPERATOR_NAMESPACE" get deploy cnpg-controller-manager >/dev/null 2>&1; then
|
|
kubectl -n "$CNPG_OPERATOR_NAMESPACE" rollout status deploy/cnpg-controller-manager --timeout=120s || true
|
|
fi
|
|
}
|
|
|
|
build_image() {
|
|
local image_tag
|
|
image_tag=$(compute_image_tag)
|
|
IMAGE="${IMAGE_REPO}:${image_tag}"
|
|
|
|
if [[ "$SKIP_BUILD" == "true" ]]; then
|
|
log "Skipping docker build (SKIP_BUILD=true)."
|
|
return 0
|
|
fi
|
|
|
|
log "Building image $IMAGE"
|
|
docker build -t "$IMAGE" "$PROLE_HOME/knoe-db"
|
|
}
|
|
|
|
load_image_if_requested() {
|
|
if [[ -n "$IMAGE_LOAD_CMD" ]]; then
|
|
log "Loading image with custom command: $IMAGE_LOAD_CMD"
|
|
eval "$IMAGE_LOAD_CMD"
|
|
return 0
|
|
fi
|
|
|
|
case "$IMAGE_LOAD" in
|
|
kind)
|
|
require_tool kind
|
|
log "Loading image into kind: $IMAGE"
|
|
kind load docker-image "$IMAGE"
|
|
;;
|
|
minikube)
|
|
require_tool minikube
|
|
log "Loading image into minikube: $IMAGE"
|
|
minikube image load "$IMAGE"
|
|
;;
|
|
k3d)
|
|
require_tool k3d
|
|
log "Importing image into k3d: $IMAGE"
|
|
if [[ -n "${K3D_CLUSTER_NAME:-}" ]]; then
|
|
k3d image import "$IMAGE" -c "$K3D_CLUSTER_NAME"
|
|
else
|
|
k3d image import "$IMAGE"
|
|
fi
|
|
;;
|
|
"")
|
|
;;
|
|
*)
|
|
echo "Unknown IMAGE_LOAD value: $IMAGE_LOAD" >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
}
|
|
|
|
render_cluster_manifest() {
|
|
local out_file=$1
|
|
|
|
if [[ ! -f "$CNPG_CLUSTER_MANIFEST" ]]; then
|
|
echo "Cluster manifest not found: $CNPG_CLUSTER_MANIFEST" >&2
|
|
exit 1
|
|
fi
|
|
|
|
awk -v image="$IMAGE" '
|
|
BEGIN { IGNORECASE=1 }
|
|
/^ imageName:/ { print " imageName: " image; next }
|
|
/^ instances:/ { print " instances: 3"; next }
|
|
/postgis_tiger_geocoder/ { next }
|
|
/schema tiger/ { next }
|
|
{ print }
|
|
' "$CNPG_CLUSTER_MANIFEST" > "$out_file"
|
|
}
|
|
|
|
collect_error_pod_logs() {
|
|
local out_dir=$1
|
|
local pods
|
|
|
|
pods=$(kubectl -n "$CNPG_TEST_NAMESPACE" get pods -l "cnpg.io/cluster=$CNPG_CLUSTER_NAME" --no-headers 2>/dev/null \
|
|
| awk '$3 ~ /(Error|CrashLoopBackOff|Init:Error|Init:CrashLoopBackOff)/ {print $1}')
|
|
|
|
if [[ -z "$pods" ]]; then
|
|
log "No error pods detected."
|
|
return 0
|
|
fi
|
|
|
|
mkdir -p "$out_dir"
|
|
for pod in $pods; do
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" describe pod "$pod" > "$out_dir/${pod}.describe" 2>&1 || true
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" logs "$pod" --all-containers --prefix=true --timestamps=true > "$out_dir/${pod}.log" 2>&1 || true
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" logs "$pod" --all-containers --prefix=true --timestamps=true --previous > "$out_dir/${pod}.previous.log" 2>&1 || true
|
|
done
|
|
log "Error pod logs written to $out_dir"
|
|
}
|
|
|
|
wait_for_primary_ready() {
|
|
log "Waiting for CNPG primary pod to be Ready (timeout ${CNPG_WAIT_TIMEOUT}s)..."
|
|
local deadline
|
|
deadline=$(( $(date +%s) + CNPG_WAIT_TIMEOUT ))
|
|
|
|
while [[ $(date +%s) -lt $deadline ]]; do
|
|
if kubectl -n "$CNPG_TEST_NAMESPACE" get pods \
|
|
-l "cnpg.io/cluster=$CNPG_CLUSTER_NAME,cnpg.io/instanceRole=primary" \
|
|
--no-headers 2>/dev/null | grep -q .; then
|
|
if kubectl -n "$CNPG_TEST_NAMESPACE" wait --for=condition=Ready pod \
|
|
-l "cnpg.io/cluster=$CNPG_CLUSTER_NAME,cnpg.io/instanceRole=primary" \
|
|
--timeout=30s; then
|
|
return 0
|
|
fi
|
|
fi
|
|
sleep 5
|
|
done
|
|
|
|
return 1
|
|
}
|
|
|
|
main() {
|
|
require_tool kubectl
|
|
require_tool docker
|
|
|
|
build_image
|
|
load_image_if_requested
|
|
|
|
ensure_namespace
|
|
ensure_cnpg_operator
|
|
|
|
if [[ -f "$CNPG_USER_SECRET_FILE" ]]; then
|
|
log "Applying CNPG user secret: $CNPG_USER_SECRET_FILE"
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" apply -f "$CNPG_USER_SECRET_FILE"
|
|
else
|
|
log "Skipping CNPG user secret (file not found): $CNPG_USER_SECRET_FILE"
|
|
fi
|
|
|
|
local tmp_dir
|
|
tmp_dir=$(mktemp -d)
|
|
local rendered_manifest="$tmp_dir/cluster.yaml"
|
|
render_cluster_manifest "$rendered_manifest"
|
|
|
|
log "Applying CNPG cluster manifest: $rendered_manifest"
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" apply -f "$rendered_manifest"
|
|
|
|
if ! wait_for_primary_ready; then
|
|
local log_dir
|
|
local base_log_dir
|
|
base_log_dir="${PROLE_LOGS:-$PROLE_HOME/logs}"
|
|
base_log_dir="${base_log_dir%/}"
|
|
log_dir=${CNPG_TEST_LOG_DIR:-$base_log_dir/cnpg-test-$(date +%Y%m%dT%H%M%S)}
|
|
collect_error_pod_logs "$log_dir"
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" get pods -l "cnpg.io/cluster=$CNPG_CLUSTER_NAME" || true
|
|
echo "CNPG primary pod did not become Ready within timeout." >&2
|
|
exit 1
|
|
fi
|
|
|
|
kubectl -n "$CNPG_TEST_NAMESPACE" get pods -l "cnpg.io/cluster=$CNPG_CLUSTER_NAME" || true
|
|
log "CNPG test completed successfully."
|
|
}
|
|
|
|
main "$@"
|