prole/knoe/core/repair_pipeline_cli.py
chrisfu c0a7d0c5dc Refine installer orchestration and Supabase rendering paths
- improve installer/action/controller flow and shell-variable expansion handling across screens\n- adjust Supabase Helm rendering and storage deployment templates\n- align monitoring, cloudnative-pg and repair pipeline behavior with updated config paths\n- refresh and expand installer/core regression tests around milestones, navigation and repair logic

Co-authored-by: Junie <junie@jetbrains.com>
2026-03-31 23:15:54 -07:00

128 lines
3.6 KiB
Python

from __future__ import annotations
import argparse
import os
import sys
from pathlib import Path
from knoe import prole_conf
from knoe.core.controller import KnoeController
from knoe.core.actions import KnoeConsoleInstaller
def _project_root() -> Path:
env_home = (os.environ.get("PROLE_HOME") or "").strip()
if env_home:
try:
return Path(env_home).expanduser().resolve()
except Exception:
pass
return Path(__file__).resolve().parents[2]
def _normalize_cfg_path(raw: str | None) -> str | None:
if not raw:
return None
s = str(raw).strip()
if not s:
return None
try:
p = Path(s).expanduser()
if p.is_dir():
return str((p / "prole.cfg").resolve())
return str(p.resolve())
except Exception:
return s
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(prog="repair_pipeline")
parser.add_argument(
"-n",
"--namespace",
dest="service_namespace",
default="",
help="Service namespace (common-core namespace)",
)
parser.add_argument(
"--db-namespace",
dest="db_namespace",
default="",
help="Database namespace",
)
parser.add_argument(
"-m",
"--mode",
dest="mode",
default="",
help="Deployment mode: k3s, k3d, k8s",
)
parser.add_argument(
"--config",
dest="config",
default="",
help="Path to prole.cfg (or directory containing it)",
)
parser.add_argument("--verbose", action="store_true")
args = parser.parse_args(argv)
mode = (args.mode or "").strip()
if mode and mode not in ("k3s", "k3d", "k8s"):
print(f"[ERROR] Invalid --mode {mode!r} (expected k3s|k3d|k8s)", file=sys.stderr)
return 2
root = _project_root()
cfg = _normalize_cfg_path(args.config)
if not cfg:
env_conf = (os.environ.get("PROLE_CONF") or "").strip()
if env_conf:
cfg = _normalize_cfg_path(env_conf)
if not cfg:
cfg = str(prole_conf.entrypoint_path(prole_conf.resolve_prole_conf_dir(root)))
controller = KnoeController(project_root=root, verbose=bool(args.verbose), cfg_path=Path(cfg))
installer = KnoeConsoleInstaller(controller, cfg_path=cfg)
try:
existing_inputs = knoe._load_inputs_from_cfg()
except Exception:
existing_inputs = {}
knoe.inputs = {**knoe._default_inputs(), **existing_inputs}
# Ensure mode influences the env we build (KUBECONFIG resolution, etc.).
if mode == "k3s":
knoe.inputs["init_cluster.cluster_env"] = "service"
elif mode == "k3d":
knoe.inputs["init_cluster.cluster_env"] = "dev"
elif mode == "k8s":
knoe.inputs["init_cluster.cluster_env"] = "prod"
service_ns = (args.service_namespace or "").strip() or knoe._service_namespace()
db_ns = (
(args.db_namespace or "").strip()
or (knoe._get_input("init_password.db_namespace", "") or "").strip()
or service_ns
or "default"
)
if args.db_namespace:
knoe.inputs["init_password.db_namespace"] = db_ns
env = knoe._script_env_for_namespace(service_ns)
env["SERVICE_NAMESPACE"] = service_ns
env["DB_NAMESPACE"] = db_ns
env["NAMESPACE"] = service_ns
anomalies: list[str] = []
if knoe._dashboard_kong_missing(env):
anomalies.append("dashboard")
if knoe._authority_context_missing():
anomalies.append("authority")
knoe._repair_stale_released_pvs(env)
knoe._run_cluster_repair_pipeline(env=env, anomalies=anomalies)
return 0
if __name__ == "__main__":
raise SystemExit(main())