Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5756ad3

Browse files
committed
FIXUP: mkdir conditionally
1 parent 56a8263 commit 5756ad3

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

‎internal/postgres/config.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,28 @@ func startupCommand(
315315
parameters *ParameterSet,
316316
) []string {
317317
version := fmt.Sprint(cluster.Spec.PostgresVersion)
318-
logDir := parameters.Value("log_directory")
318+
dataDir := DataDirectory(cluster)
319319
walDir := WALDirectory(cluster, instance)
320320

321+
// TODO: describe this?
322+
mkdirs := make([]string, 0, 6)
323+
mkdir := func(b, p string) {
324+
if path.IsAbs(p) {
325+
p = path.Clean(p)
326+
} else {
327+
p = path.Join(dataDir, p)
328+
}
329+
330+
// Create directories unless they are in the empty Postgres data directory.
331+
mkdirs = append(mkdirs,
332+
`[[ `+shell.QuoteWord(p)+` != "${postgres_data_directory}"* || -f "${postgres_data_directory}/PG_VERSION" ]] &&`,
333+
`{ (`+shell.MakeDirectories(b, p)+`) || halt "$(permissions `+shell.QuoteWord(p)+` ||:)"; }`,
334+
)
335+
}
336+
mkdir(dataMountPath, naming.PGBackRestPGDataLogPath)
337+
mkdir(dataMountPath, naming.PatroniPGDataLogPath)
338+
mkdir(dataDir, parameters.Value("log_directory"))
339+
321340
// If the user requests tablespaces, we want to make sure the directories exist with the
322341
// correct owner and permissions.
323342
tablespaceCmd := ""
@@ -445,14 +464,7 @@ chmod +x /tmp/pg_rewind_tde.sh
445464
`else (halt Permissions!); fi ||`,
446465
`halt "$(permissions "${postgres_data_directory}" ||:)"`,
447466

448-
// Create log directories.
449-
`(` + shell.MakeDirectories(dataMountPath, naming.PGBackRestPGDataLogPath) + `) ||`,
450-
`halt "$(permissions ` + naming.PGBackRestPGDataLogPath + ` ||:)"`,
451-
`(` + shell.MakeDirectories(dataMountPath, naming.PatroniPGDataLogPath) + `) ||`,
452-
`halt "$(permissions ` + naming.PatroniPGDataLogPath + ` ||:)"`,
453-
`(` + shell.MakeDirectories(DataDirectory(cluster), logDir) + `) ||`,
454-
// FIXME: This error prints the wrong directory when logDir is relative (the default).
455-
`halt "$(permissions ` + logDir + ` ||:)"`,
467+
strings.Join(mkdirs, "\n"),
456468

457469
// Copy replication client certificate files
458470
// from the /pgconf/tls/replication directory to the /tmp/replication directory in order

‎internal/postgres/reconcile_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ initContainers:
270270
recreate "${postgres_data_directory}" '0750'
271271
else (halt Permissions!); fi ||
272272
halt "$(permissions "${postgres_data_directory}" ||:)"
273-
(mkdir -p '/pgdata/pgbackrest/log' && { chmod 0775 '/pgdata/pgbackrest/log' '/pgdata/pgbackrest' || :; }) ||
274-
halt "$(permissions /pgdata/pgbackrest/log ||:)"
275-
(mkdir -p '/pgdata/patroni/log' && { chmod 0775 '/pgdata/patroni/log' '/pgdata/patroni' || :; }) ||
276-
halt "$(permissions /pgdata/patroni/log ||:)"
277-
(mkdir -p '/pgdata/pg11/log' && { chmod 0775 '/pgdata/pg11/log' || :; }) ||
278-
halt "$(permissions log ||:)"
273+
[[ '/pgdata/pgbackrest/log' != "${postgres_data_directory}"* || -f "${postgres_data_directory}/PG_VERSION" ]] &&
274+
{ (mkdir -p '/pgdata/pgbackrest/log' && { chmod 0775 '/pgdata/pgbackrest/log' '/pgdata/pgbackrest' || :; }) || halt "$(permissions '/pgdata/pgbackrest/log' ||:)"; }
275+
[[ '/pgdata/patroni/log' != "${postgres_data_directory}"* || -f "${postgres_data_directory}/PG_VERSION" ]] &&
276+
{ (mkdir -p '/pgdata/patroni/log' && { chmod 0775 '/pgdata/patroni/log' '/pgdata/patroni' || :; }) || halt "$(permissions '/pgdata/patroni/log' ||:)"; }
277+
[[ '/pgdata/pg11/log' != "${postgres_data_directory}"* || -f "${postgres_data_directory}/PG_VERSION" ]] &&
278+
{ (mkdir -p '/pgdata/pg11/log' && { chmod 0775 '/pgdata/pg11/log' || :; }) || halt "$(permissions '/pgdata/pg11/log' ||:)"; }
279279
install -D --mode=0600 -t "/tmp/replication" "/pgconf/tls/replication"/{tls.crt,tls.key,ca.crt}
280280
281281

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /