Skip to content

Commit 97d0bf7

Browse files
committed
Make convert configure_node_groups param optional
Previously, the user would need to specify the configure_node_groups parameter when running the convert plan. In some circumstances failing to pass the right value would break the convert operation. This commit adds computed default values for this parameter so that the user does not need to pass it.
1 parent a475b88 commit 97d0bf7

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Documentation and README update
1717
### Improvements
1818

1919
- Provide a useful overview of the module in the README so that readers can quickly gain a sense of how the module is used, what it affects, and what it does not affect.
20+
- Eliminate `configure_node_groups` parameter to peadm::convert. Perform the correct action(s) automatically.
2021

2122
## Release 2.1.1
2223
### Summary

functions/oid.pp

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function peadm::oid (
66
'peadm_availability_group': { '1.3.6.1.4.1.34380.1.1.9813' }
77
'pp_application': { '1.3.6.1.4.1.34380.1.1.8' }
88
'pp_cluster': { '1.3.6.1.4.1.34380.1.1.16' }
9+
'pp_role': { '1.3.6.1.4.1.34380.1.1.13' }
910
'pp_auth_role': { '1.3.6.1.4.1.34380.1.3.13' }
1011
default: { fail("No peadm OID for ${short_name}") }
1112
}

manifests/setup/convert_pe2018.pp renamed to manifests/setup/convert_pre20197.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @summary Defines configuration needed for converting PE 2018
22
#
3-
class peadm::setup::convert_pe2018 {
3+
class peadm::setup::convert_pre20197 {
44

55
# This is needed so that compiler certs can be signed. It's included by
66
# default in 2019.7 and newer, but isn't present in 2018.1. It would be

plans/convert.pp

+50-23
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
Optional[Peadm::SingleTargetSpec] $puppetdb_database_replica_host = undef,
1212

1313
# Common Configuration
14-
String $compiler_pool_address = $master_host,
15-
Array[String] $dns_alt_names = [ ],
16-
17-
# Options
18-
Boolean $configure_node_groups = true,
14+
String $compiler_pool_address = $master_host,
15+
Optional[String] $internal_compiler_a_pool_address = undef,
16+
Optional[String] $internal_compiler_b_pool_address = undef,
17+
Array[String] $dns_alt_names = [ ],
1918
) {
2019
# TODO: read and validate convertable PE version
2120

@@ -43,31 +42,47 @@
4342
$compiler_hosts,
4443
)
4544

45+
# Get trusted fact information for all compilers. Use peadm::target_name() as
46+
# the hash key because the apply block below will break trying to parse the
47+
# $compiler_extensions variable if it has Target-type hash keys.
48+
$cert_extensions = run_task('peadm::trusted_facts', $all_targets).reduce({}) |$memo,$result| {
49+
$memo + { $result.target.peadm::target_name() => $result['extensions'] }
50+
}
51+
4652
# Know what version of PE the current targets are
4753
$pe_version = run_task('peadm::read_file', $master_target,
4854
path => '/opt/puppetlabs/server/pe_version',
4955
)[0][content].chomp
5056

51-
# Get trusted fact information for all compilers. Use peadm::target_name() as
52-
# the hash key because the apply block below will break trying to parse the
53-
# $compiler_extensions variable if it has Target-type hash keys.
54-
$compiler_extensions = run_task('peadm::trusted_facts', $compiler_targets).reduce({}) |$memo,$result| {
55-
$memo + { $result.target.peadm::target_name() => $result['extensions'] }
57+
# Figure out if this PE deployment has been configured with peadm or pe_xl
58+
# before
59+
$previously_configured_by_peadm = $all_targets.any |$target| {
60+
$exts = $cert_extensions[$target.peadm::target_name()]
61+
$exts[peadm::oid('peadm_role')] or String($exts[peadm::oid('pp_role')]) =~ /pe_xl|peadm/
62+
}
63+
64+
if (!$previously_configured_by_peadm and (versioncmp($pe_version, '2019.7.0') > 0)) {
65+
fail_plan(@("EOL"/L))
66+
PE deployment cannot be converted! PE deployment must be a deployment \
67+
created by pe_xl, by an older version of peadm, or be PE version \
68+
2019.7.0 or newer. Detected PE version ${pe_version}, and did not detect \
69+
signs that the deployment was previously created by peadm/pe_xl.
70+
| EOL
5671
}
5772

5873
# Clusters A and B are used to divide PuppetDB availability for compilers. If
5974
# the compilers given already have peadm_availability_group facts designating
6075
# them A or B, use that. Otherwise, divide them by modulus of 2.
6176
if $arch['high-availability'] {
6277
$compiler_a_targets = $compiler_targets.filter |$index,$target| {
63-
$exts = $compiler_extensions[$target.peadm::target_name()]
78+
$exts = $cert_extensions[$target.peadm::target_name()]
6479
$exts[peadm::oid('peadm_availability_group')] in ['A', 'B'] ? {
6580
true => $exts[peadm::oid('peadm_availability_group')] == 'A',
6681
false => $index % 2 == 0,
6782
}
6883
}
6984
$compiler_b_targets = $compiler_targets.filter |$index,$target| {
70-
$exts = $compiler_extensions[$target.peadm::target_name()]
85+
$exts = $cert_extensions[$target.peadm::target_name()]
7186
$exts[peadm::oid('peadm_availability_group')] in ['A', 'B'] ? {
7287
true => $exts[peadm::oid('peadm_availability_group')] == 'B',
7388
false => $index % 2 != 0,
@@ -79,9 +94,10 @@
7994
$compiler_b_targets = []
8095
}
8196

82-
if $pe_version =~ /^2018/ {
97+
# If PE version is older than 2019.7
98+
if (versioncmp($pe_version, '2019.7.0') < 0) {
8399
apply($master_target) {
84-
include peadm::setup::convert_pe2018
100+
include peadm::setup::convert_pre20197
85101
}
86102
}
87103

@@ -146,24 +162,35 @@
146162
},
147163
)
148164

149-
# Create the necessary node groups in the console
150-
151-
if $configure_node_groups {
165+
# Create the necessary node groups in the console, unless the PE version is
166+
# too old to support it pre-upgrade. In that circumstance, we trust that
167+
# the existing groups are correct enough to function until the upgrade is
168+
# performed.
169+
if (versioncmp($pe_version, '2019.7.0') >= 0) {
152170
apply($master_target) {
153171
class { 'peadm::setup::node_manager_yaml':
154172
master_host => $master_target.peadm::target_name(),
155173
}
156174

157175
class { 'peadm::setup::node_manager':
158-
master_host => $master_target.peadm::target_name(),
159-
master_replica_host => $master_replica_target.peadm::target_name(),
160-
puppetdb_database_host => $puppetdb_database_target.peadm::target_name(),
161-
puppetdb_database_replica_host => $puppetdb_database_replica_target.peadm::target_name(),
162-
compiler_pool_address => $compiler_pool_address,
163-
require => Class['peadm::setup::node_manager_yaml'],
176+
master_host => $master_target.peadm::target_name(),
177+
master_replica_host => $master_replica_target.peadm::target_name(),
178+
puppetdb_database_host => $puppetdb_database_target.peadm::target_name(),
179+
puppetdb_database_replica_host => $puppetdb_database_replica_target.peadm::target_name(),
180+
compiler_pool_address => $compiler_pool_address,
181+
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
182+
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
183+
require => Class['peadm::setup::node_manager_yaml'],
164184
}
165185
}
166186
}
187+
else {
188+
out::message(@("EOL"/L))
189+
NOTICE: Node groups not created/updated as part of convert because PE \
190+
version is too old to support them. Node groups will be updated when \
191+
the peadm::upgrade plan is run.
192+
| EOL
193+
}
167194

168195
# Run Puppet on all targets to ensure catalogs and exported resources fully
169196
# up-to-date

0 commit comments

Comments
 (0)