Skip to content

Commit

Permalink
Streamline implementation of optional HA
Browse files Browse the repository at this point in the history
Try to reduce the number of `if` statements in code, and remove the need
to specify `ha` as a Boolean plan parameter. Instead, do HA if HA
systems are specified, and don't if they aren't.
  • Loading branch information
reidmv committed Jul 30, 2019
1 parent 33a300c commit 1396834
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 253 deletions.
87 changes: 36 additions & 51 deletions plans/configure.pp
@@ -1,13 +1,13 @@
# @summary Configure first-time classification and HA setup
#
plan pe_xl::configure (
Boolean $ha = true,
String[1] $master_host,
String[1] $puppetdb_database_host,
String[1] $master_replica_host,
String[1] $puppetdb_database_replica_host,
Array[String[1]] $compiler_hosts = [ ],

Optional[String[1]] $master_replica_host = undef,
Optional[String[1]] $puppetdb_database_replica_host, = undef,

# This parameter exists primarily to enable the use case of running
# pe_xl::configure over the PCP transport. An orchestrator restart happens
# during provision replica. Running `bolt plan run` directly on the master
Expand All @@ -22,6 +22,18 @@
String[1] $stagingdir = '/tmp',
) {

$ha_hosts = [
$master_replica_host,
$puppetdb_database_replica_host,
].pe_xl::flatten_compact()

# Ensure valid input for HA
$ha = $ha_hosts.size ? {
0 => false,
2 => true,
default => fail("Must specify either both or neither of master_replica_host, puppetdb_database_replica_host"),
}

# Allow for the configure task to be run local to the master.
$master_target = $executing_on_master ? {
true => "local://${master_host}",
Expand All @@ -43,43 +55,27 @@

# Set up the console node groups to configure the various hosts in their
# roles
if $ha {
run_task('pe_xl::configure_node_groups', $master_target,
master_host => $master_host,
master_replica_host => $master_replica_host,
puppetdb_database_host => $puppetdb_database_host,
puppetdb_database_replica_host => $puppetdb_database_replica_host,
compiler_pool_address => $compiler_pool_address,
)
} else {
run_task('pe_xl::configure_node_groups', $master_target,
master_host => $master_host,
puppetdb_database_host => $puppetdb_database_host,
compiler_pool_address => $compiler_pool_address,
)
}
run_task('pe_xl::configure_node_groups', $master_target,
master_host => $master_host,
master_replica_host => $master_replica_host,
puppetdb_database_host => $puppetdb_database_host,
puppetdb_database_replica_host => $puppetdb_database_replica_host,
compiler_pool_address => $compiler_pool_address,
)

# Run Puppet in no-op on the compilers so that their status in PuppetDB
# is updated and they can be identified by the puppet_enterprise module as
# CMs
if $ha {
run_task('pe_xl::puppet_runonce', [$compiler_hosts, $master_replica_host],
noop => true,
)
} else {
run_task('pe_xl::puppet_runonce', $compiler_hosts, noop => true)
}
run_task('pe_xl::puppet_runonce', [$compiler_hosts, $master_replica_host].pe_xl::flatten_compact,
noop => true,
)

# Run Puppet on the PuppetDB Database hosts to update their auth
# configuration to allow the compilers to connect
if $ha {
run_task('pe_xl::puppet_runonce', [
$puppetdb_database_host,
$puppetdb_database_replica_host,
])
} else {
run_task('pe_xl::puppet_runonce', $puppetdb_database_host)
}
run_task('pe_xl::puppet_runonce', [
$puppetdb_database_host,
$puppetdb_database_replica_host,
].pe_xl::flatten_compact)

# Run Puppet on the master to ensure all services configured and
# running in prep for provisioning the replica. This is done separately so
Expand All @@ -99,27 +95,16 @@
master_replica => $master_replica_host,
token_file => $token_file,
)

}

# Run Puppet everywhere to pick up last remaining config tweaks
if $ha {
$all_hosts = [
$master_target,
$puppetdb_database_host,
$compiler_hosts,
$master_replica_host,
$puppetdb_database_replica_host,
].pe_xl::flatten_compact()
} else {
$all_hosts = [
$master_target,
$puppetdb_database_host,
$compiler_hosts,
].pe_xl::flatten_compact()
}

run_task('pe_xl::puppet_runonce', $all_hosts)
run_task('pe_xl::puppet_runonce', [
$master_target,
$puppetdb_database_host,
$compiler_hosts,
$master_replica_host,
$puppetdb_database_replica_host,
].pe_xl::flatten_compact)

# Deploy an environment if a deploy environment is specified
if $deploy_environment {
Expand Down
4 changes: 0 additions & 4 deletions plans/init.pp
Expand Up @@ -8,7 +8,6 @@
Boolean $install = false,
Boolean $configure = false,
Boolean $upgrade = false,
Boolean $ha = true,

Optional[String[1]] $master_host = undef,
Optional[String[1]] $puppetdb_database_host = undef,
Expand All @@ -30,7 +29,6 @@

if $install {
run_plan('pe_xl::install',
ha => $ha,
master_host => $master_host,
puppetdb_database_host => $puppetdb_database_host,
master_replica_host => $master_replica_host,
Expand All @@ -48,7 +46,6 @@

if $configure {
run_plan('pe_xl::configure',
ha => $ha,
master_host => $master_host,
puppetdb_database_host => $puppetdb_database_host,
master_replica_host => $master_replica_host,
Expand All @@ -65,7 +62,6 @@

if $upgrade {
run_plan('pe_xl::upgrade',
ha => $ha,
master_host => $master_host,
puppetdb_database_host => $puppetdb_database_host,
master_replica_host => $master_replica_host,
Expand Down

0 comments on commit 1396834

Please sign in to comment.