Skip to content

Commit 7e5eed0

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

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

REFERENCE.md

Lines changed: 33 additions & 0 deletions
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(Target $primary)`
726+
727+
The peadm::get_node_group_environment function.
728+
729+
Returns: `Any`
730+
731+
##### `primary`
732+
733+
Data type: `Target`
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
@@ -1692,6 +1711,7 @@ management using PEAdm.
16921711

16931712
The following parameters are available in the `peadm::convert` plan:
16941713

1714+
* [`node_group_environment`](#-peadm--convert--node_group_environment)
16951715
* [`primary_host`](#-peadm--convert--primary_host)
16961716
* [`replica_host`](#-peadm--convert--replica_host)
16971717
* [`compiler_hosts`](#-peadm--convert--compiler_hosts)
@@ -1702,6 +1722,11 @@ The following parameters are available in the `peadm::convert` plan:
17021722
* [`internal_compiler_b_pool_address`](#-peadm--convert--internal_compiler_b_pool_address)
17031723
* [`dns_alt_names`](#-peadm--convert--dns_alt_names)
17041724
* [`begin_at_step`](#-peadm--convert--begin_at_step)
1725+
* [`environment_node_group`](#-peadm--convert--environment_node_group)
1726+
1727+
##### <a name="-peadm--convert--node_group_environment"></a>`node_group_environment`
1728+
1729+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
17051730

17061731
##### <a name="-peadm--convert--primary_host"></a>`primary_host`
17071732

@@ -1789,6 +1814,14 @@ Optional[Enum[
17891814

17901815
Default value: `undef`
17911816

1817+
##### <a name="-peadm--convert--environment_node_group"></a>`environment_node_group`
1818+
1819+
Data type: `Optional[String[1]]`
1820+
1821+
1822+
1823+
Default value: `peadm::get_node_group_environment($primary_host)`
1824+
17921825
### <a name="peadm--install"></a>`peadm::install`
17931826

17941827
Install a new PE cluster
Lines changed: 31 additions & 0 deletions
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(Target $primary) {
11+
$peconf = peadm::get_pe_conf($primary)
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

Lines changed: 3 additions & 0 deletions
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/convert.pp

Lines changed: 6 additions & 0 deletions
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+
Optional[String[1]] $environment_node_group = 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

spec/plans/convert_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
allow_apply
2020

2121
expect_task('peadm::cert_data').return_for_targets('primary' => trustedjson)
22-
expect_task('peadm::read_file').always_return({ 'content' => '2021.7.8' })
22+
expect_task('peadm::read_file').with_params('path' => '/opt/puppetlabs/server/pe_build').always_return({ 'content' => '2021.7.8' })
23+
expect_task('peadm::read_file').with_params('path' => '/etc/puppetlabs/enterprise/conf.d/pe.conf').always_return({ 'content' => {} })
2324

2425
# For some reason, expect_plan() was not working??
2526
allow_plan('peadm::modify_certificate').always_return({})

0 commit comments

Comments
 (0)