Skip to content

Commit 60f3067

Browse files
authored
(#469) Upgrade: Assign correct environment to node groups (#635)
* (#469) Upgrade: Assign production environment to node groups This makes the environment for node groups configureable. The default is 'production'. This is also the default in the node_group resource type: https://github.com/puppetlabs/puppetlabs-node_manager/blob/main/lib/puppet/type/node_group.rb#L124 We could also default to `undef` in PEADM and rely on the node_manage module, but explicitly setting `production` seems to be safer. This is related to #469 and makes the environment configureable during upgrades. Co-authored-by: David Mallon <[email protected]> * (#469) Upgrade: 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. --------- Co-authored-by: David Mallon <[email protected]> Note: internal tickets exist for the 2 CI failures, we will merge past them for now
1 parent e243c14 commit 60f3067

File tree

13 files changed

+176
-10
lines changed

13 files changed

+176
-10
lines changed

REFERENCE.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* [`peadm::file_or_content`](#peadm--file_or_content)
3131
* [`peadm::flatten_compact`](#peadm--flatten_compact)
3232
* [`peadm::generate_pe_conf`](#peadm--generate_pe_conf): Generate a pe.conf file in JSON format
33+
* [`peadm::get_node_group_environment`](#peadm--get_node_group_environment): check if a custom PE environment is set in pe.conf
3334
* [`peadm::get_pe_conf`](#peadm--get_pe_conf)
3435
* [`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
3536
* [`peadm::log_plan_parameters`](#peadm--log_plan_parameters)
@@ -740,6 +741,24 @@ Data type: `Hash`
740741
A hash of settings to set in the config file. Any keys that are set to
741742
undef will not be included in the config file.
742743

744+
### <a name="peadm--get_node_group_environment"></a>`peadm::get_node_group_environment`
745+
746+
Type: Puppet Language
747+
748+
check if a custom PE environment is set in pe.conf
749+
750+
#### `peadm::get_node_group_environment(Peadm::SingleTargetSpec $primary)`
751+
752+
The peadm::get_node_group_environment function.
753+
754+
Returns: `String` the desired environment for PE specific node groups
755+
756+
##### `primary`
757+
758+
Data type: `Peadm::SingleTargetSpec`
759+
760+
the FQDN for the primary, here we will read the pe.conf from
761+
743762
### <a name="peadm--get_pe_conf"></a>`peadm::get_pe_conf`
744763

745764
Type: Puppet Language
@@ -1832,12 +1851,21 @@ The peadm::add_database class.
18321851

18331852
The following parameters are available in the `peadm::add_database` plan:
18341853

1854+
* [`node_group_environment`](#-peadm--add_database--node_group_environment)
18351855
* [`targets`](#-peadm--add_database--targets)
18361856
* [`primary_host`](#-peadm--add_database--primary_host)
18371857
* [`mode`](#-peadm--add_database--mode)
18381858
* [`begin_at_step`](#-peadm--add_database--begin_at_step)
18391859
* [`is_migration`](#-peadm--add_database--is_migration)
18401860

1861+
##### <a name="-peadm--add_database--node_group_environment"></a>`node_group_environment`
1862+
1863+
Data type: `String[1]`
1864+
1865+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
1866+
1867+
Default value: `peadm::get_node_group_environment($primary_host)`
1868+
18411869
##### <a name="-peadm--add_database--targets"></a>`targets`
18421870

18431871
Data type: `Peadm::SingleTargetSpec`
@@ -1899,6 +1927,7 @@ The following parameters are available in the `peadm::add_replica` plan:
18991927
* [`replica_host`](#-peadm--add_replica--replica_host)
19001928
* [`replica_postgresql_host`](#-peadm--add_replica--replica_postgresql_host)
19011929
* [`token_file`](#-peadm--add_replica--token_file)
1930+
* [`node_group_environment`](#-peadm--add_replica--node_group_environment)
19021931

19031932
##### <a name="-peadm--add_replica--primary_host"></a>`primary_host`
19041933

@@ -1929,6 +1958,14 @@ Data type: `Optional[String]`
19291958

19301959
Default value: `undef`
19311960

1961+
##### <a name="-peadm--add_replica--node_group_environment"></a>`node_group_environment`
1962+
1963+
Data type: `String[1]`
1964+
1965+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
1966+
1967+
Default value: `peadm::get_node_group_environment($primary_host)`
1968+
19321969
### <a name="peadm--backup"></a>`peadm::backup`
19331970

19341971
Backup puppet primary configuration
@@ -2016,6 +2053,7 @@ management using PEAdm.
20162053
The following parameters are available in the `peadm::convert` plan:
20172054

20182055
* [`begin_at_step`](#-peadm--convert--begin_at_step)
2056+
* [`node_group_environment`](#-peadm--convert--node_group_environment)
20192057
* [`primary_host`](#-peadm--convert--primary_host)
20202058
* [`replica_host`](#-peadm--convert--replica_host)
20212059
* [`compiler_hosts`](#-peadm--convert--compiler_hosts)
@@ -2035,6 +2073,14 @@ The step where the plan should start. If not set, it will start at the beginning
20352073

20362074
Default value: `undef`
20372075

2076+
##### <a name="-peadm--convert--node_group_environment"></a>`node_group_environment`
2077+
2078+
Data type: `String[1]`
2079+
2080+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
2081+
2082+
Default value: `peadm::get_node_group_environment($primary_host)`
2083+
20382084
##### <a name="-peadm--convert--primary_host"></a>`primary_host`
20392085

20402086
Data type: `Peadm::SingleTargetSpec`
@@ -2723,6 +2769,7 @@ The following parameters are available in the `peadm::upgrade` plan:
27232769
* [`stagingdir`](#-peadm--upgrade--stagingdir)
27242770
* [`uploaddir`](#-peadm--upgrade--uploaddir)
27252771
* [`begin_at_step`](#-peadm--upgrade--begin_at_step)
2772+
* [`node_group_environment`](#-peadm--upgrade--node_group_environment)
27262773
* [`primary_host`](#-peadm--upgrade--primary_host)
27272774
* [`replica_host`](#-peadm--upgrade--replica_host)
27282775
* [`compiler_hosts`](#-peadm--upgrade--compiler_hosts)
@@ -2819,6 +2866,14 @@ The step where the plan should start. If not set, it will start at the beginning
28192866

28202867
Default value: `undef`
28212868

2869+
##### <a name="-peadm--upgrade--node_group_environment"></a>`node_group_environment`
2870+
2871+
Data type: `String[1]`
2872+
2873+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
2874+
2875+
Default value: `peadm::get_node_group_environment($primary_host)`
2876+
28222877
##### <a name="-peadm--upgrade--primary_host"></a>`primary_host`
28232878

28242879
Data type: `Peadm::SingleTargetSpec`
Lines changed: 33 additions & 0 deletions
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/legacy_compiler_group.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
String[1] $primary_host,
44
Optional[String] $internal_compiler_a_pool_address = undef,
55
Optional[String] $internal_compiler_b_pool_address = undef,
6+
String[1] $node_group_environment = 'production',
67
) {
78
Node_group {
89
purge_behavior => none,
10+
environment => $node_group_environment,
911
}
1012

1113
node_group { 'PE Legacy Compiler':

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/add_database.pp

Lines changed: 12 additions & 6 deletions
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,
@@ -10,6 +13,7 @@
1013
'cleanup-db',
1114
'finalize']] $begin_at_step = undef,
1215
Optional[Boolean] $is_migration = false,
16+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
1317
) {
1418
$primary_target = peadm::get_targets($primary_host, 1)
1519
$postgresql_target = peadm::get_targets($targets, 1)
@@ -135,15 +139,17 @@
135139
$host = pick($a_host, $b_host)
136140
out::verbose("In transitive state, setting classification to ${host}")
137141
run_plan('peadm::util::update_classification', $primary_target,
138-
postgresql_a_host => $host,
139-
postgresql_b_host => $host,
140-
peadm_config => $peadm_config
142+
postgresql_a_host => $host,
143+
postgresql_b_host => $host,
144+
peadm_config => $peadm_config,
145+
node_group_environment => $node_group_environment,
141146
)
142147
} else {
143148
run_plan('peadm::util::update_classification', $primary_target,
144-
postgresql_a_host => $avail_group_letter ? { 'A' => $postgresql_host, default => undef },
145-
postgresql_b_host => $avail_group_letter ? { 'B' => $postgresql_host, default => undef },
146-
peadm_config => $peadm_config
149+
postgresql_a_host => $avail_group_letter ? { 'A' => $postgresql_host, default => undef },
150+
postgresql_b_host => $avail_group_letter ? { 'B' => $postgresql_host, default => undef },
151+
peadm_config => $peadm_config,
152+
node_group_environment => $node_group_environment,
147153
)
148154
}
149155
}

plans/add_replica.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# @param replica_postgresql_host - The hostname and certname of the host with the replica PE-PosgreSQL database.
88
# Can be a separate host in an XL architecture, or undef in Standard or Large.
99
# @param token_file - (optional) the token file in a different location than the default.
10+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
1011
plan peadm::add_replica(
1112
# Standard or Large
1213
Peadm::SingleTargetSpec $primary_host,
@@ -17,6 +18,7 @@
1718

1819
# Common Configuration
1920
Optional[String] $token_file = undef,
21+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
2022
) {
2123
$primary_target = peadm::get_targets($primary_host, 1)
2224
$replica_target = peadm::get_targets($replica_host, 1)
@@ -96,7 +98,8 @@
9698
server_b_host => $replica_avail_group_letter ? { 'B' => $replica_target.peadm::certname(), default => undef },
9799
internal_compiler_a_pool_address => $replica_avail_group_letter ? { 'A' => $replica_target.peadm::certname(), default => undef },
98100
internal_compiler_b_pool_address => $replica_avail_group_letter ? { 'B' => $replica_target.peadm::certname(), default => undef },
99-
peadm_config => $peadm_config
101+
peadm_config => $peadm_config,
102+
node_group_environment => $node_group_environment,
100103
)
101104

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

plans/convert.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# management using PEAdm.
66
#
77
# @param begin_at_step The step where the plan should start. If not set, it will start at the beginning
8+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
89
#
910
plan peadm::convert (
1011
# Standard
@@ -26,6 +27,7 @@
2627
Array[String] $dns_alt_names = [],
2728

2829
Optional[Peadm::ConvertSteps] $begin_at_step = undef,
30+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
2931
) {
3032
peadm::assert_supported_bolt_version()
3133

@@ -316,6 +318,7 @@
316318
compiler_pool_address => $compiler_pool_address,
317319
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
318320
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
321+
node_group_environment => $node_group_environment,
319322
require => Class['peadm::setup::node_manager_yaml'],
320323
}
321324

plans/convert_compiler_to_legacy.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Peadm::SingleTargetSpec $primary_host,
44
TargetSpec $legacy_hosts,
55
Optional[Boolean] $remove_pdb = true,
6+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
67
) {
78
$primary_target = peadm::get_targets($primary_host, 1)
89
$convert_legacy_compiler_targets = peadm::get_targets($legacy_hosts)
@@ -34,6 +35,7 @@
3435
},
3536
internal_compiler_a_pool_address => getvar('cluster.params.internal_compiler_a_pool_address'),
3637
internal_compiler_b_pool_address => getvar('cluster.params.internal_compiler_b_pool_address'),
38+
node_group_environment => $node_group_environment,
3739
require => Class['peadm::setup::node_manager_yaml'],
3840
}
3941
}

plans/upgrade.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
# for offline usage.
3333
# @param begin_at_step The step where the plan should start. If not set, it will start at the beginning
3434
#
35+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
36+
#
3537
plan peadm::upgrade (
3638
# Standard
3739
Peadm::SingleTargetSpec $primary_host,
@@ -61,6 +63,7 @@
6163
Boolean $permit_unsafe_versions = false,
6264

6365
Optional[Peadm::UpgradeSteps] $begin_at_step = undef,
66+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
6467
) {
6568
# Log parameters for debugging
6669
peadm::log_plan_parameters({
@@ -69,6 +72,7 @@
6972
'compiler_hosts' => $compiler_hosts,
7073
'primary_postgresql_host' => $primary_postgresql_host,
7174
'replica_postgresql_host' => $replica_postgresql_host,
75+
'node_group_environment' => $node_group_environment,
7276
'version' => $version,
7377
})
7478

@@ -361,6 +365,7 @@
361365
compiler_pool_address => $compiler_pool_address,
362366
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
363367
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
368+
node_group_environment => $node_group_environment,
364369
require => Class['peadm::setup::node_manager_yaml'],
365370
}
366371
}

plans/util/update_classification.pp

Lines changed: 4 additions & 0 deletions
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)