prole/deploy.sh
chrisfu 7c46b52e7e chore: refine deploy.sh and Supabase ingress timeout diagnostics
- Simplified public APP endpoint fallback logic in `deploy.sh`.
- Enhanced timeout handling with detailed Supabase ingress reconciliation diagnostics.
- Removed redundant ingress class override in Helm template for Supabase.
2026-04-15 22:32:41 -07:00

100 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CONFIG_PATH="${PROLE_DEPLOY_CFG:-${ROOT_DIR}/conf/gke.cfg}"
if [[ -x "${ROOT_DIR}/.venv/bin/python3" ]]; then
PYTHON_BIN="${ROOT_DIR}/.venv/bin/python3"
elif [[ -x "${ROOT_DIR}/bin/python3" ]]; then
PYTHON_BIN="${ROOT_DIR}/bin/python3"
else
PYTHON_BIN="${PYTHON:-python3}"
fi
"${PYTHON_BIN}" -m prole.deploy_pipeline --config "${CONFIG_PATH}" "$@"
# Post-deploy summary
echo ""
echo "Public Endpoints:"
"${PYTHON_BIN}" - "${CONFIG_PATH}" <<'PY'
import sys
import subprocess
import json
import configparser
import time
def get_config(path):
c = configparser.ConfigParser()
c.read(path)
# Check [Global] then [env_setup] then [init_cluster] for contexts
g = c["Global"] if "Global" in c else {}
e = c["env_setup"] if "env_setup" in c else {}
i = c["init_cluster"] if "init_cluster" in c else {}
app_ctx = g.get("APP_CLUSTER_KUBECONTEXT") or e.get("APP_CLUSTER_KUBECONTEXT") or i.get("app_cluster_kubecontext", "")
db_ctx = g.get("DB_CLUSTER_KUBECONTEXT") or e.get("DB_CLUSTER_KUBECONTEXT") or i.get("db_cluster_kubecontext", "")
return app_ctx, db_ctx
def get_ip(host, ctx):
if not ctx: return "pending"
# Try Ingress first
try:
out = subprocess.check_output(["kubectl", "--context", ctx, "get", "ingress", "-A", "-o", "json"], stderr=subprocess.DEVNULL, text=True)
items = json.loads(out).get("items", [])
for item in items:
for rule in item.get("spec", {}).get("rules", []):
if rule.get("host") == host:
ing = item.get("status", {}).get("loadBalancer", {}).get("ingress", [])
if ing:
val = ing[0].get("ip") or ing[0].get("hostname")
if val: return val
except: pass
# Public APP endpoints must be sourced from Ingress status
# api.knoe.dev, git.knoe.dev, svc.knoe.dev, api.0.knoe.dev, db.0.knoe.dev
return "pending"
app_ctx, db_ctx = get_config(sys.argv[1])
# Targets we want to wait for if they are pending
wait_hosts = ["api.0.knoe.dev", "db.0.knoe.dev"]
timeout = 300 # 5 minutes
start = time.time()
while time.time() - start < timeout:
pending = False
for h in wait_hosts:
if get_ip(h, app_ctx) == "pending":
pending = True
break
if not pending:
break
time.sleep(10)
if time.time() - start >= timeout:
print("\nERROR: Timeout waiting for Supabase ingress reconciliation.")
print("Ingress Controller Diagnosis (kubectl get events -n supabase):")
try:
subprocess.run(["kubectl", "--context", app_ctx, "get", "events", "-n", "supabase", "--sort-by=.lastTimestamp"], check=False)
print("\nIngress Resource Status:")
subprocess.run(["kubectl", "--context", app_ctx, "describe", "ingress", "supabase-public", "-n", "supabase"], check=False)
except:
pass
sys.exit(1)
endpoints = [
("api.knoe.dev", "knoe-svc-kong", "APP", app_ctx),
("git.knoe.dev", "GitLab", "APP", app_ctx),
("db.0.knoe.dev", "Supabase Studio", "APP", app_ctx),
("api.0.knoe.dev", "Supabase Kong", "APP", app_ctx),
("svc.knoe.dev", "Grafana", "APP", app_ctx),
]
print(f"{'hostname':<20} {'service':<20} {'cluster':<10} {'external IP':<15}")
print("-" * 70)
for host, svc, clus, ctx in endpoints:
ip = get_ip(host, ctx)
print(f"{host:<20} {svc:<20} {clus:<10} {ip:<15}")
PY