Skip to content

Commit 820abe9

Browse files
authored
Merge pull request #539 from konstruktoid/issue538
check if restart policy is 5 or less
2 parents ba0b402 + e680ab2 commit 820abe9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

tests/5_container_runtime.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,27 +617,29 @@ check_5_15() {
617617
for s in $(docker service ls --format '{{.Name}}'); do
618618
if echo $container_name | grep -q "$s"; then
619619
task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}')
620-
# a container name could arbitrary include a service one: it belongs to a service (created by Docker
620+
# a container name could arbitrary include a service one: it belongs to a service (created by Docker
621621
# as part of the service), if the container task ID matches one of the task IDs of the service.
622622
if docker service ps --no-trunc "$s" --format '{{.ID}}' | grep -q "$task_id"; then
623-
spolicy=$(docker inspect --format MaxAttempts='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s")
623+
restart_policy=$(docker inspect --format '{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s")
624624
break
625625
fi
626626
fi
627627
done
628628
fi
629-
cpolicy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c")
629+
if docker inspect --format '{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c" &>/dev/null; then
630+
restart_policy=$(docker inspect --format '{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c")
631+
fi
630632

631-
if [ "$cpolicy" != "MaximumRetryCount=5" ] && [ "$spolicy" != "MaxAttempts=5" ]; then
633+
if [ "$restart_policy" -gt "5" ]; then
632634
# If it's the first container, fail the test
633635
if [ $fail -eq 0 ]; then
634636
warn -s "$check"
635-
warn " * MaximumRetryCount is not set to 5: $c"
637+
warn " * MaximumRetryCount is not set to 5 or less: $c"
636638
maxretry_unset_containers="$maxretry_unset_containers $c"
637639
fail=1
638640
continue
639641
fi
640-
warn " * MaximumRetryCount is not set to 5: $c"
642+
warn " * MaximumRetryCount is not set to 5 or less: $c"
641643
maxretry_unset_containers="$maxretry_unset_containers $c"
642644
fi
643645
done
@@ -647,7 +649,7 @@ check_5_15() {
647649
logcheckresult "PASS"
648650
return
649651
fi
650-
logcheckresult "WARN" "Containers with MaximumRetryCount not set to 5" "$maxretry_unset_containers"
652+
logcheckresult "WARN" "Containers with MaximumRetryCount not set to 5 or less" "$maxretry_unset_containers"
651653
}
652654

653655
check_5_16() {

0 commit comments

Comments
 (0)