Skip to content

Commit 09d80bb

Browse files
mcdonaldseanpNeil Anderson
and
Neil Anderson
authored
(PE-39351) Update add_database plan to work with patching/HAC (#531)
* (PE-39351) Update add_database plan to work with patching/HAC This commit updates the add_database plan to include the pe-patching and pe-hac databases when it cleans up the original postgres on the primary. The add_database plan uses pg_basebackup to copy the entire contents of the postgres DB from the original primary DB to the new DB node's postgres. That process doesn't individually update a list of databases, so there's no context of "which DBs to move", because it just moves everything. However, during the cleanup process on the original DB That exists on the primary, the plan _does_ need to list the individual internal postgres dbs that need to be deleted. * Updating reference.md * Fixing lint --------- Co-authored-by: Neil Anderson <[email protected]>
1 parent 1d53909 commit 09d80bb

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

REFERENCE.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* [`peadm::migration_opts_default`](#peadm--migration_opts_default)
3636
* [`peadm::node_manager_yaml_location`](#peadm--node_manager_yaml_location)
3737
* [`peadm::oid`](#peadm--oid)
38+
* [`peadm::pe_db_names`](#peadm--pe_db_names)
3839
* [`peadm::plan_step`](#peadm--plan_step)
3940
* [`peadm::recovery_opts_all`](#peadm--recovery_opts_all)
4041
* [`peadm::recovery_opts_default`](#peadm--recovery_opts_default)
@@ -823,6 +824,24 @@ Data type: `String`
823824

824825

825826

827+
### <a name="peadm--pe_db_names"></a>`peadm::pe_db_names`
828+
829+
Type: Puppet Language
830+
831+
The peadm::pe_db_names function.
832+
833+
#### `peadm::pe_db_names(String $pe_ver)`
834+
835+
The peadm::pe_db_names function.
836+
837+
Returns: `Array`
838+
839+
##### `pe_ver`
840+
841+
Data type: `String`
842+
843+
844+
826845
### <a name="peadm--plan_step"></a>`peadm::plan_step`
827846

828847
Type: Ruby 4.x API

functions/pe_db_names.pp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function peadm::pe_db_names (
2+
String $pe_ver,
3+
) >> Array {
4+
$original_db_names = [
5+
'pe-activity',
6+
'pe-classifier',
7+
'pe-inventory',
8+
'pe-orchestrator',
9+
'pe-rbac',
10+
]
11+
12+
$pe_2025_or_later = SemVerRange('>= 2025.0.0')
13+
$pe_2023_8_or_later = SemVerRange('>= 2023.8.0')
14+
15+
case $pe_ver {
16+
# The patching service was added in 2025.0.0
17+
$pe_2025_or_later: {
18+
$original_db_names + [
19+
'pe-hac',
20+
'pe-patching',
21+
]
22+
}
23+
24+
# The host-action-collector (hac) was added in 2023.8
25+
$pe_2023_8_or_later: {
26+
$original_db_names + ['pe-hac']
27+
}
28+
29+
default: {
30+
$original_db_names
31+
}
32+
}
33+
}

plans/add_database.pp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# Get current peadm config before making modifications and shutting down
1919
# PuppetDB
2020
$peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value
21+
$pe_ver = $peadm_config['pe_version']
2122

2223
$compilers = $peadm_config['params']['compilers']
2324

@@ -41,7 +42,7 @@
4142
$operating_mode = $mode
4243
out::message("Operating mode overridden by parameter mode set to ${mode}")
4344
} else {
44-
# If array is empty then no external databases were previously configured
45+
# If array is empty then no external databases were previously configured
4546
$no_external_db = peadm::flatten_compact([
4647
$postgresql_a_host,
4748
$postgresql_b_host,
@@ -87,7 +88,7 @@
8788

8889
peadm::plan_step('init-db-node') || {
8990
# Install PSQL on new node to be used as external PuppetDB backend by using
90-
# puppet in lieu of installer
91+
# puppet in lieu of installer
9192
run_plan('peadm::subplans::component_install', $postgresql_target,
9293
primary_host => $primary_target,
9394
avail_group_letter => $avail_group_letter,
@@ -162,16 +163,10 @@
162163
if $operating_mode == 'init' {
163164
# Clean up old puppetdb database on primary and those which were copied to
164165
# new host.
165-
$target_db_purge = [
166-
'pe-activity',
167-
'pe-classifier',
168-
'pe-inventory',
169-
'pe-orchestrator',
170-
'pe-rbac',
171-
]
166+
$target_db_purge = peadm::pe_db_names($pe_ver)
172167

173168
# If a primary replica exists then pglogical is enabled and will prevent
174-
# the clean up of databases on our target because it opens a connection.
169+
# the clean up of databases on our target because it opens a connection.
175170
if $replica_host {
176171
run_plan('peadm::util::db_disable_pglogical', $postgresql_target, databases => $target_db_purge)
177172
}

0 commit comments

Comments
 (0)