Skip to content

Commit

Permalink
feat: make the entrypoint of pgBackRest image configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
Keiji Hokamura committed Dec 7, 2022
1 parent da682a2 commit 86c8552
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ spec:
pgbackrest:
description: pgBackRest archive configuration
properties:
command:
description: The command for pgBackRest containers. If it's
ommit, "/opt/crunchy/bin/pgbackrest" is used as the default
one.
items:
type: string
type: array
configuration:
description: 'Projected volumes containing custom pgBackRest
configuration. These files are mounted under "/etc/pgbackrest/conf.d"
Expand Down
5 changes: 5 additions & 0 deletions docs/content/references/crd.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion internal/controller/postgrescluster/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ func generateBackupJobSpecIntent(postgresCluster *v1beta1.PostgresCluster,
cmdOpts = append(cmdOpts, opts...)

container := corev1.Container{
Command: []string{"/opt/crunchy/bin/pgbackrest"},
Env: []corev1.EnvVar{
{Name: "COMMAND", Value: "backup"},
{Name: "COMMAND_OPTS", Value: strings.Join(cmdOpts, " ")},
Expand All @@ -694,6 +693,12 @@ func generateBackupJobSpecIntent(postgresCluster *v1beta1.PostgresCluster,
SecurityContext: initialize.RestrictedSecurityContext(),
}

if postgresCluster.Spec.Backups.PGBackRest.Command != nil {
container.Command = postgresCluster.Spec.Backups.PGBackRest.Command
} else {
container.Command = []string{"/opt/crunchy/bin/pgbackrest"}
}

if postgresCluster.Spec.Backups.PGBackRest.Jobs != nil {
container.Resources = postgresCluster.Spec.Backups.PGBackRest.Jobs.Resources
}
Expand Down
13 changes: 13 additions & 0 deletions internal/controller/postgrescluster/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2715,6 +2715,19 @@ volumes:
}
})
})

t.Run("Command", func(t *testing.T) {
cmd := []string{"cmd", "blah"}
cluster := &v1beta1.PostgresCluster{}
cluster.Spec.Backups.PGBackRest.Command = cmd
job, err := generateBackupJobSpecIntent(
cluster, v1beta1.PGBackRestRepo{},
"",
nil, nil,
)
assert.NilError(t, err)
assert.DeepEqual(t, job.Template.Spec.Containers[0].Command, cmd)
})
}

func TestGenerateRepoHostIntent(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ type PGBackRestArchive struct {
// +optional
Image string `json:"image,omitempty"`

// The command for pgBackRest containers. If it's ommit, "/opt/crunchy/bin/pgbackrest" is
// used as the default one.
// +optional
Command []string `json:"command,omitempty"`

// Jobs field allows configuration for all backup jobs
// +optional
Jobs *BackupJobs `json:"jobs,omitempty"`
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 86c8552

Please sign in to comment.