Skip to content

Commit

Permalink
(PE-39215) Retreiving replica postgres from get_peadm_config - add_re…
Browse files Browse the repository at this point in the history
…plica

No longer requiring user to input replica postgres host and instead getting this from peadm config
  • Loading branch information
ragingra committed Oct 28, 2024
1 parent b07439a commit e3036c8
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 32 deletions.
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

0 comments on commit e3036c8

Please sign in to comment.