Skip to content

Commit 677d96a

Browse files
egeguneshors
andauthored
K8SPG-704: Allow configuring create_replica_methods (#1110)
* K8SPG-704: Allow configuring create_replica_methods * add test case --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 57b8fbe commit 677d96a

12 files changed

+139
-0
lines changed

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

+9
Original file line numberDiff line numberDiff line change
@@ -14023,6 +14023,15 @@ spec:
1402314023
type: boolean
1402414024
patroni:
1402514025
properties:
14026+
createReplicaMethods:
14027+
description: CreateReplicaMethods allows overriding create_replica_methods
14028+
for all instances.
14029+
items:
14030+
enum:
14031+
- basebackup
14032+
- pgbackrest
14033+
type: string
14034+
type: array
1402614035
dynamicConfiguration:
1402714036
description: |-
1402814037
Patroni dynamic configuration settings. Changes to this value will be

Diff for: build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -13355,6 +13355,15 @@ spec:
1335513355
type: boolean
1335613356
patroni:
1335713357
properties:
13358+
createReplicaMethods:
13359+
description: CreateReplicaMethods allows overriding create_replica_methods
13360+
for all instances.
13361+
items:
13362+
enum:
13363+
- basebackup
13364+
- pgbackrest
13365+
type: string
13366+
type: array
1335813367
dynamicConfiguration:
1335913368
description: |-
1336013369
Patroni dynamic configuration settings. Changes to this value will be

Diff for: config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -13760,6 +13760,15 @@ spec:
1376013760
type: boolean
1376113761
patroni:
1376213762
properties:
13763+
createReplicaMethods:
13764+
description: CreateReplicaMethods allows overriding create_replica_methods
13765+
for all instances.
13766+
items:
13767+
enum:
13768+
- basebackup
13769+
- pgbackrest
13770+
type: string
13771+
type: array
1376313772
dynamicConfiguration:
1376413773
description: |-
1376513774
Patroni dynamic configuration settings. Changes to this value will be

Diff for: config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -13965,6 +13965,15 @@ spec:
1396513965
type: boolean
1396613966
patroni:
1396713967
properties:
13968+
createReplicaMethods:
13969+
description: CreateReplicaMethods allows overriding create_replica_methods
13970+
for all instances.
13971+
items:
13972+
enum:
13973+
- basebackup
13974+
- pgbackrest
13975+
type: string
13976+
type: array
1396813977
dynamicConfiguration:
1396913978
description: |-
1397013979
Patroni dynamic configuration settings. Changes to this value will be

Diff for: deploy/bundle.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -14057,6 +14057,15 @@ spec:
1405714057
type: boolean
1405814058
patroni:
1405914059
properties:
14060+
createReplicaMethods:
14061+
description: CreateReplicaMethods allows overriding create_replica_methods
14062+
for all instances.
14063+
items:
14064+
enum:
14065+
- basebackup
14066+
- pgbackrest
14067+
type: string
14068+
type: array
1406014069
dynamicConfiguration:
1406114070
description: |-
1406214071
Patroni dynamic configuration settings. Changes to this value will be
@@ -39663,6 +39672,15 @@ spec:
3966339672
type: boolean
3966439673
patroni:
3966539674
properties:
39675+
createReplicaMethods:
39676+
description: CreateReplicaMethods allows overriding create_replica_methods
39677+
for all instances.
39678+
items:
39679+
enum:
39680+
- basebackup
39681+
- pgbackrest
39682+
type: string
39683+
type: array
3966639684
dynamicConfiguration:
3966739685
description: |-
3966839686
Patroni dynamic configuration settings. Changes to this value will be

Diff for: deploy/cr.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ spec:
495495
# max_worker_processes: 2
496496
# shared_buffers: 1GB
497497
# work_mem: 2MB
498+
# createReplicaMethods:
499+
# - pgbackrest
500+
# - basebackup
498501

499502
# extensions:
500503
# image: perconalab/percona-postgresql-operator:main

Diff for: deploy/crd.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -14057,6 +14057,15 @@ spec:
1405714057
type: boolean
1405814058
patroni:
1405914059
properties:
14060+
createReplicaMethods:
14061+
description: CreateReplicaMethods allows overriding create_replica_methods
14062+
for all instances.
14063+
items:
14064+
enum:
14065+
- basebackup
14066+
- pgbackrest
14067+
type: string
14068+
type: array
1406014069
dynamicConfiguration:
1406114070
description: |-
1406214071
Patroni dynamic configuration settings. Changes to this value will be
@@ -39663,6 +39672,15 @@ spec:
3966339672
type: boolean
3966439673
patroni:
3966539674
properties:
39675+
createReplicaMethods:
39676+
description: CreateReplicaMethods allows overriding create_replica_methods
39677+
for all instances.
39678+
items:
39679+
enum:
39680+
- basebackup
39681+
- pgbackrest
39682+
type: string
39683+
type: array
3966639684
dynamicConfiguration:
3966739685
description: |-
3966839686
Patroni dynamic configuration settings. Changes to this value will be

Diff for: deploy/cw-bundle.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -14057,6 +14057,15 @@ spec:
1405714057
type: boolean
1405814058
patroni:
1405914059
properties:
14060+
createReplicaMethods:
14061+
description: CreateReplicaMethods allows overriding create_replica_methods
14062+
for all instances.
14063+
items:
14064+
enum:
14065+
- basebackup
14066+
- pgbackrest
14067+
type: string
14068+
type: array
1406014069
dynamicConfiguration:
1406114070
description: |-
1406214071
Patroni dynamic configuration settings. Changes to this value will be
@@ -39663,6 +39672,15 @@ spec:
3966339672
type: boolean
3966439673
patroni:
3966539674
properties:
39675+
createReplicaMethods:
39676+
description: CreateReplicaMethods allows overriding create_replica_methods
39677+
for all instances.
39678+
items:
39679+
enum:
39680+
- basebackup
39681+
- pgbackrest
39682+
type: string
39683+
type: array
3966639684
dynamicConfiguration:
3966739685
description: |-
3966839686
Patroni dynamic configuration settings. Changes to this value will be

Diff for: internal/patroni/config.go

+8
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,14 @@ func instanceYAML(
585585
methods = append([]string{pgBackRestCreateReplicaMethod}, methods...)
586586
}
587587

588+
// K8SPG-704: Allow overriding create replica methods list
589+
if cluster.Spec.Patroni != nil && len(cluster.Spec.Patroni.CreateReplicaMethods) > 0 {
590+
methods = []string{}
591+
for _, m := range cluster.Spec.Patroni.CreateReplicaMethods {
592+
methods = append(methods, string(m))
593+
}
594+
}
595+
588596
// NOTE(cbandy): Is there any chance a user might want to specify their own
589597
// method? This is a list and cannot be merged.
590598
postgresql["create_replica_methods"] = methods

Diff for: internal/patroni/config_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,32 @@ postgresql:
976976
pgpass: /tmp/.pgpass
977977
use_unix_socket: true
978978
restapi: {}
979+
tags: {}
980+
`, "\t\n")+"\n")
981+
982+
cluster.Spec.Patroni.CreateReplicaMethods = []v1beta1.CreateReplicaMethod{"basebackup", "pgbackrest"}
983+
dataWithCustomMethods, err := instanceYAML(cluster, instance, nil)
984+
assert.NilError(t, err)
985+
assert.Equal(t, dataWithCustomMethods, strings.Trim(`
986+
# Generated by postgres-operator. DO NOT EDIT.
987+
# Your changes will not be saved.
988+
bootstrap:
989+
initdb:
990+
- data-checksums
991+
- encoding=UTF8
992+
- waldir=/pgdata/pg12_wal
993+
- encryption-key-command=echo test
994+
method: initdb
995+
kubernetes: {}
996+
postgresql:
997+
basebackup:
998+
- waldir=/pgdata/pg12_wal
999+
create_replica_methods:
1000+
- basebackup
1001+
- pgbackrest
1002+
pgpass: /tmp/.pgpass
1003+
use_unix_socket: true
1004+
restapi: {}
9791005
tags: {}
9801006
`, "\t\n")+"\n")
9811007
}

Diff for: pkg/apis/postgres-operator.crunchydata.com/v1beta1/patroni_types.go

+7
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ type PatroniSpec struct {
4242
// +optional
4343
Switchover *PatroniSwitchover `json:"switchover,omitempty"`
4444

45+
// CreateReplicaMethods allows overriding create_replica_methods for all instances.
46+
// +optional
47+
CreateReplicaMethods []CreateReplicaMethod `json:"createReplicaMethods,omitempty"`
48+
4549
// TODO(cbandy): Add UseConfigMaps bool, default false.
4650
// TODO(cbandy): Allow other DCS: etcd, raft, etc?
4751
// N.B. changing this will cause downtime.
4852
// - https://patroni.readthedocs.io/en/latest/kubernetes.html
4953
}
5054

55+
// +kubebuilder:validation:Enum={basebackup,pgbackrest}
56+
type CreateReplicaMethod string
57+
5158
type PatroniSwitchover struct {
5259

5360
// Whether or not the operator should allow switchovers in a PostgresCluster

Diff for: pkg/apis/postgres-operator.crunchydata.com/v1beta1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)