Files
forgeway/scripts/apply_cloud_secret.py
Dolon (Agent)andClaude Opus 5 3155d4a230 forgeway 0.1.1 — per-cluster OpenAI-compatible LLM router
Two endpoints over forge's Ollama gpt-oss:120b:
  /local-optimistic/v1  forge, else cloud gpt-5.4-mini
  /local-strict/v1      forge, else a clean 503 the caller handles

Discovery, not configuration: each instance probes an ordered candidate list
(stable DNS name, then the Lounge and future Serenity literals) concurrently but
in priority order, so the happy path is one round trip and silicon's move to
Serenity needs no rewrite.

/healthz runs a real 1-token completion — forge can be up with Ollama stopped.
Liveness/readiness are deliberately NOT forge-gated: otherwise k8s would evict
the pods during an outage and callers would get a connection failure instead of
the promised 503, and Kuma could not tell "forge down" from "router gone".

max_tokens/max_completion_tokens are translated per backend: Ollama accepts only
the former, gpt-5.4-mini rejects it outright.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 14:30:14 +00:00

74 lines
2.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""Create/refresh the cloud-fallback Secret in a cluster, out of band.
The credential is read from this process's environment and handed to kubectl on
stdin. It is never placed in a command line, an argument, a URL, a log line, or
a shell variable, and it is never written to the GitOps repo.
python3 scripts/apply_cloud_secret.py ~/.kube/rocinante-admin.yaml
"""
from __future__ import annotations
import base64
import json
import os
import subprocess
import sys
NAMESPACE = "forgeway"
SECRET = "forgeway-cloud"
def main() -> int:
if len(sys.argv) != 2:
return print(__doc__) or 2
kubeconfig = os.path.expanduser(sys.argv[1])
key = os.environ.get("OPENAI_API_KEY", "")
if not key:
print("OPENAI_API_KEY is not present in this environment", file=sys.stderr)
return 1
env = {**os.environ, "KUBECONFIG": kubeconfig}
subprocess.run(
["kubectl", "create", "namespace", NAMESPACE, "--dry-run=client", "-o", "json"],
env=env, check=True, capture_output=True,
)
ns = subprocess.run(
["kubectl", "get", "namespace", NAMESPACE],
env=env, capture_output=True,
)
if ns.returncode != 0:
subprocess.run(["kubectl", "create", "namespace", NAMESPACE], env=env, check=True)
manifest = {
"apiVersion": "v1",
"kind": "Secret",
"metadata": {
"name": SECRET,
"namespace": NAMESPACE,
"annotations": {
# Argo does not manage this object; it is applied out of band so
# the credential never reaches the repo.
"argocd.argoproj.io/sync-options": "Prune=false",
},
},
"type": "Opaque",
"data": {"OPENAI_API_KEY": base64.b64encode(key.encode()).decode()},
}
proc = subprocess.run(
["kubectl", "apply", "-f", "-"],
env=env, input=json.dumps(manifest).encode(), capture_output=True,
)
sys.stdout.write(proc.stdout.decode())
sys.stderr.write(proc.stderr.decode())
if proc.returncode == 0:
print(f"ok: {NAMESPACE}/{SECRET} applied (value not shown)")
return proc.returncode
if __name__ == "__main__":
raise SystemExit(main())