Skip to content

Commit b136625

Browse files
authored
Merge pull request #84 from puppetlabs/one-check-to-rule-them-all
Reduce several check tasks down to one
2 parents 763b877 + 9f24023 commit b136625

9 files changed

+55
-75
lines changed

functions/wait_until_service_ready.pp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# A convenience function to help remember port numbers for services and handle
2+
# running the wait_until_service_ready task
3+
function peadm::wait_until_service_ready(
4+
String $service,
5+
TargetSpec $target,
6+
) {
7+
$port = case $service {
8+
'orchestrator-service': { '8143' }
9+
default: { '8140' }
10+
}
11+
12+
run_task('peadm::wait_until_service_ready', $target,
13+
service => $service,
14+
port => $port,
15+
)
16+
}

plans/action/install.pp

+4-12
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,11 @@
330330
)
331331
}
332332

333+
# The puppetserver might be in the middle of a restart after the Puppet run,
334+
# so we check the status by calling the api and ensuring the puppetserver is
335+
# taking requests before proceeding.
333336
run_task('peadm::puppet_runonce', $master_target)
334-
335-
# The puppetserver might be in the middle of a restart so we check the status by calling
336-
# the api and ensuring the puppetserver is taking requests.
337-
ctrl::do_until('limit' => 10) || {
338-
$pe_status = run_task('peadm::check_status', $master_target, service => 'pe-master')
339-
if ($pe_status.first['state'] != 'running') {
340-
ctrl::sleep(5)
341-
false
342-
} else {
343-
true
344-
}
345-
}
337+
peadm::wait_until_service_ready('pe-master', $master_target)
346338

347339
run_task('peadm::puppet_runonce', $all_targets - $master_target)
348340

plans/upgrade.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121

122122
# If in use, wait until orchestrator service is healthy to proceed
123123
if $all_targets.any |$target| { $target.protocol == 'pcp' } {
124-
run_task('peadm::orchestrator_healthcheck', $master_target)
124+
peadm::wait_until_service_ready('orchestrator-service', $master_target)
125125
wait_until_available($all_targets, wait_time => 120)
126126
}
127127

@@ -135,7 +135,7 @@
135135
# The master could restart orchestration services again, in which case we
136136
# would have to wait for nodes to reconnect
137137
if $all_targets.any |$target| { $target.protocol == 'pcp' } {
138-
run_task('peadm::orchestrator_healthcheck', $master_target)
138+
peadm::wait_until_service_ready('orchestrator-service', $master_target)
139139
wait_until_available($all_targets, wait_time => 120)
140140
}
141141

tasks/check_status.json

-13
This file was deleted.

tasks/check_status.sh

-18
This file was deleted.

tasks/orchestrator_healthcheck.json

-8
This file was deleted.

tasks/orchestrator_healthcheck.sh

-22
This file was deleted.

tasks/wait_until_service_ready.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"description": "Return when the orchestrator service is healthy, or timeout after 15 seconds",
3+
"parameters": {
4+
"service": {
5+
"type": "Enum[all, ca, pe-master, orchestrator-service]",
6+
"description": "What service to check. For example: all, pe-master, orchestrator-service"
7+
},
8+
"port": {
9+
"type": "Enum['8140', '8143']",
10+
"description": "Which port to query the status API on"
11+
}
12+
},
13+
"implementations": [
14+
{"name": "wait_until_service_ready.sh", "input_method": "environment"}
15+
]
16+
}

tasks/wait_until_service_ready.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
check() {
4+
if [[ "$PT_service" == 'all' ]]; then
5+
out=$(curl -fks https://localhost:${PT_port}/status/v1/simple)
6+
else
7+
out=$(curl -fks https://localhost:${PT_port}/status/v1/simple/${PT_service})
8+
fi
9+
}
10+
11+
n=0
12+
until [ $n -ge 20 ]
13+
do
14+
check && break
15+
n=$[$n+1]
16+
sleep 3
17+
done

0 commit comments

Comments
 (0)