Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,6 @@ func instanceYAML(
}

postgresql := map[string]any{
// TODO(cbandy): "bin_dir"

// Missing here is "connect_address" which cannot be known until the
// instance Pod is created. That value should be injected using the downward
// API and the PATRONI_POSTGRESQL_CONNECT_ADDRESS environment variable.
Expand Down
9 changes: 8 additions & 1 deletion internal/patroni/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,14 @@ func InstancePod(ctx context.Context,
}
}

container.Command = []string{"patroni", configDirectory}
// Start Patroni in an environment that prioritizes executables of the specified Postgres version.
// NOTE: Patroni ignores PATH when "postgresql.bin_dir" is set.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could users set this and break something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Patroni reads this setting from YAML files or environment variables, neither of which is configurable.

//
// https://patroni.readthedocs.io/en/latest/yaml_configuration.html#postgresql
container.Command = []string{
"sh", "-c", "--", postgres.ShellPath(inCluster.Spec.PostgresVersion) + ` && exec "$@"`, "--",
"patroni", configDirectory,
}

container.Env = append(container.Env,
instanceEnvironment(inCluster, inClusterPodService, inPatroniLeaderService,
Expand Down
6 changes: 6 additions & 0 deletions internal/patroni/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ func TestInstancePod(t *testing.T) {
assert.Assert(t, cmp.MarshalMatches(template.Spec, `
containers:
- command:
- sh
- -c
- --
- PATH="/usr/lib/postgresql/11/bin:/usr/libexec/postgresql11:/usr/pgsql-11/bin${PATH+:${PATH}}"
&& exec "$@"
- --
- patroni
- /etc/patroni
env:
Expand Down
7 changes: 5 additions & 2 deletions internal/postgres/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func startupCommand(
instance *v1beta1.PostgresInstanceSetSpec,
parameters *ParameterSet,
) []string {
version := fmt.Sprint(cluster.Spec.PostgresVersion)
version := cluster.Spec.PostgresVersion
dataDir := DataDirectory(cluster)
logDir := parameters.Value("log_directory")
walDir := WALDirectory(cluster, instance)
Expand Down Expand Up @@ -463,7 +463,7 @@ chmod +x /tmp/pg_rewind_tde.sh
`
}

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

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

// Prioritize executables for this major version of Postgres.
ShellPath(version),

// Log the effective user ID and all the group IDs.
`echo Initializing ...`,
`results 'uid' "$(id -u ||:)" 'gid' "$(id -G ||:)"`,
Expand Down
1 change: 1 addition & 0 deletions internal/postgres/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ initContainers:
set -x; mv --no-target-directory "${current}" "${desired}"
ln --no-dereference --force --symbolic "${desired}" "${name}"
)
PATH="/usr/lib/postgresql/11/bin:/usr/libexec/postgresql11:/usr/pgsql-11/bin${PATH+:${PATH}}"
echo Initializing ...
results 'uid' "$(id -u ||:)" 'gid' "$(id -G ||:)"
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
Expand Down
Loading