Use $HOSTNAME in restore.sh instead of the hostname binary - #71
Merged
Conversation
restore.sh is the only script in this repo that shells out to hostname; every other one uses $HOSTNAME. The hostname binary is not installed in the RHEL/CentOS Stream based images that run this script, so HOST came back empty. The script has no set -e, so it carried on: the [[ "$HOST" =~ -0$ ]] test was false on every pod, ordinal 0 got recovery_target_action = 'pause' instead of 'promote', and the script then waited forever on pg_is_wal_replay_paused() for a node that was supposed to promote. Signed-off-by: Tamal Saha <tamal@appscode.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.
scripts/restore.shis the only script in this repo that shells out to thehostnamebinary; every other one reads bash's$HOSTNAME.hostnameis not installed in the RHEL/CentOS Stream based images that run this script — neitherghcr.io/appscode-images/postgres-enterprise:16.9-stream9-extnor theghcr.io/kubedb/postgres-archiver:*_16.9-stream9*image that actually executes it (Walg.Image, wired up in kubedb/postgrespkg/controller/sidekick.go). There is nohostnamepackage in either;command -v hostnamecomes back empty in both.The failure
HOST=$(hostname)The script has no
set -e, so it carries on withHOSTempty. Every later branch keys off it:With
HOSTempty the test is false on every pod, so ordinal 0 is configured to pause instead of promote. The script then takes the replica path at the bottom and loops forever onpg_is_wal_replay_paused()waiting for a node that was supposed to promote — a PITR restore that never completes.The fix
Use
$HOSTNAME, which bash sets itself, matching whatconfig_recovery.conf.sh,ha_backup_job.sh,warm_stanby.sh,start.shand the rest of the repo already do. No os-release branching needed — this works identically on alpine, bookworm and stream9.Verification
HOST="$HOSTNAME"in a#!/bin/bashscript, run with--hostname my-pg-0and--hostname my-pg-2:bash -n scripts/restore.shis clean.