Skip to content

Commit

Permalink
Merge pull request #129 from puppetlabs/fix-upgrade-peconf
Browse files Browse the repository at this point in the history
Fix upgrade peconf
  • Loading branch information
reidmv committed Sep 26, 2020
2 parents 6944b8e + 13f8ab7 commit 2d396e9
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# PEADM module

## Unreleased
### Summary

Bugfix release

### Bugfixes

- Previously, on upgrade, peadm did not ensure that PostgreSQL servers' pe.conf file contained the critical keys that inform the installer that the system is a stand-alone database. The peadm::upgrade plan now ensures the critical keys are correct as part of the upgrade preparation.
- When upgrading a DR replica to PE 2019.8.0 or 2019.8.1, there is an installer bug that causes the upgrade to fail due to how `puppetdb delete-reports` performs in this configuration. This release works around the problem by bypassing `puppetdb delete-reports`. This workaround will be removed in future releases of peadm after the installer / `puppetdb delete-reports` bug is fixed.

## 2.4.0
### Summary

Expand Down
4 changes: 2 additions & 2 deletions functions/validate_version.pp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function peadm::validate_version(
String $version,
) {
$supported = ($version =~ SemVerRange('>= 2019.7.0 < 2019.9.0'))
$supported = ($version =~ SemVerRange('>= 2019.7.0 <= 2019.8.1'))
unless $supported {
fail(@("REASON"/L))
Expand All @@ -10,7 +10,7 @@ function peadm::validate_version(
For PE versions older than 2019.7, please use version 1.x of the \
puppetlabs-peadm module.

For PE versions newer than 2019.8.x, check to see if a new version of peadm \
For PE versions newer than 2019.8.1, check to see if a new version of peadm \
exists which supports that version of PE.

| REASON
Expand Down
15 changes: 15 additions & 0 deletions lib/puppet/functions/peadm/parsehocon.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true


Puppet::Functions.create_function(:'peadm::parsehocon') do
dispatch :parsehocon do
param 'String', :hocon_string
end

def parsehocon(hocon_string)
require 'hocon/config_factory'

data = Hocon::ConfigFactory.parse_string(hocon_string)
data.resolve.root.unwrapped
end
end
58 changes: 57 additions & 1 deletion plans/upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,37 @@
# task for idempotency reasons. When the orchestrator has been upgraded but
# not all pxp-agents have, the built-in service task does not work over pcp.
run_command('systemctl stop puppet', $all_targets)

# Create a variable for configuring PuppetDB access for all the certnames
# that are known to need it.
$profile_database_puppetdb_hosts = {
'puppet_enterprise::profile::database::puppetdb_hosts' => (
$compiler_targets + $master_target + $master_replica_target
).map |$t| { $t.peadm::target_name() },
}

# Ensure the pe.conf files on the PostgreSQL node(s) are correct. This file
# is only ever consulted during install and upgrade of these nodes, but if
# it contains the wrong values, upgrade will fail.
peadm::flatten_compact([
$puppetdb_database_target,
$puppetdb_database_replica_target,
]).each |$target| {
$current_pe_conf = run_task('peadm::read_file', $target,
path => '/etc/puppetlabs/enterprise/conf.d/pe.conf',
).first['content']

$pe_conf = ($current_pe_conf ? {
undef => {},
default => $current_pe_conf.peadm::parsehocon(),
} + {
'console_admin_password' => 'not used',
'puppet_enterprise::puppet_master_host' => $master_target.peadm::target_name(),
'puppet_enterprise::database_host' => $target.peadm::target_name(),
} + $profile_database_puppetdb_hosts).to_json_pretty()

write_file($pe_conf, '/etc/puppetlabs/enterprise/conf.d/pe.conf', $target)
}
}

peadm::plan_step('upgrade-primary') || {
Expand Down Expand Up @@ -242,12 +273,37 @@
$puppetdb_database_replica_target,
]))

# Upgrade the master replica
# The `puppetdb delete-reports` CLI app has a bug in 2019.8.0 where it
# doesn't deal well with the PuppetDB database being on a separate node.
# So, move it aside before running the upgrade.
$pdbapps = '/opt/puppetlabs/server/apps/puppetdb/cli/apps'
$workaround_delete_reports = $arch['high-availability'] and $version =~ SemVerRange('>= 2019.8')
if $workaround_delete_reports {
run_command(@("COMMAND"/$), $master_replica_target)
if [ -e ${pdbapps}/delete-reports -a ! -h ${pdbapps}/delete-reports ]
then
mv ${pdbapps}/delete-reports ${pdbapps}/delete-reports.original
ln -s \$(which true) ${pdbapps}/delete-reports
fi
| COMMAND
}

# Upgrade the master replica.
run_task('peadm::puppet_infra_upgrade', $master_target,
type => 'replica',
targets => $master_replica_target.map |$t| { $t.peadm::target_name() },
token_file => $token_file,
)

# Return the delete-reports CLI app to its original state
if $workaround_delete_reports {
run_command(@("COMMAND"/$), $master_replica_target)
if [ -e ${pdbapps}/delete-reports.original ]
then
mv ${pdbapps}/delete-reports.original ${pdbapps}/delete-reports
fi
| COMMAND
}
}

peadm::plan_step('upgrade-replica-compilers') || {
Expand Down

0 comments on commit 2d396e9

Please sign in to comment.