Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce several check tasks down to one #84

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions functions/wait_until_service_ready.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A convenience function to help remember port numbers for services and handle
# running the wait_until_service_ready task
function peadm::wait_until_service_ready(
String $service,
TargetSpec $target,
) {
$port = case $service {
'orchestrator-service': { '8143' }
default: { '8140' }
}

run_task('peadm::wait_until_service_ready', $target,
service => $service,
port => $port,
)
}
16 changes: 4 additions & 12 deletions plans/action/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -330,19 +330,11 @@
)
}

# The puppetserver might be in the middle of a restart after the Puppet run,
# so we check the status by calling the api and ensuring the puppetserver is
# taking requests before proceeding.
run_task('peadm::puppet_runonce', $master_target)

# The puppetserver might be in the middle of a restart so we check the status by calling
# the api and ensuring the puppetserver is taking requests.
ctrl::do_until('limit' => 10) || {
$pe_status = run_task('peadm::check_status', $master_target, service => 'pe-master')
if ($pe_status.first['state'] != 'running') {
ctrl::sleep(5)
false
} else {
true
}
}
peadm::wait_until_service_ready('pe-master', $master_target)

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

Expand Down
4 changes: 2 additions & 2 deletions plans/upgrade.pp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@

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

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

Expand Down
13 changes: 0 additions & 13 deletions tasks/check_status.json

This file was deleted.

18 changes: 0 additions & 18 deletions tasks/check_status.sh

This file was deleted.

8 changes: 0 additions & 8 deletions tasks/orchestrator_healthcheck.json

This file was deleted.

22 changes: 0 additions & 22 deletions tasks/orchestrator_healthcheck.sh

This file was deleted.

16 changes: 16 additions & 0 deletions tasks/wait_until_service_ready.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "Return when the orchestrator service is healthy, or timeout after 15 seconds",
"parameters": {
"service": {
"type": "Enum[all, ca, pe-master, orchestrator-service]",
"description": "What service to check. For example: all, pe-master, orchestrator-service"
},
"port": {
"type": "Enum['8140', '8143']",
"description": "Which port to query the status API on"
}
},
"implementations": [
{"name": "wait_until_service_ready.sh", "input_method": "environment"}
]
}
17 changes: 17 additions & 0 deletions tasks/wait_until_service_ready.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

check() {
if [[ "$PT_service" == 'all' ]]; then
out=$(curl -fks https://localhost:${PT_port}/status/v1/simple)
else
out=$(curl -fks https://localhost:${PT_port}/status/v1/simple/${PT_service})
fi
}

n=0
until [ $n -ge 20 ]
do
check && break
n=$[$n+1]
sleep 3
done