Skip to content

Commit 2560e75

Browse files
(PE-39789) Support custom environment
Co-authored-by: bastelfreak [email protected]
1 parent 7e680a4 commit 2560e75

File tree

14 files changed

+181
-7
lines changed

14 files changed

+181
-7
lines changed

REFERENCE.md

Lines changed: 64 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`
@@ -2129,6 +2175,7 @@ The following parameters are available in the `peadm::install` plan:
21292175
* [`final_agent_state`](#-peadm--install--final_agent_state)
21302176
* [`stagingdir`](#-peadm--install--stagingdir)
21312177
* [`uploaddir`](#-peadm--install--uploaddir)
2178+
* [`node_group_environment`](#-peadm--install--node_group_environment)
21322179
* [`primary_host`](#-peadm--install--primary_host)
21332180
* [`replica_host`](#-peadm--install--replica_host)
21342181
* [`compiler_hosts`](#-peadm--install--compiler_hosts)
@@ -2229,6 +2276,14 @@ for offline usage.
22292276

22302277
Default value: `undef`
22312278

2279+
##### <a name="-peadm--install--node_group_environment"></a>`node_group_environment`
2280+
2281+
Data type: `String[1]`
2282+
2283+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
2284+
2285+
Default value: `peadm::get_node_group_environment($primary_host)`
2286+
22322287
##### <a name="-peadm--install--primary_host"></a>`primary_host`
22332288

22342289
Data type: `Peadm::SingleTargetSpec`
@@ -2723,6 +2778,7 @@ The following parameters are available in the `peadm::upgrade` plan:
27232778
* [`stagingdir`](#-peadm--upgrade--stagingdir)
27242779
* [`uploaddir`](#-peadm--upgrade--uploaddir)
27252780
* [`begin_at_step`](#-peadm--upgrade--begin_at_step)
2781+
* [`node_group_environment`](#-peadm--upgrade--node_group_environment)
27262782
* [`primary_host`](#-peadm--upgrade--primary_host)
27272783
* [`replica_host`](#-peadm--upgrade--replica_host)
27282784
* [`compiler_hosts`](#-peadm--upgrade--compiler_hosts)
@@ -2819,6 +2875,14 @@ The step where the plan should start. If not set, it will start at the beginning
28192875

28202876
Default value: `undef`
28212877

2878+
##### <a name="-peadm--upgrade--node_group_environment"></a>`node_group_environment`
2879+
2880+
Data type: `String[1]`
2881+
2882+
environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
2883+
2884+
Default value: `peadm::get_node_group_environment($primary_host)`
2885+
28222886
##### <a name="-peadm--upgrade--primary_host"></a>`primary_host`
28232887

28242888
Data type: `Peadm::SingleTargetSpec`
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+
# @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+
function peadm::get_node_group_environment(Peadm::SingleTargetSpec $primary) {
11+
$peconf = peadm::get_pe_conf(get_target($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/add_database.pp

Lines changed: 9 additions & 3 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)
@@ -98,7 +102,7 @@
98102
run_plan('peadm::subplans::component_install', $postgresql_target,
99103
primary_host => $primary_target,
100104
avail_group_letter => $avail_group_letter,
101-
role => 'puppet/puppetdb-database'
105+
role => 'puppet/puppetdb-database',
102106
)
103107
}
104108

@@ -137,13 +141,15 @@
137141
run_plan('peadm::util::update_classification', $primary_target,
138142
postgresql_a_host => $host,
139143
postgresql_b_host => $host,
140-
peadm_config => $peadm_config
144+
peadm_config => $peadm_config,
145+
node_group_environment => $node_group_environment,
141146
)
142147
} else {
143148
run_plan('peadm::util::update_classification', $primary_target,
144149
postgresql_a_host => $avail_group_letter ? { 'A' => $postgresql_host, default => undef },
145150
postgresql_b_host => $avail_group_letter ? { 'B' => $postgresql_host, default => undef },
146-
peadm_config => $peadm_config
151+
peadm_config => $peadm_config,
152+
node_group_environment => $node_group_environment,
147153
)
148154
}
149155
}

plans/add_replica.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
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
11+
#
1012
plan peadm::add_replica(
1113
# Standard or Large
1214
Peadm::SingleTargetSpec $primary_host,
@@ -17,6 +19,7 @@
1719

1820
# Common Configuration
1921
Optional[String] $token_file = undef,
22+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
2023
) {
2124
$primary_target = peadm::get_targets($primary_host, 1)
2225
$replica_target = peadm::get_targets($replica_host, 1)
@@ -96,7 +99,8 @@
9699
server_b_host => $replica_avail_group_letter ? { 'B' => $replica_target.peadm::certname(), default => undef },
97100
internal_compiler_a_pool_address => $replica_avail_group_letter ? { 'A' => $replica_target.peadm::certname(), default => undef },
98101
internal_compiler_b_pool_address => $replica_avail_group_letter ? { 'B' => $replica_target.peadm::certname(), default => undef },
99-
peadm_config => $peadm_config
102+
peadm_config => $peadm_config,
103+
node_group_environment => $node_group_environment,
100104
)
101105

102106
# 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/install.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
# @param uploaddir
3131
# Directory the installer tarball will be uploaded to or expected to be in
3232
# for offline usage.
33+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
3334
#
3435
plan peadm::install (
3536
# Standard
@@ -74,6 +75,7 @@
7475
Peadm::Download_mode $download_mode = 'bolthost',
7576
Boolean $permit_unsafe_versions = false,
7677
String $token_lifetime = '1y',
78+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
7779
) {
7880
# Log parameters for debugging
7981
peadm::log_plan_parameters({
@@ -148,6 +150,7 @@
148150
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
149151
deploy_environment => $deploy_environment,
150152
ldap_config => $ldap_config,
153+
node_group_environment => $node_group_environment,
151154

152155
# Other
153156
stagingdir => $stagingdir,

plans/subplans/configure.pp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# @param final_agent_state
2020
# Configures the state the puppet agent should be in on infrastructure nodes
2121
# after PE is configured successfully.
22+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
2223
#
2324
plan peadm::subplans::configure (
2425
# Standard
@@ -43,7 +44,8 @@
4344

4445
# Other
4546
String $stagingdir = '/tmp',
46-
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),
4749
) {
4850
# TODO: get and validate PE version
4951

@@ -106,6 +108,7 @@
106108
compiler_pool_address => $compiler_pool_address,
107109
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
108110
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
111+
node_group_environment => $node_group_environment,
109112
require => Class['peadm::setup::node_manager_yaml'],
110113
}
111114
}

plans/upgrade.pp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
# Directory the installer tarball will be uploaded to or expected to be in
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
34+
# @param node_group_environment environment for the PEADM specific node groups, if not set it will be gathered from pe.conf or production
3435
#
3536
plan peadm::upgrade (
3637
# Standard
@@ -61,6 +62,7 @@
6162
Boolean $permit_unsafe_versions = false,
6263

6364
Optional[Peadm::UpgradeSteps] $begin_at_step = undef,
65+
String[1] $node_group_environment = peadm::get_node_group_environment($primary_host),
6466
) {
6567
# Log parameters for debugging
6668
peadm::log_plan_parameters({
@@ -361,6 +363,7 @@
361363
compiler_pool_address => $compiler_pool_address,
362364
internal_compiler_a_pool_address => $internal_compiler_a_pool_address,
363365
internal_compiler_b_pool_address => $internal_compiler_b_pool_address,
366+
node_group_environment => $node_group_environment,
364367
require => Class['peadm::setup::node_manager_yaml'],
365368
}
366369
}

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)