Skip to content

Commit

Permalink
Merge pull request #90 from vdice/ref/use-helm-wait
Browse files Browse the repository at this point in the history
ref(scripts): tear out wait logic in favor of helm's `--wait` flag
  • Loading branch information
Vaughn Dice authored Mar 14, 2017
2 parents 1daf3a8 + 6ede51d commit fa502b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 134 deletions.
96 changes: 0 additions & 96 deletions scripts/deis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,102 +43,6 @@ clean_cluster() {
fi
}

deis-healthcheck() {
echo "Health check deis until it is completely up!"

wait-for-all-pods "deis"
local successes=0
local failures=0
local max_attempts=10
echo "Checking to see if Workflow has come up properly."
while [[ ${successes} -lt "${max_attempts}" ]] && [[ ${failures} -lt "${max_attempts}" ]]; do
wait-for-router
if [ $? -eq 0 ]; then
let successes+=1
else
let failures+=1
fi

if [ ${successes} -eq ${max_attempts} ]; then
echo "Successfully interacted with Deis platform via '$(get-router-ip)' ${successes} time(s)."
elif [ ${failures} -eq ${max_attempts} ]; then
echo "Failed to interact with Deis platform via '$(get-router-ip)' ${failures} time(s); deleting lease and exiting."
delete-lease
exit 1
fi
sleep 1
done

echo "Use http://grafana.$(get-router-ip).nip.io/ to monitor the e2e run"
}

wait-for-all-pods() {
echo "Waiting for all pods to be running"

local timeout_secs=180
local increment_secs=1
local waited_time=0

local command_output
while [ ${waited_time} -lt ${timeout_secs} ]; do
kubectl get pods --namespace=deis -o json | jq -r '.items[].status.conditions[] | select(.type=="Ready")' | grep -q "False"
if [ $? -gt 0 ]; then
echo
echo "All pods are running!"
return 0
fi

sleep ${increment_secs}
(( waited_time += increment_secs ))

if [ ${waited_time} -ge ${timeout_secs} ]; then
echo "Not all pods started."
kubectl get pods --namespace=deis
delete-lease
exit 1
fi

echo -n . 1>&2
done
}

get-router-ip() {
command_output="$(kubectl --namespace=deis get svc deis-router -o json | jq -r ".status.loadBalancer.ingress[0].ip")"
if [ ! -z "${command_output}" ] && [ "${command_output}" != "null" ]; then
echo "${command_output}"
fi
}

wait-for-router() {
local timeout_secs=30
local increment_secs=1
local waited_time=0
local command_output

while [ ${waited_time} -lt ${timeout_secs} ]; do
router_ip="$(get-router-ip)"

command_output="$(curl -sSL -o /dev/null -w '%{http_code}' "${router_ip}")"
command_exit_code=$?

if [ "${command_output}" == "404" ]; then
return 0
fi

sleep ${increment_secs}
(( waited_time += increment_secs ))

if [ ${waited_time} -ge ${timeout_secs} ]; then
echo "Endpoint is unresponsive at ${router_ip}"
delete-lease
exit 1
fi

echo -n . 1>&2
return ${command_exit_code}
done
}

get-pod-logs() {
pods=$(kubectl get pods --all-namespaces | sed '1d' | awk '{print $1, $2}')
while read -r namespace pod; do
Expand Down
30 changes: 0 additions & 30 deletions scripts/e2e.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/bash

tail_logs_from_e2e_pod() {
echo "Waiting for e2e pod to become ready"
wait-for-pod-ready workflow-e2e
kubectl logs -f --namespace=deis -c tests workflow-e2e
return-pod-exit-code workflow-e2e
return $?
Expand Down Expand Up @@ -30,34 +28,6 @@ return-pod-exit-code() {
return "${exit_code}"
}

wait-for-pod-ready() {
local name="${1}"
local timeout_secs=30
local increment_secs=1
local waited_time=0

while [ ${waited_time} -lt ${timeout_secs} ]; do
test_container_output="$(kubectl get po "${name}" -a --namespace=deis -o json | jq -r --arg container "tests" ".status.containerStatuses[] | select(.name==\$container) | .ready")"
artifact_container_output="$(kubectl get po "${name}" -a --namespace=deis -o json | jq -r --arg container "artifacts" ".status.containerStatuses[] | select(.name==\$container) | .ready")"

if [ "${test_container_output}" == "true" ] && [ "${artifact_container_output}" == "true" ]; then
return 0
fi

sleep ${increment_secs}
(( waited_time += increment_secs ))

if [ ${waited_time} -ge ${timeout_secs} ]; then
echo
echo "workflow-e2e pod was never ready. Test Container:${test_container_output} -- Artifact Container:${artifact_container_output}"
delete-lease
exit 1
fi

echo -n . 1>&2
done
}

wait-for-container-terminated() {
local pod_name="${1}"
local container_name="${2}"
Expand Down
6 changes: 3 additions & 3 deletions scripts/run_e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ chart_repo="$(get-chart-repo workflow "${CHART_REPO_TYPE}")"
echo "Adding workflow chart repo '${chart_repo}'"
helm repo add "${chart_repo}" https://charts.deis.com/"${chart_repo}"

install_cmd="helm install ${chart_repo}/workflow --namespace=deis \
install_cmd="helm install --wait ${chart_repo}/workflow --namespace=deis \
$(set-chart-version workflow) --set controller.registration_mode=enabled $(set-chart-values workflow)"
# TODO: remove this "registration_mode" override when e2e tests expect "admin_only" as the default
# execute in subshell to print full command being run
(set -x; eval "${install_cmd}")

dump-logs && deis-healthcheck
dump-logs

# Add workflow-e2e chart repo and install chart
chart_repo="$(get-chart-repo workflow-e2e "${CHART_REPO_TYPE}")"
echo "Adding workflow-e2e chart repo '${chart_repo}'"
helm repo add "${chart_repo}" https://charts.deis.com/"${chart_repo}"

install_cmd="helm install ${chart_repo}/workflow-e2e --namespace=deis \
install_cmd="helm install --wait ${chart_repo}/workflow-e2e --namespace=deis \
$(set-chart-version workflow-e2e) $(set-chart-values workflow-e2e)"
# execute in subshell to print full command being run
(set -x; eval "${install_cmd}")
Expand Down
10 changes: 5 additions & 5 deletions scripts/run_upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ for chart_repo in ${chart_repos}; do
helm repo add "${chart_repo}" https://charts.deis.com/"${chart_repo}"
done

install_cmd="helm install ${ORIGIN_WORKFLOW_REPO}/workflow --namespace=deis \
install_cmd="helm install --wait ${ORIGIN_WORKFLOW_REPO}/workflow --namespace=deis \
$(set-chart-version workflow) $(set-chart-values workflow)"
# execute in subshell to print full command being run
(set -x; eval "${install_cmd}")
Expand All @@ -20,7 +20,7 @@ $(set-chart-version workflow) $(set-chart-values workflow)"
release="$(helm ls --date --short | tail -n 1)"
helm ls "${release}"

dump-logs && deis-healthcheck
dump-logs

# if off-cluster storage, create state
if [ "${STORAGE_TYPE}" != "" ]; then
Expand All @@ -44,15 +44,15 @@ if [ "${STORAGE_TYPE}" != "" ]; then
fi

# Upgrade release
upgrade_cmd="helm upgrade ${release} ${UPGRADE_WORKFLOW_REPO}/workflow \
upgrade_cmd="helm upgrade --wait ${release} ${UPGRADE_WORKFLOW_REPO}/workflow \
--set controller.registration_mode=enabled $(set-chart-values workflow)"
# TODO: remove this "registration_mode" override when e2e tests expect "admin_only" as the default
# execute in subshell to print full command being run
(set -x; eval "${upgrade_cmd}")

helm ls "${release}"

dump-logs && deis-healthcheck
dump-logs

# Sanity check
kubectl get po --namespace deis
Expand All @@ -78,7 +78,7 @@ if [ "${RUN_E2E}" == true ]; then
helm repo add "${chart_repo}" https://charts.deis.com/"${chart_repo}"

# shellcheck disable=SC2046
helm install "${chart_repo}"/workflow-e2e --namespace=deis \
helm install --wait "${chart_repo}"/workflow-e2e --namespace=deis \
$(set-chart-version workflow-e2e) $(set-chart-values workflow-e2e)

echo "Running kubectl describe pod workflow-e2e and piping the output to ${DEIS_DESCRIBE}"
Expand Down

0 comments on commit fa502b9

Please sign in to comment.