fix(ops): reach the DB via ephemeral psql pod, drop CNPG discovery - #23
Merged
Conversation
Run 31169336292's diagnostics settled it: the platform namespace has no CNPG Cluster CR and no ranch-db-* pods — the k8s/deploy and k8s/infrastructure CNPG manifests never reached the cluster (known ArgoCD sync gap), and terraform's database module is a stub deferring to those same manifests. Where the DB actually lives is unknowable from the repo, so stop looking for it: launch an ephemeral postgres:16-alpine pod that gets DATABASE_URL from the ranch-api-env secret via secretKeyRef (the exact string the running API uses; never leaves the cluster, only its credential-stripped host/db part is logged) and pipe the same guarded SQL through kubectl exec. Inputs enter the pod as env vars and reach SQL via \getenv + set_config; the pod self-expires (activeDeadlineSeconds) and an always() step deletes it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Evidence from the last run
The diagnostics added in #22 settled the question (run after #22 merge):
clusters.postgresql.cnpg.ioinplatform: No resources foundranch-db-*pods; the namespace holds onlyranch-api/app/admin,lightrag(+ its own postgres) andbrowser-poolSo the CNPG cluster from
k8s/deploy/10-postgres.yaml/k8s/infrastructure/database/pg-cluster.yamldoes not exist in prod — the known ArgoCD sync gap. Terraform'smodules/databaseis a stub deferring to those same manifests. Where the API's database actually lives is unknowable from the repo — butranch-apiis Running, so itsDATABASE_URLin theranch-api-envsecret points at the real thing.Fix
Stop searching for a DB pod entirely:
postgres:16-alpineclient pod inplatformthat receivesDATABASE_URLviasecretKeyRef— the exact connection string the running API uses. It never leaves the cluster and is never printed; the step echoes only the credential-strippedhost:port/dbpart for the log.kubectl execpipes the same guarded SQL throughpsql "$DATABASE_URL"— works wherever the DB lives (in-cluster, external, managed).\getenv+set_config()— still zero string interpolation.activeDeadlineSeconds: 600,sleep 300command) and anif: always()step deletes it, so nothing lingers even on failure.Guards unchanged: target must exist, the last remaining Owner can never be demoted, owners printed before/after.
Verification
Next dispatch after merge. If the client pod can't start (image pull, missing secret key), the step dumps
kubectl describeof the pod instead of a bare error.🤖 Generated with Claude Code