Skip to content

Commit 428e06c

Browse files
Have jq skip over pods without containerStatuses
A pending pod will not have any containerStatuses as the container has yet to be deployed and this line of code errors with `jq: error (at <stdin>:5): Cannot iterate over null (null)` on any pod with a pending status (in my case because I purposefully made the pod schedulable) on my nodes. Adding the ? will have jq skip over instances that do not have results.
1 parent a034811 commit 428e06c

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
@@ -367,7 +367,7 @@ mode_pods() {
367367
for pod in "${pods[@]}"; do
368368
containers=($(echo "$nsdata" | \
369369
jq -r "select(.metadata.name==\"$pod\") | \
370-
.status.containerStatuses[].name"))
370+
.status.containerStatuses[]?.name"))
371371
for container in "${containers[@]}"; do
372372
restart_count=$(echo "$nsdata" | \
373373
jq -r "select(.metadata.name==\"$pod\") | \

0 commit comments

Comments
 (0)