Skip to content

Commit eddfee6

Browse files
committed
Look in more directories for Postgres binaries
This makes PostgresCluster compatible with images from other distros. Issue: PGO-864
1 parent 0276eff commit eddfee6

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

internal/patroni/config.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,6 @@ func instanceYAML(
484484
}
485485

486486
postgresql := map[string]any{
487-
// TODO(cbandy): "bin_dir"
488-
489487
// Missing here is "connect_address" which cannot be known until the
490488
// instance Pod is created. That value should be injected using the downward
491489
// API and the PATRONI_POSTGRESQL_CONNECT_ADDRESS environment variable.

internal/patroni/reconcile.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ func InstancePod(ctx context.Context,
105105
}
106106
}
107107

108-
container.Command = []string{"patroni", configDirectory}
108+
// Start Patroni in an environment that prioritizes executables of the specified Postgres version.
109+
// NOTE: Patroni ignores PATH when "postgresql.bin_dir" is set.
110+
//
111+
// https://patroni.readthedocs.io/en/latest/yaml_configuration.html#postgresql
112+
container.Command = []string{
113+
"sh", "-c", "--", postgres.ShellPath(inCluster.Spec.PostgresVersion) + ` && exec "$@"`, "--",
114+
"patroni", configDirectory,
115+
}
109116

110117
container.Env = append(container.Env,
111118
instanceEnvironment(inCluster, inClusterPodService, inPatroniLeaderService,

internal/patroni/reconcile_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ func TestInstancePod(t *testing.T) {
140140
assert.Assert(t, cmp.MarshalMatches(template.Spec, `
141141
containers:
142142
- command:
143+
- sh
144+
- -c
145+
- --
146+
- PATH="/usr/lib/postgresql/11/bin:/usr/libexec/postgresql11:/usr/pgsql-11/bin${PATH+:${PATH}}"
147+
&& exec "$@"
148+
- --
143149
- patroni
144150
- /etc/patroni
145151
env:

internal/postgres/config.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func startupCommand(
405405
instance *v1beta1.PostgresInstanceSetSpec,
406406
parameters *ParameterSet,
407407
) []string {
408-
version := fmt.Sprint(cluster.Spec.PostgresVersion)
408+
version := cluster.Spec.PostgresVersion
409409
dataDir := DataDirectory(cluster)
410410
logDir := parameters.Value("log_directory")
411411
walDir := WALDirectory(cluster, instance)
@@ -463,7 +463,7 @@ chmod +x /tmp/pg_rewind_tde.sh
463463
`
464464
}
465465

466-
args := []string{version, walDir}
466+
args := []string{fmt.Sprint(version), walDir}
467467
script := strings.Join([]string{
468468
`declare -r expected_major_version="$1" pgwal_directory="$2"`,
469469

@@ -485,6 +485,9 @@ chmod +x /tmp/pg_rewind_tde.sh
485485
// Function to change a directory symlink while keeping the directory contents.
486486
strings.TrimSpace(bashSafeLink),
487487

488+
// Prioritize executables for this major version of Postgres.
489+
ShellPath(version),
490+
488491
// Log the effective user ID and all the group IDs.
489492
`echo Initializing ...`,
490493
`results 'uid' "$(id -u ||:)" 'gid' "$(id -G ||:)"`,

internal/postgres/reconcile_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ initContainers:
274274
set -x; mv --no-target-directory "${current}" "${desired}"
275275
ln --no-dereference --force --symbolic "${desired}" "${name}"
276276
)
277+
PATH="/usr/lib/postgresql/11/bin:/usr/libexec/postgresql11:/usr/pgsql-11/bin${PATH+:${PATH}}"
277278
echo Initializing ...
278279
results 'uid' "$(id -u ||:)" 'gid' "$(id -G ||:)"
279280
if [[ "${pgwal_directory}" == *"pgwal/"* ]] && [[ ! -d "/pgwal/pgbackrest-spool" ]];then rm -rf "/pgdata/pgbackrest-spool" && mkdir -p "/pgwal/pgbackrest-spool" && ln --force --symbolic "/pgwal/pgbackrest-spool" "/pgdata/pgbackrest-spool";fi

0 commit comments

Comments
 (0)