Skip to content

Commit 2d2c2ef

Browse files
committed
Reset max_restart_count for every container
The `max_restart_count`-variable is not reset when iterating over the pods: A Pod restarted three times: ``` > k get pods -n foo NAME READY STATUS RESTARTS AGE grove-0 1/1 Running 3 (46h ago) 46h ``` When checking the namespace directly, the check returns the correct result: ``` > './check_kubernetes.sh' '-H' 'https://xxxxxxxxxxx.io:443' '-T' $TOKEN '-c' '10' '-m' 'pods' '-w' '1' -N foo WARNING. 25 pods ready, 0 pods succeeded, 0 pods not ready Container foo/bar/grove: 3 restarts. ``` However when running on all namespaces, where other restarted pods are found, the grove-pod isn't displayed: ``` > './check_kubernetes.sh' '-H' 'https://xxxxxxxxxxx.io:443' '-T' $TOKEN '-c' '10' '-m' 'pods' '-w' '1' WARNING. 84 pods ready, 7 pods succeeded, 0 pods not ready Container kube-system/microsoft-defender-collector-ds-jbj8n/microsoft-defender-pod-collector: 1 restarts. Container mgmt/defectdojo-django-7879d4d8d8-s4qr8/uwsgi: 5 restarts. Container mgmt/defectdojo-django-7879d4d8d8-s4qr8/uwsgi: 3 restarts. ``` With the proposed change, it works: ``` > './check_kubernetes.sh' '-H' 'https://xxxxxxxxxxxx.io:443' '-T' $TOKEN '-c' '10' '-m' 'pods' '-w' '1' WARNING. 84 pods ready, 7 pods succeeded, 0 pods not ready Container kube-system/microsoft-defender-collector-ds-jbj8n/microsoft-defender-pod-collector: 1 restarts. Container mgmt/defectdojo-django-7879d4d8d8-s4qr8/uwsgi: 5 restarts. Container foo/bar/grove: 3 restarts. ```
1 parent 53cbf8a commit 2d2c2ef

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

check_kubernetes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ mode_pods() {
373373
count_ready=0
374374
count_succeeded=0
375375
count_failed=0
376-
max_restart_count=0
377376
bad_container=""
378377
data=$(getJSON "api/v1$api_ns/pods/")
379378
[ $? -gt 0 ] && die "$data"
@@ -406,6 +405,7 @@ mode_pods() {
406405
jq -r "select(.metadata.name==\"$pod\") | \
407406
.status.containerStatuses[]?.name"))
408407
for container in "${containers[@]}"; do
408+
max_restart_count=0
409409
restart_count=$(echo "$nsdata" | \
410410
jq -r "select(.metadata.name==\"$pod\") | \
411411
.status.containerStatuses[] | \

0 commit comments

Comments
 (0)