Repository navigation
Fix/cluster reseed cnpg - #438
Merged
Merged
Conversation
Mike Farah's yq (nixpkgs yq-go, binary `yq`), so recipes can read YAML with a query instead of a hand-written parser. cluster.just is the first to need it: it reads the backend's database settings out of its ConfigMap.
cluster::backup, wipe and reseed assumed the chart's bundled postgres: a StatefulSet to exec into, a superuser, and a Secret named hackagon-backend-db. Dev runs CloudNativePG instead, so reseed stopped on the missing Secret before touching anything. The recipes now read where the database is and how to log in from the backend itself: host, dbname and user from its ConfigMap, the password from the Secret its Deployment references. Everything runs as that user through a port-forward, so neither exec nor a superuser is needed: - backup is a pg_dump of the app database. Keycloak's database is no longer in it; none of these recipes touches Keycloak. - wipe drops everything in the backend's schema in one transaction instead of DROP DATABASE, which needs a superuser and may fight an operator that manages the database. - Both refuse before changing anything if the user does not own every relation it would have to drop, or if the tunnel has closed. - A database host naming another namespace is refused: the port-forward stays in the guarded one, so it would reach the wrong database. - pg_dump and psql connect without TLS, as the backend does. Over TLS, postgres resets each connection as it closes, and kubectl drops the whole port-forward over one reset. - The tunnel is ready when kubectl prints "Forwarding from", rather than when a probe connection gets through. The public recipes run inside the Nix shell, which brings pg_dump and psql.
marftn
requested changes
Nov 19, 2026
marftn
left a comment
Contributor
There was a problem hiding this comment.
It looks good but there is a small potential race condition with the kubeconfig: if you switch the kubeconfig context from dev to prod in another terminal after the guard has passed (e.g., during build time), it will try to run on prod. This is unlikely to have an impact with the current setup because the namespace names also differ from dev to prod.
It can be fixed easily by resolving the context once at the start and passing it with --context to every kubectl call. The threat is quite low, so I'm also ok with leaving this out to avoid making the file more complicated. Let me know what you prefer :)
Every kubectl call used the kubeconfig's current context at the moment it ran, so switching contexts in another terminal after the guard had passed (during the seed build, say) sent the rest of the run to the new one. The first recipe of a run now reads the current context once and exports it as HACKAGON_KUBE_CONTEXT; the recipes it calls inherit it, and every kubectl call passes it as --context. Setting HACKAGON_KUBE_CONTEXT up front picks a context without switching to it.
marftn
approved these changes
Nov 19, 2026
marftn
left a comment
Contributor
There was a problem hiding this comment.
Looks good now! Thanks 🙂 you can merge.
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.
Operators can back up, wipe and reseed dev and staging again
Before:
just cluster::reseed devstopped withsecrets "hackagon-backend-db" not found. The cluster recipes assumed the chart's bundled postgres.Change: Dev and staging run on CloudNativePG, with a different Secret, different service names and no superuser. Now the recipes ask the running backend where its database is and how it logs in, then do everything as that same user through one port-forward.
just cluster::backup,wipeandreseedwork on dev withoutkubectl execor superuser accessbackupdumps the app database only. Keycloak's database is no longer included, and these recipes never touch it.wipeempties the app database in one transaction instead of dropping itHACKAGON_KUBE_CONTEXTto pick a context without switching to it.yq