Skip to content

(PE-39215) Retrieving replica postgres from get_peadm_config - add_replica #520

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 0 additions & 10 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,6 @@ The following parameters are available in the `peadm::add_replica` plan:

* [`primary_host`](#-peadm--add_replica--primary_host)
* [`replica_host`](#-peadm--add_replica--replica_host)
* [`replica_postgresql_host`](#-peadm--add_replica--replica_postgresql_host)
* [`token_file`](#-peadm--add_replica--token_file)

##### <a name="-peadm--add_replica--primary_host"></a>`primary_host`
Expand All @@ -1803,15 +1802,6 @@ Data type: `Peadm::SingleTargetSpec`

- The hostname and certname of the replica VM

##### <a name="-peadm--add_replica--replica_postgresql_host"></a>`replica_postgresql_host`

Data type: `Optional[Peadm::SingleTargetSpec]`

- The hostname and certname of the host with the replica PE-PosgreSQL database.
Can be a separate host in an XL architecture, or undef in Standard or Large.

Default value: `undef`

##### <a name="-peadm--add_replica--token_file"></a>`token_file`

Data type: `Optional[String]`
Expand Down
6 changes: 0 additions & 6 deletions documentation/add_replica.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,6 @@ The plan performs the following steps:
- **Description:**
The hostname and certname of the replica VM.

### `primary_postgresql_host`

- **Type:** `Optional[Peadm::SingleTargetSpec]`
- **Description:**
The target specification for the primary PostgreSQL host that the new replica will synchronize with. This is the database server from which the replica will replicate data.

### `token_file`

- **Type:** `Optional[String]`
Expand Down
3 changes: 1 addition & 2 deletions documentation/automated_recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Manual procedures are documented in [recovery.md](recovery.md)
This procedure uses the following placeholder references.

* _\<primary-server-fqdn\>_ - The FQDN and certname of the primary Puppet server
* _\<replica-postgres-server-fqdn\>_ - The FQDN and certname of the PE-PostgreSQL server which resides in the same availability group as the replacement replica Puppet server
* _\<replacement-replica-fqdn\>_ - The FQDN and certname of the replacement replica Puppet server

1. Run `peadm::add_replica` plan to deploy replacement replica Puppet server
Expand All @@ -24,7 +23,7 @@ This procedure uses the following placeholder references.

2. For Extra Large deployments

bolt plan run peadm::add_replica primary_host=<primary-server-fqdn> replica_host=<replacement-replica-fqdn> replica_postgresql_host=<replica-postgres-server-fqdn>
bolt plan run peadm::add_replica primary_host=<primary-server-fqdn> replica_host=<replacement-replica-fqdn>

## Replace failed PE-PostgreSQL server (A or B side)

Expand Down
16 changes: 6 additions & 10 deletions plans/add_replica.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,34 @@
# 2: The existing replica is broken, we have a fresh new VM we want to provision the replica to.
# @param primary_host - The hostname and certname of the primary Puppet server
# @param replica_host - The hostname and certname of the replica VM
# @param replica_postgresql_host - The hostname and certname of the host with the replica PE-PosgreSQL database.
# Can be a separate host in an XL architecture, or undef in Standard or Large.
# @param token_file - (optional) the token file in a different location than the default.
plan peadm::add_replica(
# Standard or Large
Peadm::SingleTargetSpec $primary_host,
Peadm::SingleTargetSpec $replica_host,

# Extra Large
Optional[Peadm::SingleTargetSpec] $replica_postgresql_host = undef,

# Common Configuration
Optional[String] $token_file = undef,
) {
$primary_target = peadm::get_targets($primary_host, 1)
$replica_target = peadm::get_targets($replica_host, 1)
$replica_postgresql_target = peadm::get_targets($replica_postgresql_host, 1)

$code_manager_enabled = run_task('peadm::code_manager_enabled', $primary_target).first.value['code_manager_enabled']

if $code_manager_enabled == false {
fail('Code Manager must be enabled to add a replica. Please refer to the docs for more information on enabling Code Manager.')
}

# Get current peadm config to ensure we forget active replicas
$peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value

$replica_postgresql_target = $peadm_config['params']['replica_postgresql_host']

run_command('systemctl stop puppet.service', peadm::flatten_compact([
$primary_target,
$replica_postgresql_target,
]))

# Get current peadm config to ensure we forget active replicas
$peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value

# Make list of all possible replicas, configured and provided
$replicas = peadm::flatten_compact([
$replica_host,
Expand Down Expand Up @@ -65,7 +61,7 @@
# Wrap these things that operate on replica_postgresql_target in an if statement
# to avoid failures retrieving PSQL version because you can't operate functions
# on a return value of nil.
if $replica_postgresql_host {
if $replica_postgresql_target {
# On the PE-PostgreSQL server in the <replacement-avail-group-letter> group
$psql_version = run_task('peadm::get_psql_version', $replica_postgresql_target).first.value['version']

Expand Down
2 changes: 0 additions & 2 deletions spec/acceptance/peadm_spec/plans/add_replica.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

$primary_host = $t.filter |$n| { $n.vars['role'] == 'primary' }
$replica_host = $t.filter |$n| { $n.vars['role'] == 'spare-replica' }
$replica_postgresql_host = $t.filter |$n| { $n.vars['role'] == 'replica-pdb-postgresql' }

if $replica_host == [] {
fail_plan('"replica" role missing from inventory, cannot continue')
Expand All @@ -19,6 +18,5 @@
run_plan('peadm::add_replica',
primary_host => $primary_host,
replica_host => $replica_host,
replica_postgresql_host => $replica_postgresql_host ? { [] => undef, default => $replica_postgresql_host },
)
}
2 changes: 0 additions & 2 deletions spec/acceptance/peadm_spec/plans/perform_failover.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
out::message("Active nodes 2: ${res2.first['stdout']}")

# add new replica
$replica_postgresql_host = $t.filter |$n| { $n.vars['role'] == 'primary-pdb-postgresql' }[0]
$new_replica_host = $t.filter |$n| { $n.vars['role'] == 'spare-replica' }[0]

if $new_replica_host == [] {
Expand All @@ -76,7 +75,6 @@
run_plan('peadm::add_replica',
primary_host => $replica_host.uri,
replica_host => $new_replica_host.uri,
replica_postgresql_host => $replica_postgresql_host ? {[] => undef, default => $replica_postgresql_host.uri },
)

$res3 = run_command("/opt/puppetlabs/bin/puppet query \'${query}\'", $replica_host)
Expand Down
Loading