helm: add db-init pre-install hook for external PostgreSQL#311
helm: add db-init pre-install hook for external PostgreSQL#311
Conversation
…ives Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)
|
Consolidating into 2 PRs: chart features + docs |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f18d345f03
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| nodeSelector: | ||
| {{- . | nindent 8 }} |
There was a problem hiding this comment.
Align deployment nodeSelector with pod-spec indentation
This nodeSelector key is indented one space deeper than sibling pod-spec fields, so when nodeSelector/global.nodeSelector is set and this block renders, Helm emits invalid YAML for the Deployment and install/template fails with a parse error. The key needs to align with other fields under spec.template.spec.
Useful? React with 👍 / 👎.
| {{- with (include "codex-lb.nodeSelector" .) }} | ||
| nodeSelector: | ||
| {{- . | nindent 8 }} |
There was a problem hiding this comment.
Align migration hook nodeSelector indentation
The migration Job has the same over-indented nodeSelector block, which renders invalid YAML whenever a node selector is configured; because migration.enabled defaults to true, this can break installs/upgrades in common configurations that set node selectors. The nodeSelector key must be aligned with other fields under spec.template.spec.
Useful? React with 👍 / 👎.
| {{- range .Values.dbInit.databases }} | ||
| DO $$ BEGIN | ||
| IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '{{ .user }}') THEN | ||
| CREATE ROLE {{ .user }} WITH LOGIN PASSWORD '{{ .password }}'; |
There was a problem hiding this comment.
Escape db-init SQL identifiers and literals
This statement injects Helm values directly into SQL without identifier/literal escaping, so valid inputs like a username containing - or a password containing ' will break the hook (and can alter SQL semantics). Use SQL-safe quoting (%I/%L, quote_ident, quote_literal) for role/database names and passwords before executing.
Useful? React with 👍 / 👎.
| {{- with .Values.nodeSelector }} | ||
| nodeSelector: | ||
| {{- toYaml . | nindent 8 }} |
There was a problem hiding this comment.
Apply merged nodeSelector helper in db-init hook
The new db-init Job reads only .Values.nodeSelector, so global.nodeSelector is ignored for this hook while other pods were switched to the merged helper. In clusters relying on global selectors for placement/network access, db-init can run on unintended nodes or fail scheduling; this hook should use the same merged selector logic as deployment/migration/test pods.
Useful? React with 👍 / 👎.
Summary
dbInit.enabled=trueandpostgresql.enabled=false(external DB mode)dbInit.databaseslistMotivation
When using external managed PostgreSQL (OCI, RDS, Cloud SQL), users must manually create application databases and users before deploying codex-lb. This hook automates that step.
Changes
templates/hooks/db-init-job.yaml: New pre-install hook Jobvalues.yaml: AdddbInitsection