Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2114,6 +2114,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
11 changes: 11 additions & 0 deletions cmd/pgbackrest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"
"strings"
"syscall"
"time"

log "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -78,6 +79,16 @@ func main() {
}
log.Infof("debug flag set to %t", debugFlag)

if delay, found := os.LookupEnv("INITIAL_DELAY_SECS"); found {
delaySecs, err := strconv.ParseInt(delay, 10, 64)
if err != nil {
panic(err)
}

log.Infof("sleeping for %d seconds", delaySecs)
time.Sleep(time.Duration(delaySecs) * time.Second)
}

config, err := NewConfig()
if err != nil {
panic(err)
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
14 changes: 14 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down Expand Up @@ -28447,6 +28454,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
1 change: 1 addition & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ spec:
repoName: repo1
options:
- --type=full
# initialDelaySeconds: 120
repos:
- name: repo1
schedules:
Expand Down
14 changes: 14 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down Expand Up @@ -28447,6 +28454,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
14 changes: 14 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down Expand Up @@ -28447,6 +28454,13 @@ spec:
description: Defines details for manual pgBackRest backup
Jobs
properties:
initialDelaySeconds:
description: |-
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
before initiating the backup process.
format: int64
type: integer
options:
description: |-
Command line options to include when running the pgBackRest backup command.
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/postgrescluster/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"reflect"
"regexp"
"sort"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -860,6 +861,14 @@ func generateBackupJobSpecIntent(ctx context.Context, postgresCluster *v1beta1.P
}
}

// K8SPG-615
if m := postgresCluster.Spec.Backups.PGBackRest.Manual; postgresCluster.CompareVersion("2.7.0") >= 0 && m != nil && m.InitialDelaySeconds != 0 {
container.Env = append(container.Env, corev1.EnvVar{
Name: "INITIAL_DELAY_SECS",
Value: strconv.FormatInt(m.InitialDelaySeconds, 10),
})
}

if postgresCluster.CompareVersion("2.7.0") >= 0 {
if annotations != nil {
annotations[naming.DefaultContainerAnnotation] = naming.PGBackRestRepoContainerName
Expand Down
138 changes: 138 additions & 0 deletions internal/controller/postgrescluster/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,144 @@ volumes:
}
})
})

t.Run("InitialDelaySeconds", func(t *testing.T) {
t.Run("<2.7.0", func(t *testing.T) {
cluster := &v1beta1.PostgresCluster{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
naming.LabelVersion: "2.6.0",
},
},
Spec: v1beta1.PostgresClusterSpec{
Backups: v1beta1.Backups{
PGBackRest: v1beta1.PGBackRestArchive{
Manual: &v1beta1.PGBackRestManualBackup{
InitialDelaySeconds: 30,
},
},
},
},
}
job := generateBackupJobSpecIntent(ctx,
cluster, v1beta1.PGBackRestRepo{},
"", "",
nil, nil,
)

container := job.Template.Spec.Containers[0]

var envVarFound bool
for _, env := range container.Env {
if env.Name == "INITIAL_DELAY_SECS" {
envVarFound = true
}
}

assert.Check(t, envVarFound == false)
})

t.Run(">=2.7.0", func(t *testing.T) {
cluster := &v1beta1.PostgresCluster{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
naming.LabelVersion: "2.7.0",
},
},
Spec: v1beta1.PostgresClusterSpec{
Backups: v1beta1.Backups{
PGBackRest: v1beta1.PGBackRestArchive{
Manual: &v1beta1.PGBackRestManualBackup{
InitialDelaySeconds: 30,
},
},
},
},
}
job := generateBackupJobSpecIntent(ctx,
cluster, v1beta1.PGBackRestRepo{},
"", "",
nil, nil,
)

container := job.Template.Spec.Containers[0]

var envVar corev1.EnvVar
for _, env := range container.Env {
if env.Name == "INITIAL_DELAY_SECS" {
envVar = env
}
}

if assert.Check(t, envVar.Name == "INITIAL_DELAY_SECS") {
assert.Equal(t, envVar.Value, "30")
}
})

t.Run("NoManual", func(t *testing.T) {
cluster := &v1beta1.PostgresCluster{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
naming.LabelVersion: "2.7.0",
},
},
Spec: v1beta1.PostgresClusterSpec{
Backups: v1beta1.Backups{
PGBackRest: v1beta1.PGBackRestArchive{},
},
},
}
job := generateBackupJobSpecIntent(ctx,
cluster, v1beta1.PGBackRestRepo{},
"", "",
nil, nil,
)

container := job.Template.Spec.Containers[0]

var envVarFound bool
for _, env := range container.Env {
if env.Name == "INITIAL_DELAY_SECS" {
envVarFound = true
}
}

assert.Check(t, envVarFound == false)
})

t.Run("EmptyValue", func(t *testing.T) {
cluster := &v1beta1.PostgresCluster{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
naming.LabelVersion: "2.7.0",
},
},
Spec: v1beta1.PostgresClusterSpec{
Backups: v1beta1.Backups{
PGBackRest: v1beta1.PGBackRestArchive{
Manual: &v1beta1.PGBackRestManualBackup{},
},
},
},
}
job := generateBackupJobSpecIntent(ctx,
cluster, v1beta1.PGBackRestRepo{},
"", "",
nil, nil,
)

container := job.Template.Spec.Containers[0]

var envVarFound bool
for _, env := range container.Env {
if env.Name == "INITIAL_DELAY_SECS" {
envVarFound = true
}
}

assert.Check(t, envVarFound == false)
})
})
}

func TestGenerateRepoHostIntent(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@ type PGBackRestManualBackup struct {
// https://pgbackrest.org/command.html#command-backup
// +optional
Options []string `json:"options,omitempty"`

// InitialDelaySeconds defines the number of seconds to wait before starting the backup.
// After the backup pod is scheduled, its entrypoint will wait for this number of seconds
// before initiating the backup process.
// +optional
InitialDelaySeconds int64 `json:"initialDelaySeconds,omitempty"`
}

// PGBackRestRepoHost represents a pgBackRest dedicated repository host
Expand Down
Loading