Skip to content

Commit 00f008f

Browse files
committed
K8SPG-615: Add initialDelaySeconds for backups
1 parent a2dbe30 commit 00f008f

12 files changed

Lines changed: 235 additions & 0 deletions

File tree

build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1956,6 +1956,13 @@ spec:
19561956
description: Defines details for manual pgBackRest backup
19571957
Jobs
19581958
properties:
1959+
initialDelaySeconds:
1960+
description: |-
1961+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
1962+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
1963+
before initiating the backup process.
1964+
format: int64
1965+
type: integer
19591966
options:
19601967
description: |-
19611968
Command line options to include when running the pgBackRest backup command.

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,13 @@ spec:
21122112
description: Defines details for manual pgBackRest backup
21132113
Jobs
21142114
properties:
2115+
initialDelaySeconds:
2116+
description: |-
2117+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
2118+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
2119+
before initiating the backup process.
2120+
format: int64
2121+
type: integer
21152122
options:
21162123
description: |-
21172124
Command line options to include when running the pgBackRest backup command.

cmd/pgbackrest/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"strconv"
2626
"strings"
2727
"syscall"
28+
"time"
2829

2930
log "github.com/sirupsen/logrus"
3031
corev1 "k8s.io/api/core/v1"
@@ -79,6 +80,16 @@ func main() {
7980
}
8081
log.Infof("debug flag set to %t", debugFlag)
8182

83+
if delay, found := os.LookupEnv("INITIAL_DELAY_SECS"); found {
84+
delaySecs, err := strconv.ParseInt(delay, 10, 64)
85+
if err != nil {
86+
panic(err)
87+
}
88+
89+
log.Infof("sleeping for %d seconds", delaySecs)
90+
time.Sleep(time.Duration(delaySecs) * time.Second)
91+
}
92+
8293
config, err := NewConfig()
8394
if err != nil {
8495
panic(err)

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2517,6 +2517,13 @@ spec:
25172517
description: Defines details for manual pgBackRest backup
25182518
Jobs
25192519
properties:
2520+
initialDelaySeconds:
2521+
description: |-
2522+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
2523+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
2524+
before initiating the backup process.
2525+
format: int64
2526+
type: integer
25202527
options:
25212528
description: |-
25222529
Command line options to include when running the pgBackRest backup command.

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,6 +1948,13 @@ spec:
19481948
description: Defines details for manual pgBackRest backup
19491949
Jobs
19501950
properties:
1951+
initialDelaySeconds:
1952+
description: |-
1953+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
1954+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
1955+
before initiating the backup process.
1956+
format: int64
1957+
type: integer
19511958
options:
19521959
description: |-
19531960
Command line options to include when running the pgBackRest backup command.

deploy/bundle.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,13 @@ spec:
28142814
description: Defines details for manual pgBackRest backup
28152815
Jobs
28162816
properties:
2817+
initialDelaySeconds:
2818+
description: |-
2819+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
2820+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
2821+
before initiating the backup process.
2822+
format: int64
2823+
type: integer
28172824
options:
28182825
description: |-
28192826
Command line options to include when running the pgBackRest backup command.
@@ -28436,6 +28443,13 @@ spec:
2843628443
description: Defines details for manual pgBackRest backup
2843728444
Jobs
2843828445
properties:
28446+
initialDelaySeconds:
28447+
description: |-
28448+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
28449+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
28450+
before initiating the backup process.
28451+
format: int64
28452+
type: integer
2843928453
options:
2844028454
description: |-
2844128455
Command line options to include when running the pgBackRest backup command.

deploy/cr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ spec:
509509
repoName: repo1
510510
options:
511511
- --type=full
512+
# initialDelaySeconds: 120
512513
repos:
513514
- name: repo1
514515
schedules:

deploy/crd.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,13 @@ spec:
28142814
description: Defines details for manual pgBackRest backup
28152815
Jobs
28162816
properties:
2817+
initialDelaySeconds:
2818+
description: |-
2819+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
2820+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
2821+
before initiating the backup process.
2822+
format: int64
2823+
type: integer
28172824
options:
28182825
description: |-
28192826
Command line options to include when running the pgBackRest backup command.
@@ -28436,6 +28443,13 @@ spec:
2843628443
description: Defines details for manual pgBackRest backup
2843728444
Jobs
2843828445
properties:
28446+
initialDelaySeconds:
28447+
description: |-
28448+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
28449+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
28450+
before initiating the backup process.
28451+
format: int64
28452+
type: integer
2843928453
options:
2844028454
description: |-
2844128455
Command line options to include when running the pgBackRest backup command.

deploy/cw-bundle.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2814,6 +2814,13 @@ spec:
28142814
description: Defines details for manual pgBackRest backup
28152815
Jobs
28162816
properties:
2817+
initialDelaySeconds:
2818+
description: |-
2819+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
2820+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
2821+
before initiating the backup process.
2822+
format: int64
2823+
type: integer
28172824
options:
28182825
description: |-
28192826
Command line options to include when running the pgBackRest backup command.
@@ -28436,6 +28443,13 @@ spec:
2843628443
description: Defines details for manual pgBackRest backup
2843728444
Jobs
2843828445
properties:
28446+
initialDelaySeconds:
28447+
description: |-
28448+
InitialDelaySeconds defines the number of seconds to wait before starting the backup.
28449+
After the backup pod is scheduled, its entrypoint will wait for this number of seconds
28450+
before initiating the backup process.
28451+
format: int64
28452+
type: integer
2843928453
options:
2844028454
description: |-
2844128455
Command line options to include when running the pgBackRest backup command.

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"reflect"
1212
"regexp"
1313
"sort"
14+
"strconv"
1415
"strings"
1516
"time"
1617

@@ -861,6 +862,14 @@ func generateBackupJobSpecIntent(ctx context.Context, postgresCluster *v1beta1.P
861862
}
862863
}
863864

865+
// K8SPG-615
866+
if manual := postgresCluster.Spec.Backups.PGBackRest.Manual; postgresCluster.CompareVersion("2.7.0") >= 0 && manual != nil && manual.InitialDelaySeconds != 0 {
867+
container.Env = append(container.Env, corev1.EnvVar{
868+
Name: "INITIAL_DELAY_SECS",
869+
Value: strconv.FormatInt(manual.InitialDelaySeconds, 10),
870+
})
871+
}
872+
864873
jobSpec := &batchv1.JobSpec{
865874
Template: corev1.PodTemplateSpec{
866875
ObjectMeta: metav1.ObjectMeta{Labels: labels, Annotations: annotations},

0 commit comments

Comments
 (0)