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 8, 2022
1 parent da682a2 commit c95d8be
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ spec:
pgbackrest:
description: pgBackRest archive configuration
properties:
command:
description: The command for pgBackRest containers. The default
is "/opt/crunchy/bin/pgbackrest".
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,10 @@ type PGBackRestArchive struct {
// +optional
Image string `json:"image,omitempty"`

// The command for pgBackRest containers. The default is "/opt/crunchy/bin/pgbackrest".
// +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 c95d8be

Please sign in to comment.