Skip to content

Commit

Permalink
Ensure pgBackRest log directories are writable
Browse files Browse the repository at this point in the history
The `install` command only sets permissions on the final directory.
  • Loading branch information
cbandy committed Feb 11, 2025
1 parent 877d79b commit 86ed388
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/pgbackrest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package pgbackrest
import (
"context"
"fmt"
"path"
"strconv"
"strings"
"time"
Expand All @@ -19,6 +20,7 @@ import (
"github.com/crunchydata/postgres-operator/internal/initialize"
"github.com/crunchydata/postgres-operator/internal/naming"
"github.com/crunchydata/postgres-operator/internal/postgres"
"github.com/crunchydata/postgres-operator/internal/shell"
"github.com/crunchydata/postgres-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
)

Expand Down Expand Up @@ -152,7 +154,9 @@ func MakePGBackrestLogDir(template *corev1.PodTemplateSpec,
}

container := corev1.Container{
Command: []string{"bash", "-c", "umask 000 && install -m 777 -d " + pgBackRestLogPath},
// TODO(log-rotation): The second argument here should be the path
// of the volume mount. Find a way to calculate that consistently.
Command: []string{"bash", "-c", shell.MakeDirectories(0o775, path.Dir(pgBackRestLogPath), pgBackRestLogPath)},
Image: config.PGBackRestContainerImage(cluster),
ImagePullPolicy: cluster.Spec.ImagePullPolicy,
Name: naming.ContainerPGBackRestLogDirInit,
Expand Down
2 changes: 1 addition & 1 deletion internal/pgbackrest/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func TestMakePGBackrestLogDir(t *testing.T) {
for _, c := range podTemplate.Spec.InitContainers {
if c.Name == naming.ContainerPGBackRestLogDirInit {
// ignore "bash -c", should skip repo with no volume
assert.Equal(t, "umask 000 && install -m 777 -d /pgbackrest/repo2/log", c.Command[2])
assert.Equal(t, `mkdir -p '/pgbackrest/repo2/log' && chmod 0775 '/pgbackrest/repo2/log'`, c.Command[2])
assert.Equal(t, c.Image, "test-image")
assert.Equal(t, c.ImagePullPolicy, corev1.PullAlways)
assert.Assert(t, !cmp.DeepEqual(c.SecurityContext,
Expand Down

0 comments on commit 86ed388

Please sign in to comment.