From d26e05995c45228a9eaa9e247f10d23ff64ce4ba Mon Sep 17 00:00:00 2001 From: "Sean P. McDonald" Date: Wed, 11 Dec 2024 15:14:49 -0600 Subject: [PATCH 1/3] (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. --- functions/pe_db_names.pp | 29 +++++++++++++++++++++++++++++ plans/add_database.pp | 15 +++++---------- 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 functions/pe_db_names.pp diff --git a/functions/pe_db_names.pp b/functions/pe_db_names.pp new file mode 100644 index 000000000..d2db5ed17 --- /dev/null +++ b/functions/pe_db_names.pp @@ -0,0 +1,29 @@ +function peadm::pe_db_names ( + String $pe_ver, +) >> Array { + $original_db_names = [ + 'pe-activity', + 'pe-classifier', + 'pe-inventory', + 'pe-orchestrator', + 'pe-rbac', + ] + case $pe_ver { + # The patching service was added in 2025.0.0 + SemVerRange('>= 2025.0.0'): { + $original_db_names + [ + 'pe-hac', + 'pe-patching', + ] + } + + # The host-action-collector (hac) was added in 2023.8 + SemVerRange('>= 2023.8.0'): { + $original_db_names + [ 'pe-hac' ] + } + + default: { + $original_db_names + } + } +} diff --git a/plans/add_database.pp b/plans/add_database.pp index 6219bde85..72860bba9 100644 --- a/plans/add_database.pp +++ b/plans/add_database.pp @@ -18,6 +18,7 @@ # Get current peadm config before making modifications and shutting down # PuppetDB $peadm_config = run_task('peadm::get_peadm_config', $primary_target).first.value + $pe_ver = $peadm_config['pe_version'] $compilers = $peadm_config['params']['compilers'] @@ -41,7 +42,7 @@ $operating_mode = $mode out::message("Operating mode overridden by parameter mode set to ${mode}") } else { - # If array is empty then no external databases were previously configured + # If array is empty then no external databases were previously configured $no_external_db = peadm::flatten_compact([ $postgresql_a_host, $postgresql_b_host, @@ -87,7 +88,7 @@ peadm::plan_step('init-db-node') || { # Install PSQL on new node to be used as external PuppetDB backend by using - # puppet in lieu of installer + # puppet in lieu of installer run_plan('peadm::subplans::component_install', $postgresql_target, primary_host => $primary_target, avail_group_letter => $avail_group_letter, @@ -162,16 +163,10 @@ if $operating_mode == 'init' { # Clean up old puppetdb database on primary and those which were copied to # new host. - $target_db_purge = [ - 'pe-activity', - 'pe-classifier', - 'pe-inventory', - 'pe-orchestrator', - 'pe-rbac', - ] + $target_db_purge = peadm::pe_db_names($pe_ver) # If a primary replica exists then pglogical is enabled and will prevent - # the clean up of databases on our target because it opens a connection. + # the clean up of databases on our target because it opens a connection. if $replica_host { run_plan('peadm::util::db_disable_pglogical', $postgresql_target, databases => $target_db_purge) } From 8b2e7ebcaa2ea9a8bc757ce7e451b1de00cfd062 Mon Sep 17 00:00:00 2001 From: Neil Anderson Date: Fri, 13 Dec 2024 11:17:14 +0000 Subject: [PATCH 2/3] Updating reference.md --- REFERENCE.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/REFERENCE.md b/REFERENCE.md index 2951060f1..526c843ce 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -35,6 +35,7 @@ * [`peadm::migration_opts_default`](#peadm--migration_opts_default) * [`peadm::node_manager_yaml_location`](#peadm--node_manager_yaml_location) * [`peadm::oid`](#peadm--oid) +* [`peadm::pe_db_names`](#peadm--pe_db_names) * [`peadm::plan_step`](#peadm--plan_step) * [`peadm::recovery_opts_all`](#peadm--recovery_opts_all) * [`peadm::recovery_opts_default`](#peadm--recovery_opts_default) @@ -823,6 +824,24 @@ Data type: `String` +### `peadm::pe_db_names` + +Type: Puppet Language + +The peadm::pe_db_names function. + +#### `peadm::pe_db_names(String $pe_ver)` + +The peadm::pe_db_names function. + +Returns: `Array` + +##### `pe_ver` + +Data type: `String` + + + ### `peadm::plan_step` Type: Ruby 4.x API From e49d87235cf177587a82776a4cf96c29bac5c36e Mon Sep 17 00:00:00 2001 From: Neil Anderson Date: Fri, 13 Dec 2024 12:12:31 +0000 Subject: [PATCH 3/3] Fixing lint --- functions/pe_db_names.pp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/functions/pe_db_names.pp b/functions/pe_db_names.pp index d2db5ed17..bc1137ec3 100644 --- a/functions/pe_db_names.pp +++ b/functions/pe_db_names.pp @@ -8,9 +8,13 @@ function peadm::pe_db_names ( 'pe-orchestrator', 'pe-rbac', ] + + $pe_2025_or_later = SemVerRange('>= 2025.0.0') + $pe_2023_8_or_later = SemVerRange('>= 2023.8.0') + case $pe_ver { # The patching service was added in 2025.0.0 - SemVerRange('>= 2025.0.0'): { + $pe_2025_or_later: { $original_db_names + [ 'pe-hac', 'pe-patching', @@ -18,8 +22,8 @@ function peadm::pe_db_names ( } # The host-action-collector (hac) was added in 2023.8 - SemVerRange('>= 2023.8.0'): { - $original_db_names + [ 'pe-hac' ] + $pe_2023_8_or_later: { + $original_db_names + ['pe-hac'] } default: {