Skip to content

Commit 88130ca

Browse files
committed
Ensure pgBackRest log directories are writable
The `install` command only sets permissions on the final directory.
1 parent 951fa40 commit 88130ca

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

internal/pgbackrest/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package pgbackrest
77
import (
88
"context"
99
"fmt"
10+
"path"
1011
"strconv"
1112
"strings"
1213
"time"
@@ -19,6 +20,7 @@ import (
1920
"github.com/crunchydata/postgres-operator/internal/initialize"
2021
"github.com/crunchydata/postgres-operator/internal/naming"
2122
"github.com/crunchydata/postgres-operator/internal/postgres"
23+
"github.com/crunchydata/postgres-operator/internal/shell"
2224
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2325
)
2426

@@ -153,7 +155,9 @@ func MakePGBackrestLogDir(template *corev1.PodTemplateSpec,
153155
}
154156

155157
container := corev1.Container{
156-
Command: []string{"bash", "-c", "umask 000 && install -m 777 -d " + pgBackRestLogPath},
158+
// TODO(log-rotation): The second argument here should be the path
159+
// of the volume mount. Find a way to calculate that consistently.
160+
Command: []string{"bash", "-c", shell.MakeDirectories(0o775, path.Dir(pgBackRestLogPath), pgBackRestLogPath)},
157161
Image: config.PGBackRestContainerImage(cluster),
158162
ImagePullPolicy: cluster.Spec.ImagePullPolicy,
159163
Name: naming.ContainerPGBackRestLogDirInit,

internal/pgbackrest/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func TestMakePGBackrestLogDir(t *testing.T) {
292292
for _, c := range podTemplate.Spec.InitContainers {
293293
if c.Name == naming.ContainerPGBackRestLogDirInit {
294294
// ignore "bash -c", should skip repo with no volume
295-
assert.Equal(t, "umask 000 && install -m 777 -d /pgbackrest/repo2/log", c.Command[2])
295+
assert.Equal(t, `mkdir -p '/pgbackrest/repo2/log' && chmod 0775 '/pgbackrest/repo2/log'`, c.Command[2])
296296
assert.Equal(t, c.Image, "test-image")
297297
assert.Equal(t, c.ImagePullPolicy, corev1.PullAlways)
298298
assert.Assert(t, !cmp.DeepEqual(c.SecurityContext,

0 commit comments

Comments
 (0)