Skip to content

K8SPG-704: Allow configuring create_replica_methods #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 6, 2025
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 @@ -14023,6 +14023,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13355,6 +13355,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13760,6 +13760,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13965,6 +13965,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
18 changes: 18 additions & 0 deletions deploy/bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14057,6 +14057,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down Expand Up @@ -39663,6 +39672,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
3 changes: 3 additions & 0 deletions deploy/cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ spec:
# max_worker_processes: 2
# shared_buffers: 1GB
# work_mem: 2MB
# createReplicaMethods:
# - pgbackrest
# - basebackup

# extensions:
# image: perconalab/percona-postgresql-operator:main
Expand Down
18 changes: 18 additions & 0 deletions deploy/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14057,6 +14057,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down Expand Up @@ -39663,6 +39672,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
18 changes: 18 additions & 0 deletions deploy/cw-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14057,6 +14057,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down Expand Up @@ -39663,6 +39672,15 @@ spec:
type: boolean
patroni:
properties:
createReplicaMethods:
description: CreateReplicaMethods allows overriding create_replica_methods
for all instances.
items:
enum:
- basebackup
- pgbackrest
type: string
type: array
dynamicConfiguration:
description: |-
Patroni dynamic configuration settings. Changes to this value will be
Expand Down
8 changes: 8 additions & 0 deletions internal/patroni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,14 @@ func instanceYAML(
methods = append([]string{pgBackRestCreateReplicaMethod}, methods...)
}

// K8SPG-704: Allow overriding create replica methods list
if cluster.Spec.Patroni != nil && len(cluster.Spec.Patroni.CreateReplicaMethods) > 0 {
methods = []string{}
for _, m := range cluster.Spec.Patroni.CreateReplicaMethods {
methods = append(methods, string(m))
}
}

Comment on lines +588 to +595
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend unit testing this function. In order to better manage the test in future upstream merges, maybe we can just add the following in

	cluster.Spec.Patroni.CreateReplicaMethods = []v1beta1.CreateReplicaMethod{"custom1", "custom2"}
	dataWithCustomMethods, err := instanceYAML(cluster, instance, nil)
	assert.NilError(t, err)
	assert.Equal(t, dataWithCustomMethods, strings.Trim(`
# Generated by postgres-operator. DO NOT EDIT.
# Your changes will not be saved.
bootstrap:
  initdb:
  - data-checksums
  - encoding=UTF8
  - waldir=/pgdata/pg12_wal
  - encryption-key-command=echo test
  method: initdb
kubernetes: {}
postgresql:
  basebackup:
  - waldir=/pgdata/pg12_wal
  create_replica_methods:
  - custom1
  - custom2
  pgpass: /tmp/.pgpass
  use_unix_socket: true
restapi: {}
tags: {}
	`, "\t\n")+"\n")
	

In func TestInstanceYAML(t *testing.T)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// NOTE(cbandy): Is there any chance a user might want to specify their own
// method? This is a list and cannot be merged.
postgresql["create_replica_methods"] = methods
Expand Down
26 changes: 26 additions & 0 deletions internal/patroni/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,32 @@ postgresql:
pgpass: /tmp/.pgpass
use_unix_socket: true
restapi: {}
tags: {}
`, "\t\n")+"\n")

cluster.Spec.Patroni.CreateReplicaMethods = []v1beta1.CreateReplicaMethod{"basebackup", "pgbackrest"}
dataWithCustomMethods, err := instanceYAML(cluster, instance, nil)
assert.NilError(t, err)
assert.Equal(t, dataWithCustomMethods, strings.Trim(`
# Generated by postgres-operator. DO NOT EDIT.
# Your changes will not be saved.
bootstrap:
initdb:
- data-checksums
- encoding=UTF8
- waldir=/pgdata/pg12_wal
- encryption-key-command=echo test
method: initdb
kubernetes: {}
postgresql:
basebackup:
- waldir=/pgdata/pg12_wal
create_replica_methods:
- basebackup
- pgbackrest
pgpass: /tmp/.pgpass
use_unix_socket: true
restapi: {}
tags: {}
`, "\t\n")+"\n")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ type PatroniSpec struct {
// +optional
Switchover *PatroniSwitchover `json:"switchover,omitempty"`

// CreateReplicaMethods allows overriding create_replica_methods for all instances.
// +optional
CreateReplicaMethods []CreateReplicaMethod `json:"createReplicaMethods,omitempty"`

// TODO(cbandy): Add UseConfigMaps bool, default false.
// TODO(cbandy): Allow other DCS: etcd, raft, etc?
// N.B. changing this will cause downtime.
// - https://patroni.readthedocs.io/en/latest/kubernetes.html
}

// +kubebuilder:validation:Enum={basebackup,pgbackrest}
type CreateReplicaMethod string

type PatroniSwitchover struct {

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

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

Loading