Skip to content
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

(PE-39352) Update backup restore plans for hac database #532

Open
wants to merge 3 commits 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
78 changes: 75 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

### Functions

* [`peadm::amend_recovery_defaults_by_pe_version`](#peadm--amend_recovery_defaults_by_pe_version)
* [`peadm::assert_supported_architecture`](#peadm--assert_supported_architecture): Assert that the architecture given is a supported one
* [`peadm::assert_supported_bolt_version`](#peadm--assert_supported_bolt_version): Assert that the Bolt executable running PEAdm is a supported version
* [`peadm::assert_supported_pe_version`](#peadm--assert_supported_pe_version): Assert that the PE version given is supported by PEAdm
Expand All @@ -39,6 +40,7 @@
* [`peadm::recovery_opts_all`](#peadm--recovery_opts_all)
* [`peadm::recovery_opts_default`](#peadm--recovery_opts_default)
* [`peadm::update_pe_conf`](#peadm--update_pe_conf): Update the pe.conf file on a target with the provided hash
* [`peadm::validated_pe_version_for_backup_restore`](#peadm--validated_pe_version_for_backup_restore): Verify that *pe_version* string is a valid SemVer. If not, warn, and return "0.0.0" as a permissive default.
* [`peadm::wait_until_service_ready`](#peadm--wait_until_service_ready): A convenience function to help remember port numbers for services and handle running the wait_until_service_ready task

### Data types
Expand Down Expand Up @@ -139,6 +141,36 @@ Supported use cases:

## Functions

### <a name="peadm--amend_recovery_defaults_by_pe_version"></a>`peadm::amend_recovery_defaults_by_pe_version`

Type: Puppet Language

The peadm::amend_recovery_defaults_by_pe_version function.

#### `peadm::amend_recovery_defaults_by_pe_version(Hash $base_opts, Peadm::Pe_version $pe_version, Boolean $opt_value)`

The peadm::amend_recovery_defaults_by_pe_version function.

Returns: `Any`

##### `base_opts`

Data type: `Hash`



##### `pe_version`

Data type: `Peadm::Pe_version`



##### `opt_value`

Data type: `Boolean`



### <a name="peadm--assert_supported_architecture"></a>`peadm::assert_supported_architecture`

Type: Puppet Language
Expand Down Expand Up @@ -787,12 +819,18 @@ Type: Puppet Language

The peadm::migration_opts_default function.

#### `peadm::migration_opts_default()`
#### `peadm::migration_opts_default(Peadm::Pe_version $pe_version)`

The peadm::migration_opts_default function.

Returns: `Any`

##### `pe_version`

Data type: `Peadm::Pe_version`



### <a name="peadm--node_manager_yaml_location"></a>`peadm::node_manager_yaml_location`

Type: Ruby 4.x API
Expand Down Expand Up @@ -853,24 +891,36 @@ Type: Puppet Language

The peadm::recovery_opts_all function.

#### `peadm::recovery_opts_all()`
#### `peadm::recovery_opts_all(Peadm::Pe_version $pe_version)`

The peadm::recovery_opts_all function.

Returns: `Any`

##### `pe_version`

Data type: `Peadm::Pe_version`



### <a name="peadm--recovery_opts_default"></a>`peadm::recovery_opts_default`

Type: Puppet Language

The peadm::recovery_opts_default function.

#### `peadm::recovery_opts_default()`
#### `peadm::recovery_opts_default(Peadm::Pe_version $pe_version)`

The peadm::recovery_opts_default function.

Returns: `Any`

##### `pe_version`

Data type: `Peadm::Pe_version`



### <a name="peadm--update_pe_conf"></a>`peadm::update_pe_conf`

Type: Puppet Language
Expand All @@ -895,6 +945,26 @@ Data type: `Hash`

The hash to update the pe.conf file with

### <a name="peadm--validated_pe_version_for_backup_restore"></a>`peadm::validated_pe_version_for_backup_restore`

Type: Puppet Language

Verify that *pe_version* string is a valid SemVer.
If not, warn, and return "0.0.0" as a permissive default.

#### `peadm::validated_pe_version_for_backup_restore(Optional[String] $pe_version)`

Verify that *pe_version* string is a valid SemVer.
If not, warn, and return "0.0.0" as a permissive default.

Returns: `Any`

##### `pe_version`

Data type: `Optional[String]`



### <a name="peadm--wait_until_service_ready"></a>`peadm::wait_until_service_ready`

Type: Puppet Language
Expand Down Expand Up @@ -1014,6 +1084,8 @@ Struct[{
'orchestrator' => Optional[Boolean],
'puppetdb' => Optional[Boolean],
'rbac' => Optional[Boolean],
'hac' => Optional[Boolean],
'patching' => Optional[Boolean],
}]
```

Expand Down
25 changes: 25 additions & 0 deletions functions/amend_recovery_defaults_by_pe_version.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function peadm::amend_recovery_defaults_by_pe_version (
Hash $base_opts,
Peadm::Pe_version $pe_version,
Boolean $opt_value,
) {
# work around puppet-lint check_unquoted_string_in_case
$pe_2025_0 = SemVerRange('>= 2025.0')
$pe_2023_7 = SemVerRange('>= 2023.7')
case $pe_version {
$pe_2025_0: {
$base_opts + {
'hac' => $opt_value,
'patching' => $opt_value,
}
}
$pe_2023_7: {
$base_opts + {
'hac' => $opt_value,
}
}
default: {
$base_opts
}
}
}
7 changes: 5 additions & 2 deletions functions/migration_opts_default.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function peadm::migration_opts_default () {
{
function peadm::migration_opts_default (
Peadm::Pe_version $pe_version,
) {
$base_opts = {
'activity' => true,
'ca' => true,
'classifier' => true,
Expand All @@ -9,4 +11,5 @@ function peadm::migration_opts_default () {
'puppetdb' => true,
'rbac' => true,
}
peadm::amend_recovery_defaults_by_pe_version($base_opts, $pe_version, true)
}
7 changes: 5 additions & 2 deletions functions/recovery_opts_all.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function peadm::recovery_opts_all () {
{
function peadm::recovery_opts_all (
Peadm::Pe_version $pe_version,
) {
$base_opts = {
'activity' => true,
'ca' => true,
'classifier' => true,
Expand All @@ -9,4 +11,5 @@ function peadm::recovery_opts_all () {
'puppetdb' => true,
'rbac' => true,
}
peadm::amend_recovery_defaults_by_pe_version($base_opts, $pe_version, true)
}
7 changes: 5 additions & 2 deletions functions/recovery_opts_default.pp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
function peadm::recovery_opts_default () {
{
function peadm::recovery_opts_default (
Peadm::Pe_version $pe_version,
) {
$base_opts = {
'activity' => false,
'ca' => true,
'classifier' => false,
Expand All @@ -9,4 +11,5 @@ function peadm::recovery_opts_default () {
'puppetdb' => true,
'rbac' => false,
}
peadm::amend_recovery_defaults_by_pe_version($base_opts, $pe_version, false)
}
23 changes: 23 additions & 0 deletions functions/validated_pe_version_for_backup_restore.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Verify that *pe_version* string is a valid SemVer.
# If not, warn, and return "0.0.0" as a permissive default.
function peadm::validated_pe_version_for_backup_restore(
Optional[String] $pe_version,
) {
# work around puppet-lint check_unquoted_string_in_case
$semverrange = SemVerRange('>=0.0.0')
case $pe_version {
# Validate that the value is a SemVer value.
$semverrange: {
$pe_version
}
default: {
$msg = @("WARN")
WARNING: Retrieved a missing or unparseable PE version of '${pe_version}'.
Newer service databases released in 2023.7+ will be skipped from defaults.
(host-action-collector, patching)
|-WARN
out::message($msg)
'0.0.0'
}
}
}
12 changes: 9 additions & 3 deletions plans/backup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
getvar('cluster.params.compiler_hosts'),
)

$pe_version = peadm::validated_pe_version_for_backup_restore(getvar('cluster.pe_version'))

$recovery_opts = $backup_type? {
'recovery' => peadm::recovery_opts_default(),
'migration' => peadm::migration_opts_default(),
'custom' => peadm::recovery_opts_all() + $backup,
'recovery' => peadm::recovery_opts_default($pe_version),
'migration' => peadm::migration_opts_default($pe_version),
'custom' => peadm::recovery_opts_all($pe_version) + $backup,
}

$timestamp = Timestamp.new().strftime('%Y-%m-%dT%H%M%SZ')
Expand All @@ -55,6 +57,10 @@
'activity' => $primary_target,
'rbac' => $primary_target,
'puppetdb' => $puppetdb_postgresql_target,
# (host-action-collector db will be filtered for pe version by recovery_opts)
'hac' => $primary_target,
# (patching db will be filtered for pe version by recovery_opts)
'patching' => $primary_target,
}.filter |$key,$_| {
$recovery_opts[$key] == true
}
Expand Down
16 changes: 11 additions & 5 deletions plans/restore.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# try to load the cluster configuration by running peadm::get_peadm_config, but allow for errors to happen
$_cluster = run_task('peadm::get_peadm_config', $targets, { '_catch_errors' => true }).first.value

if $_cluster == undef or getvar('_cluster.params') == undef {
if $_cluster == undef or getvar('_cluster.params') == undef or getvar('_cluster.pe_version') == undef {
# failed to get cluster config, load from backup
out::message('Failed to get cluster configuration, loading from backup...')
$result = download_file("${recovery_directory}/peadm/peadm_config.json", 'peadm_config.json', $targets).first.value
Expand All @@ -59,11 +59,13 @@
getvar('cluster.params.compiler_hosts'),
)

$pe_version = peadm::validated_pe_version_for_backup_restore(getvar('cluster.pe_version'))

$recovery_opts = $restore_type? {
'recovery' => peadm::recovery_opts_default(),
'recovery' => peadm::recovery_opts_default($pe_version),
'recovery-db' => { 'puppetdb' => true, },
'migration' => peadm::migration_opts_default(),
'custom' => peadm::recovery_opts_all() + $restore,
'migration' => peadm::migration_opts_default($pe_version),
'custom' => peadm::recovery_opts_all($pe_version) + $restore,
}

$primary_target = peadm::get_targets(getvar('cluster.params.primary_host'), 1)
Expand Down Expand Up @@ -97,6 +99,10 @@
'activity' => [$primary_target],
'rbac' => [$primary_target],
'puppetdb' => $puppetdb_postgresql_targets,
# (host-action-collector db will be filtered for pe version by recovery_opts)
'hac' => $primary_target,
# (patching db will be filtered for pe version by recovery_opts)
'patching' => $primary_target,
}.filter |$key,$_| {
$recovery_opts[$key] == true
}
Expand Down Expand Up @@ -203,7 +209,7 @@
if getvar('recovery_opts.orchestrator') {
out::message('# Restoring orchestrator secret keys')
run_command(@("CMD"/L), $primary_target)
cp -rp ${shellquote($recovery_directory)}/orchestrator/secrets/* /etc/puppetlabs/orchestration-services/conf.d/secrets/
cp -rp ${shellquote($recovery_directory)}/orchestrator/secrets/* /etc/puppetlabs/orchestration-services/conf.d/secrets/
| CMD
}
# lint:endignore
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/peadm_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"pe_version" : "2023.7.0",
"params": { "primary_host": "primary", "primary_postgresql_host": "postgres" }
}
3 changes: 3 additions & 0 deletions spec/fixtures/peadm_config.no_pe_version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"params": { "primary_host": "primary", "primary_postgresql_host": "postgres" }
}
15 changes: 15 additions & 0 deletions spec/functions/amend_recovery_defaults_by_pe_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

describe 'peadm::amend_recovery_defaults_by_pe_version' do
it 'just returns the base opts if version < 2023.7' do
is_expected.to run.with_params({}, '2023.6.0', true).and_return({})
end

it 'adds hac if version >= 2023.7' do
is_expected.to run.with_params({}, '2023.7.0', true).and_return({ 'hac' => true })
end

it 'adds hac false based on opt_value' do
is_expected.to run.with_params({}, '2023.7.0', false).and_return({ 'hac' => false })
end
end
51 changes: 51 additions & 0 deletions spec/functions/migration_opts_default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
require 'spec_helper'

describe 'peadm::migration_opts_default' do
it 'returns pre 2023.7 defaults' do
is_expected.to run.with_params('2023.6.0').and_return(
{
'activity' => true,
'ca' => true,
'classifier' => true,
'code' => false,
'config' => false,
'orchestrator' => true,
'puppetdb' => true,
'rbac' => true,
},
)
end

it 'returns 2023.7+ defaults with hac' do
is_expected.to run.with_params('2023.7.0').and_return(
{
'activity' => true,
'ca' => true,
'classifier' => true,
'code' => false,
'config' => false,
'orchestrator' => true,
'puppetdb' => true,
'rbac' => true,
'hac' => true,
},
)
end

it 'returns 2025.0+ defaults with hac and patching' do
is_expected.to run.with_params('2025.0.0').and_return(
{
'activity' => true,
'ca' => true,
'classifier' => true,
'code' => false,
'config' => false,
'orchestrator' => true,
'puppetdb' => true,
'rbac' => true,
'hac' => true,
'patching' => true,
},
)
end
end
Loading
Loading