From c8c90ee523d30723d9710f5775ae4ee75fea3db1 Mon Sep 17 00:00:00 2001 From: andreagalle Date: Wed, 12 Apr 2023 13:27:36 +0000 Subject: [PATCH 1/4] checking for the MaxAttempts=5 too at service level --- tests/5_container_runtime.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index bd9564b..a38589d 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -595,9 +595,19 @@ check_5_14() { fail=0 maxretry_unset_containers="" for c in $containers; do - policy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") + for s in $(docker service ls --format '{{.Name}}'); do + if docker inspect "$c" --format '{{.Name}}' | grep -q "$s"; then + task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}') + # a container name could arbitrary include a service one: it belongs to a service (created by Docker + # as part of the service), if the container task ID matches one of the task IDs of the service. + if docker service ps --no-trunc "$s" --format '{{.ID}}' | grep -q "$task_id"; then + spolicy=$(docker inspect --format MaximumRetryCount='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") + fi + fi + done + cpolicy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") - if [ "$policy" != "MaximumRetryCount=5" ]; then + if [ "$cpolicy" != "MaximumRetryCount=5" ] || [ "$spolicy" != "MaxAttempts=5" ]; then # If it's the first container, fail the test if [ $fail -eq 0 ]; then warn -s "$check" From f97b420af91106e0f671eee467bbb17ceeb703ac Mon Sep 17 00:00:00 2001 From: andreagalle Date: Wed, 12 Apr 2023 14:46:13 +0000 Subject: [PATCH 2/4] couple typos & performance improvements --- tests/5_container_runtime.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index a38589d..db4ea28 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -595,19 +595,21 @@ check_5_14() { fail=0 maxretry_unset_containers="" for c in $containers; do - for s in $(docker service ls --format '{{.Name}}'); do - if docker inspect "$c" --format '{{.Name}}' | grep -q "$s"; then + container_name=$(docker inspect "$c" --format '{{.Name}}') +q for s in $(docker service ls --format '{{.Name}}'); do + if echo $container_name | grep -q "$s"; then task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}') # a container name could arbitrary include a service one: it belongs to a service (created by Docker # as part of the service), if the container task ID matches one of the task IDs of the service. if docker service ps --no-trunc "$s" --format '{{.ID}}' | grep -q "$task_id"; then - spolicy=$(docker inspect --format MaximumRetryCount='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") + spolicy=$(docker inspect --format MaxAttempts='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") + break fi fi done cpolicy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") - if [ "$cpolicy" != "MaximumRetryCount=5" ] || [ "$spolicy" != "MaxAttempts=5" ]; then + if [ "$cpolicy" != "MaximumRetryCount=5" ] && [ "$spolicy" != "MaxAttempts=5" ]; then # If it's the first container, fail the test if [ $fail -eq 0 ]; then warn -s "$check" From 412f514bb4bff5e29fe5d526903aa936af66215a Mon Sep 17 00:00:00 2001 From: andreagalle Date: Wed, 12 Apr 2023 14:51:01 +0000 Subject: [PATCH 3/4] just a typo --- tests/5_container_runtime.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index db4ea28..acb8bac 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -596,7 +596,7 @@ check_5_14() { maxretry_unset_containers="" for c in $containers; do container_name=$(docker inspect "$c" --format '{{.Name}}') -q for s in $(docker service ls --format '{{.Name}}'); do + for s in $(docker service ls --format '{{.Name}}'); do if echo $container_name | grep -q "$s"; then task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}') # a container name could arbitrary include a service one: it belongs to a service (created by Docker From 0dc2d2b1e6e32112d061a075da7610082678e63f Mon Sep 17 00:00:00 2001 From: andreagalle Date: Wed, 26 Apr 2023 07:04:53 +0000 Subject: [PATCH 4/4] should fix the: Error response from daemon: This node is not a swarm manager. issue --- tests/5_container_runtime.sh | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index acb8bac..7f6fa1a 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -596,17 +596,19 @@ check_5_14() { maxretry_unset_containers="" for c in $containers; do container_name=$(docker inspect "$c" --format '{{.Name}}') - for s in $(docker service ls --format '{{.Name}}'); do - if echo $container_name | grep -q "$s"; then - task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}') - # a container name could arbitrary include a service one: it belongs to a service (created by Docker - # as part of the service), if the container task ID matches one of the task IDs of the service. - if docker service ps --no-trunc "$s" --format '{{.ID}}' | grep -q "$task_id"; then - spolicy=$(docker inspect --format MaxAttempts='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") - break + if [ "$(docker info --format '{{.Swarm.LocalNodeState}}')" = "active" ]; then + for s in $(docker service ls --format '{{.Name}}'); do + if echo $container_name | grep -q "$s"; then + task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}') + # a container name could arbitrary include a service one: it belongs to a service (created by Docker + # as part of the service), if the container task ID matches one of the task IDs of the service. + if docker service ps --no-trunc "$s" --format '{{.ID}}' | grep -q "$task_id"; then + spolicy=$(docker inspect --format MaxAttempts='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") + break + fi fi - fi - done + done + fi cpolicy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") if [ "$cpolicy" != "MaximumRetryCount=5" ] && [ "$spolicy" != "MaxAttempts=5" ]; then