Skip to content

Commit ec84e0c

Browse files
committed
(#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 #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 ec84e0c

14 files changed

+186
-13
lines changed

REFERENCE.md

+55
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)
@@ -715,6 +716,24 @@ Data type: `Hash`
715716
A hash of settings to set in the config file. Any keys that are set to
716717
undef will not be included in the config file.
717718

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

720739
Type: Puppet Language
@@ -1563,11 +1582,20 @@ The peadm::add_database class.
15631582

15641583
The following parameters are available in the `peadm::add_database` plan:
15651584

1585+
* [`node_group_environment`](#-peadm--add_database--node_group_environment)
15661586
* [`targets`](#-peadm--add_database--targets)
15671587
* [`primary_host`](#-peadm--add_database--primary_host)
15681588
* [`mode`](#-peadm--add_database--mode)
15691589
* [`begin_at_step`](#-peadm--add_database--begin_at_step)
15701590

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

15731601
Data type: `Peadm::SingleTargetSpec`
@@ -1692,6 +1720,7 @@ management using PEAdm.
16921720

16931721
The following parameters are available in the `peadm::convert` plan:
16941722

1723+
* [`node_group_environment`](#-peadm--convert--node_group_environment)
16951724
* [`primary_host`](#-peadm--convert--primary_host)
16961725
* [`replica_host`](#-peadm--convert--replica_host)
16971726
* [`compiler_hosts`](#-peadm--convert--compiler_hosts)
@@ -1703,6 +1732,14 @@ The following parameters are available in the `peadm::convert` plan:
17031732
* [`dns_alt_names`](#-peadm--convert--dns_alt_names)
17041733
* [`begin_at_step`](#-peadm--convert--begin_at_step)
17051734

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

17081745
Data type: `Peadm::SingleTargetSpec`
@@ -1805,6 +1842,7 @@ The following parameters are available in the `peadm::install` plan:
18051842
* [`final_agent_state`](#-peadm--install--final_agent_state)
18061843
* [`stagingdir`](#-peadm--install--stagingdir)
18071844
* [`uploaddir`](#-peadm--install--uploaddir)
1845+
* [`node_group_environment`](#-peadm--install--node_group_environment)
18081846
* [`primary_host`](#-peadm--install--primary_host)
18091847
* [`replica_host`](#-peadm--install--replica_host)
18101848
* [`compiler_hosts`](#-peadm--install--compiler_hosts)
@@ -1904,6 +1942,14 @@ for offline usage.
19041942

19051943
Default value: `undef`
19061944

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

19091955
Data type: `Peadm::SingleTargetSpec`
@@ -2277,6 +2323,7 @@ The following parameters are available in the `peadm::upgrade` plan:
22772323
* [`r10k_known_hosts`](#-peadm--upgrade--r10k_known_hosts)
22782324
* [`stagingdir`](#-peadm--upgrade--stagingdir)
22792325
* [`uploaddir`](#-peadm--upgrade--uploaddir)
2326+
* [`node_group_environment`](#-peadm--upgrade--node_group_environment)
22802327
* [`primary_host`](#-peadm--upgrade--primary_host)
22812328
* [`replica_host`](#-peadm--upgrade--replica_host)
22822329
* [`compiler_hosts`](#-peadm--upgrade--compiler_hosts)
@@ -2366,6 +2413,14 @@ for offline usage.
23662413

23672414
Default value: `'/tmp'`
23682415

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

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

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

+13-7
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,7 +95,7 @@
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

@@ -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

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
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+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
13+
#
1314
# Can be a separate host in an XL architecture, or undef in Standard or Large.
1415
plan peadm::add_replica(
1516
# Standard or Large
@@ -21,6 +22,7 @@
2122

2223
# Common Configuration
2324
Optional[String] $token_file = undef,
25+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
2426
) {
2527
$primary_target = peadm::get_targets($primary_host, 1)
2628
$replica_target = peadm::get_targets($replica_host, 1)
@@ -94,7 +96,8 @@
9496
server_b_host => $replica_avail_group_letter ? { 'B' => $replica_host, default => undef },
9597
internal_compiler_a_pool_address => $replica_avail_group_letter ? { 'A' => $replica_host, default => undef },
9698
internal_compiler_b_pool_address => $replica_avail_group_letter ? { 'B' => $replica_host, default => undef },
97-
peadm_config => $peadm_config
99+
peadm_config => $peadm_config,
100+
node_group_environment => $node_group_environment,
98101
)
99102

100103
# 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

+5-1
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,
@@ -42,7 +44,8 @@
4244

4345
# Other
4446
String $stagingdir = '/tmp',
45-
Enum['running', 'stopped'] $final_agent_state = 'running'
47+
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)