Skip to content

Commit 1364524

Browse files
committed
(puppetlabs#469) Assign correct environment to node groups
This checks if a user configured a environment in pe.conf. If that's the case, it will be used for the PEADM-specific node groups. Otherwise we fall back to production. This fixes a timing issue discovered in puppetlabs#469. In situations where the PE infra isn't running in production, we cannot assume that a production environment exists. And a node group can only reference classes from the environment the node group belongs to.
1 parent 4a27e2d commit 1364524

11 files changed

+133
-12
lines changed

REFERENCE.md

+55-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [`peadm::file_or_content`](#peadm--file_or_content)
3030
* [`peadm::flatten_compact`](#peadm--flatten_compact)
3131
* [`peadm::generate_pe_conf`](#peadm--generate_pe_conf): Generate a pe.conf file in JSON format
32+
* [`peadm::get_node_group_environment`](#peadm--get_node_group_environment): check if a custom PE environment is set in pe.conf
3233
* [`peadm::get_pe_conf`](#peadm--get_pe_conf)
3334
* [`peadm::get_targets`](#peadm--get_targets): Accept undef or a SingleTargetSpec, and return an Array[Target, 1, 0]. This differs from get_target() in that: - It returns an Array[Target
3435
* [`peadm::migration_opts_default`](#peadm--migration_opts_default)
@@ -109,7 +110,6 @@ Supported use cases:
109110
* `peadm::misc::divert_code_manager`: This plan exists to account for a scenario where a PE XL
110111
* `peadm::modify_cert_extensions`
111112
* `peadm::subplans::component_install`: Install a new PEADM component
112-
* `peadm::subplans::configure`: Configure first-time classification and DR setup
113113
* `peadm::subplans::db_populate`: Destructively (re)populates a new or existing database with the contents or a known good source
114114
* `peadm::subplans::install`: Perform initial installation of Puppet Enterprise Extra Large
115115
* `peadm::subplans::modify_certificate`
@@ -715,6 +715,24 @@ Data type: `Hash`
715715
A hash of settings to set in the config file. Any keys that are set to
716716
undef will not be included in the config file.
717717

718+
### <a name="peadm--get_node_group_environment"></a>`peadm::get_node_group_environment`
719+
720+
Type: Puppet Language
721+
722+
check if a custom PE environment is set in pe.conf
723+
724+
#### `peadm::get_node_group_environment(Peadm::SingleTargetSpec $primary)`
725+
726+
The peadm::get_node_group_environment function.
727+
728+
Returns: `Any`
729+
730+
##### `primary`
731+
732+
Data type: `Peadm::SingleTargetSpec`
733+
734+
the FQDN for the primary, here we will read the pe.conf from
735+
718736
### <a name="peadm--get_pe_conf"></a>`peadm::get_pe_conf`
719737

720738
Type: Puppet Language
@@ -1563,11 +1581,20 @@ The peadm::add_database class.
15631581

15641582
The following parameters are available in the `peadm::add_database` plan:
15651583

1584+
* [`node_group_environment`](#-peadm--add_database--node_group_environment)
15661585
* [`targets`](#-peadm--add_database--targets)
15671586
* [`primary_host`](#-peadm--add_database--primary_host)
15681587
* [`mode`](#-peadm--add_database--mode)
15691588
* [`begin_at_step`](#-peadm--add_database--begin_at_step)
15701589

1590+
##### <a name="-peadm--add_database--node_group_environment"></a>`node_group_environment`
1591+
1592+
Data type: `String[1]`
1593+
1594+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
1595+
1596+
Default value: `peadm::get_node_group_environment($primary_host)`
1597+
15711598
##### <a name="-peadm--add_database--targets"></a>`targets`
15721599

15731600
Data type: `Peadm::SingleTargetSpec`
@@ -1692,6 +1719,7 @@ management using PEAdm.
16921719

16931720
The following parameters are available in the `peadm::convert` plan:
16941721

1722+
* [`node_group_environment`](#-peadm--convert--node_group_environment)
16951723
* [`primary_host`](#-peadm--convert--primary_host)
16961724
* [`replica_host`](#-peadm--convert--replica_host)
16971725
* [`compiler_hosts`](#-peadm--convert--compiler_hosts)
@@ -1703,6 +1731,14 @@ The following parameters are available in the `peadm::convert` plan:
17031731
* [`dns_alt_names`](#-peadm--convert--dns_alt_names)
17041732
* [`begin_at_step`](#-peadm--convert--begin_at_step)
17051733

1734+
##### <a name="-peadm--convert--node_group_environment"></a>`node_group_environment`
1735+
1736+
Data type: `String[1]`
1737+
1738+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
1739+
1740+
Default value: `peadm::get_node_group_environment($primary_host)`
1741+
17061742
##### <a name="-peadm--convert--primary_host"></a>`primary_host`
17071743

17081744
Data type: `Peadm::SingleTargetSpec`
@@ -1805,6 +1841,7 @@ The following parameters are available in the `peadm::install` plan:
18051841
* [`final_agent_state`](#-peadm--install--final_agent_state)
18061842
* [`stagingdir`](#-peadm--install--stagingdir)
18071843
* [`uploaddir`](#-peadm--install--uploaddir)
1844+
* [`node_group_environment`](#-peadm--install--node_group_environment)
18081845
* [`primary_host`](#-peadm--install--primary_host)
18091846
* [`replica_host`](#-peadm--install--replica_host)
18101847
* [`compiler_hosts`](#-peadm--install--compiler_hosts)
@@ -1904,6 +1941,14 @@ for offline usage.
19041941

19051942
Default value: `undef`
19061943

1944+
##### <a name="-peadm--install--node_group_environment"></a>`node_group_environment`
1945+
1946+
Data type: `String[1]`
1947+
1948+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
1949+
1950+
Default value: `peadm::get_node_group_environment($primary_host)`
1951+
19071952
##### <a name="-peadm--install--primary_host"></a>`primary_host`
19081953

19091954
Data type: `Peadm::SingleTargetSpec`
@@ -2277,6 +2322,7 @@ The following parameters are available in the `peadm::upgrade` plan:
22772322
* [`r10k_known_hosts`](#-peadm--upgrade--r10k_known_hosts)
22782323
* [`stagingdir`](#-peadm--upgrade--stagingdir)
22792324
* [`uploaddir`](#-peadm--upgrade--uploaddir)
2325+
* [`node_group_environment`](#-peadm--upgrade--node_group_environment)
22802326
* [`primary_host`](#-peadm--upgrade--primary_host)
22812327
* [`replica_host`](#-peadm--upgrade--replica_host)
22822328
* [`compiler_hosts`](#-peadm--upgrade--compiler_hosts)
@@ -2366,6 +2412,14 @@ for offline usage.
23662412

23672413
Default value: `'/tmp'`
23682414

2415+
##### <a name="-peadm--upgrade--node_group_environment"></a>`node_group_environment`
2416+
2417+
Data type: `String[1]`
2418+
2419+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
2420+
2421+
Default value: `peadm::get_node_group_environment($primary_host)`
2422+
23692423
##### <a name="-peadm--upgrade--primary_host"></a>`primary_host`
23702424

23712425
Data type: `Peadm::SingleTargetSpec`
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# @summary check if a custom PE environment is set in pe.conf
3+
#
4+
# @param primary the FQDN for the primary, here we will read the pe.conf from
5+
#
6+
# @see https://www.puppet.com/docs/pe/latest/upgrade_pe#update_environment
7+
#
8+
# @author Tim Meusel <[email protected]>
9+
#
10+
function peadm::get_node_group_environment(Peadm::SingleTargetSpec $primary) {
11+
$peconf = peadm::get_pe_conf(peadm::get_targets($primary, 1))
12+
# if both are set, they need to be set to the same value
13+
# if they are not set, we assume that the user runs their infra in production
14+
$pe_install = $peconf['pe_install::install::classification::pe_node_group_environment']
15+
$puppet_enterprise = $peconf['puppet_enterprise::master::recover_configuration::pe_environment']
16+
17+
# check if both are equal
18+
# This also evaluates to true if both are undef
19+
if $pe_install == $puppet_enterprise {
20+
# check if the option isn't undef
21+
# ToDo: A proper regex for allowed characters in an environment would be nice
22+
# https://github.com/puppetlabs/puppet-docs/issues/1158
23+
if $pe_install =~ String[1] {
24+
return $pe_install
25+
} else {
26+
return 'production'
27+
}
28+
} else {
29+
fail("pe_install::install::classification::pe_node_group_environment and puppet_enterprise::master::recover_configuration::pe_environment need to be set to the same value, not '${pe_install}' and ${puppet_enterprise}")
30+
}
31+
}

manifests/setup/node_manager.pp

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# A load balancer address directing traffic to any of the "B" pool
2424
# compilers. This is used for DR configuration in large and extra large
2525
# architectures.
26+
# @param node_group_environment the environment that will be assigned to all the PE Infra node groups
2627
#
2728
class peadm::setup::node_manager (
2829
String[1] $primary_host,
@@ -36,6 +37,7 @@
3637
Optional[String[1]] $compiler_pool_address = undef,
3738
Optional[String[1]] $internal_compiler_a_pool_address = $server_a_host,
3839
Optional[String[1]] $internal_compiler_b_pool_address = $server_b_host,
40+
String[1] $node_group_environment = 'production',
3941
) {
4042
# "Not-configured" placeholder string. This will be used in places where we
4143
# cannot set an explicit null, and need to supply some kind of value.
@@ -46,6 +48,7 @@
4648
# else.
4749
Node_group {
4850
purge_behavior => none,
51+
environment => $node_group_environment,
4952
}
5053

5154
##################################################

plans/add_database.pp

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#
2+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
3+
#
14
plan peadm::add_database(
25
Peadm::SingleTargetSpec $targets,
36
Peadm::SingleTargetSpec $primary_host,
@@ -9,6 +12,7 @@
912
'update-db-settings',
1013
'cleanup-db',
1114
'finalize']] $begin_at_step = undef,
15+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
1216
) {
1317
$primary_target = peadm::get_targets($primary_host, 1)
1418
$postgresql_target = peadm::get_targets($targets, 1)
@@ -91,13 +95,13 @@
9195
run_plan('peadm::subplans::component_install', $postgresql_target,
9296
primary_host => $primary_target,
9397
avail_group_letter => $avail_group_letter,
94-
role => 'puppet/puppetdb-database'
98+
role => 'puppet/puppetdb-database',
9599
)
96100
}
97101

98102
# Stop Puppet to ensure catalogs are not being compiled for PE infrastructure nodes
99103
run_command('systemctl stop puppet.service', peadm::flatten_compact([
100-
$postgresql_target,
104+
$postgresql_target,
101105
$compilers,
102106
$primary_target,
103107
$replica_target,
@@ -128,15 +132,17 @@
128132
$host = pick($a_host, $b_host)
129133
out::verbose("In transitive state, setting classification to ${host}")
130134
run_plan('peadm::util::update_classification', $primary_target,
131-
postgresql_a_host => $host,
132-
postgresql_b_host => $host,
133-
peadm_config => $peadm_config
135+
postgresql_a_host => $host,
136+
postgresql_b_host => $host,
137+
peadm_config => $peadm_config,
138+
node_group_environment => $node_group_environment,
134139
)
135140
} else {
136141
run_plan('peadm::util::update_classification', $primary_target,
137-
postgresql_a_host => $avail_group_letter ? { 'A' => $postgresql_host, default => undef },
138-
postgresql_b_host => $avail_group_letter ? { 'B' => $postgresql_host, default => undef },
139-
peadm_config => $peadm_config
142+
postgresql_a_host => $avail_group_letter ? { 'A' => $postgresql_host, default => undef },
143+
postgresql_b_host => $avail_group_letter ? { 'B' => $postgresql_host, default => undef },
144+
peadm_config => $peadm_config,
145+
node_group_environment => $node_group_environment,
140146
)
141147
}
142148
}

plans/add_replica.pp

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
# @param replica_host - The hostname and certname of the replica VM
1010
# @param replica_postgresql_host - The hostname and certname of the host with the replica PE-PosgreSQL database.
1111
# @param token_file - (optional) the token file in a different location than the default.
12-
#
12+
#
13+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
14+
#
1315
# Can be a separate host in an XL architecture, or undef in Standard or Large.
1416
plan peadm::add_replica(
1517
# Standard or Large
@@ -21,6 +23,7 @@
2123

2224
# Common Configuration
2325
Optional[String] $token_file = undef,
26+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
2427
) {
2528
$primary_target = peadm::get_targets($primary_host, 1)
2629
$replica_target = peadm::get_targets($replica_host, 1)
@@ -94,7 +97,8 @@
9497
server_b_host => $replica_avail_group_letter ? { 'B' => $replica_host, default => undef },
9598
internal_compiler_a_pool_address => $replica_avail_group_letter ? { 'A' => $replica_host, default => undef },
9699
internal_compiler_b_pool_address => $replica_avail_group_letter ? { 'B' => $replica_host, default => undef },
97-
peadm_config => $peadm_config
100+
peadm_config => $peadm_config,
101+
node_group_environment => $node_group_environment,
98102
)
99103

100104
# Source list of files on Primary and synchronize to new Replica

plans/convert.pp

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# This plan sets required certificate extensions on PE nodes, and configures
44
# the required PE node groups to make an existing cluster compatible with
55
# management using PEAdm.
6+
#
7+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
8+
#
69
plan peadm::convert (
710
# Standard
811
Peadm::SingleTargetSpec $primary_host,
@@ -26,6 +29,8 @@
2629
'modify-infra-certs',
2730
'convert-node-groups',
2831
'finalize']] $begin_at_step = undef,
32+
33+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
2934
) {
3035
peadm::assert_supported_bolt_version()
3136

@@ -223,6 +228,7 @@
223228
compiler_pool_address => $compiler_pool_address,
224229
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
225230
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
231+
node_group_environment => $node_group_environment,
226232
require => Class['peadm::setup::node_manager_yaml'],
227233
}
228234

plans/install.pp

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
# Directory the installer tarball will be uploaded to or expected to be in
3232
# for offline usage.
3333
#
34+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
35+
#
3436
plan peadm::install (
3537
# Standard
3638
Peadm::SingleTargetSpec $primary_host,
@@ -73,6 +75,7 @@
7375
Enum['direct', 'bolthost'] $download_mode = 'bolthost',
7476
Boolean $permit_unsafe_versions = false,
7577
String $token_lifetime = '1y',
78+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
7679
) {
7780
peadm::assert_supported_bolt_version()
7881

@@ -134,6 +137,7 @@
134137
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
135138
deploy_environment => $deploy_environment,
136139
ldap_config => $ldap_config,
140+
node_group_environment => $node_group_environment,
137141

138142
# Other
139143
stagingdir => $stagingdir,

plans/subplans/configure.pp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# Configures the state the puppet agent should be in on infrastructure nodes
2121
# after PE is configured successfully.
2222
#
23+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
24+
#
2325
plan peadm::subplans::configure (
2426
# Standard
2527
Peadm::SingleTargetSpec $primary_host,
@@ -43,6 +45,7 @@
4345
# Other
4446
String $stagingdir = '/tmp',
4547
Enum['running', 'stopped'] $final_agent_state = 'running'
48+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
4649
) {
4750
# TODO: get and validate PE version
4851

@@ -102,6 +105,7 @@
102105
compiler_pool_address => $compiler_pool_address,
103106
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
104107
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
108+
node_group_environment => $node_group_environment,
105109
require => Class['peadm::setup::node_manager_yaml'],
106110
}
107111
}

plans/upgrade.pp

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
# Directory the installer tarball will be uploaded to or expected to be in
3232
# for offline usage.
3333
#
34+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
35+
#
3436
plan peadm::upgrade (
3537
# Standard
3638
Peadm::SingleTargetSpec $primary_host,
@@ -66,6 +68,7 @@
6668
'upgrade-replica',
6769
'upgrade-replica-compilers',
6870
'finalize']] $begin_at_step = undef,
71+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
6972
) {
7073
# Ensure input valid for a supported architecture
7174
$arch = peadm::assert_supported_architecture(
@@ -326,6 +329,7 @@
326329
compiler_pool_address => $compiler_pool_address,
327330
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
328331
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
332+
node_group_environment => $node_group_environment,
329333
require => Class['peadm::setup::node_manager_yaml'],
330334
}
331335
}

plans/util/update_classification.pp

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
#
33
# @summary Configure classification
44
#
5+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
6+
#
57
plan peadm::util::update_classification (
68
# Standard
79
Peadm::SingleTargetSpec $targets,
10+
String[1] $node_group_environment,
811
Optional[Hash] $peadm_config = undef,
912
Optional[Peadm::SingleTargetSpec] $server_a_host = undef,
1013
Optional[Peadm::SingleTargetSpec] $server_b_host = undef,
@@ -76,6 +79,7 @@
7679
compiler_pool_address => $new['params']['compiler_pool_address'],
7780
internal_compiler_a_pool_address => $new['params']['internal_compiler_a_pool_address'],
7881
internal_compiler_b_pool_address => $new['params']['internal_compiler_b_pool_address'],
82+
node_group_environment => $node_group_environment,
7983
require => Class['peadm::setup::node_manager_yaml'],
8084
}
8185
}

0 commit comments

Comments
 (0)