fix(db): seed postgresql-custom idempotently instead of empty-dir check - #250
Open
ymichaelson wants to merge 1 commit into
Open
fix(db): seed postgresql-custom idempotently instead of empty-dir check#250ymichaelson wants to merge 1 commit into
ymichaelson wants to merge 1 commit into
Conversation
The init-pgsodium container gated the copy of default postgresql-custom config files on the pgsodium volume being empty ([ -z "$(ls -A)" ]). On block-storage volumes (EBS, GCE PD, Ceph RBD, OpenEBS LVM, ...) the filesystem is formatted ext4/xfs and ships a lost+found directory, so the volume is never truly empty on first use. The copy was skipped, leaving /etc/postgresql-custom/*.conf missing and postgres failing to start with "configuration file postgresql.conf contains errors" (CrashLoopBackOff). Replace the emptiness check with an idempotent no-clobber copy (cp -an): it seeds any missing config files on every start without overwriting existing ones, preserving runtime-generated pgsodium keys (the reason the persistent volume was introduced in supabase-community#197).
Contributor
|
Hi @ymichaelson, thanks for the PR. The idea of replacing the empty-dir check with an idempotent copy is definitely the right direction for block-storage volumes. I wanted to let you know that the I reproduced it locally and the root cause is that $ docker run --rm --entrypoint /bin/sh supabase/postgres:17.6.1.136 -c 'cp --version'
cp: unrecognized option: version
BusyBox v1.37.0$ docker run --rm -v vol:/mnt/pgsodium supabase/postgres:17.6.1.136 -c 'cp -an /etc/postgresql-custom/. /mnt/pgsodium/ && ls /mnt/pgsodium'
# exit 0, but nothing is copiedSo the init-pgsodium container finishes successfully but leaves /mnt/pgsodium empty. Then the postgres container mounts that empty volume at /etc/postgresql-custom and fails with: |
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
The
init-pgsodiumcontainer copies default/etc/postgresql-customconfigfiles only when the pgsodium volume is empty (
[ -z "$(ls -A)" ]). Onblock-storage volumes (OpenEBS LVM, AWS EBS, GCE PD, Ceph RBD, ...) the
ext4/xfs filesystem ships a
lost+founddirectory, so the volume is nevertruly empty on first use. The copy is skipped, the config files are missing,
and postgres fails to start:
Result: db StatefulSet in CrashLoopBackOff on any block-backed StorageClass.
Fixes #248.
What is the new behavior?
Replace the emptiness check with an idempotent, no-clobber copy:
-n(no-clobber) never overwrites existing files, so runtime-generatedpgsodium keys are preserved across restarts (the reason feat(db): add persistent pgsodium volume mounted at /etc/postgresql-custom #197 added the
persistent volume).
lost+foundno longer blocks the copy.emptyDirand block-backed volumes.Additional context
Verified
cp -anidempotency locally: a runtime-modified file is preserved,a missing file is re-seeded, and a
lost+founddirectory has no effect.helm lintpasses and templates render. Chart version bumped 0.7.2 -> 0.7.3.