Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Count "not ready" pods correctly (#37)
Browse files Browse the repository at this point in the history
Some pods (for example, Pending pods) don't have "Ready" condition.
So we can't decide which pods are "not ready" using it.
This patch fixes this issue.

Fixes #34
  • Loading branch information
yuanying authored and superbrothers committed Aug 6, 2018
1 parent 1026bfd commit 32d555c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions assets/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ wait_until_pods_ready() {

echo "Waiting for pods to be ready for ${period}s (interval: ${interval}s, selector: ${selector:-''})"

# The list of "<pod-name> <ready(True|False)>" which is excluded terminating and failed/succeeded pods.
# The list of "<pod-name> <ready(True|False|`null`)>" which is excluded terminating and failed/succeeded pods.
template="$(cat <<EOL
{{- range .items -}}
{{- if and (not .metadata.deletionTimestamp) (ne .status.phase "Failed") (ne .status.phase "Succeeded") -}}
Expand All @@ -154,8 +154,9 @@ EOL
sleep "$interval"

statuses="$(kubectl get po --selector="$selector" -o template --template="$template")"
not_ready="$(echo "$statuses" | grep -c "False" ||:)"
ready="$(echo "$statuses" | grep -c "True" ||:)"
# Some pods don't have "Ready" condition, so we can't determine "not Ready" using "False".
not_ready="$(echo -n "$statuses" | grep -v -c "True" ||:)"
ready="$(echo -n "$statuses" | grep -c "True" ||:)"

echo "Waiting for pods to be ready... ($ready/$((not_ready + ready)))"

Expand All @@ -165,7 +166,7 @@ EOL
done

echo "Waited for ${period}s, but the following pods are not ready yet."
echo "$statuses" | awk '{if ($2 == "False") print "- " $1}'
echo "$statuses" | awk '{if ($2 != "True") print "- " $1}'
return 1
}

Expand Down
9 changes: 9 additions & 0 deletions test/suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ teardown() {
assert_not_equal "<no value>" "${lines[0]}"
assert_success
}

@test "pending pod" {
# Request large resources, so that pod will fall into Pending state
run assets/out <<< "$(jq -n '{"source": {"kubeconfig": $kubeconfig}, "params": {"kubectl": $kubectl}}' \
--arg kubeconfig "$(cat "$kubeconfig_file")" \
--arg kubectl "run nginx --image nginx --requests='cpu=1000'")"
assert_match 'deployment.apps "nginx" created' "$output"
assert_failure
}

0 comments on commit 32d555c

Please sign in to comment.