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

Commit 32d555c

Browse files
O. Yuanyingsuperbrothers
O. Yuanying
authored andcommitted
Count "not ready" pods correctly (#37)
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
1 parent 1026bfd commit 32d555c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

assets/common.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ wait_until_pods_ready() {
139139

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

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

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

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

@@ -165,7 +166,7 @@ EOL
165166
done
166167

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

test/suite.bats

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ teardown() {
7171
assert_not_equal "<no value>" "${lines[0]}"
7272
assert_success
7373
}
74+
75+
@test "pending pod" {
76+
# Request large resources, so that pod will fall into Pending state
77+
run assets/out <<< "$(jq -n '{"source": {"kubeconfig": $kubeconfig}, "params": {"kubectl": $kubectl}}' \
78+
--arg kubeconfig "$(cat "$kubeconfig_file")" \
79+
--arg kubectl "run nginx --image nginx --requests='cpu=1000'")"
80+
assert_match 'deployment.apps "nginx" created' "$output"
81+
assert_failure
82+
}

0 commit comments

Comments
 (0)