From 8cf5fefe849789282a5d8f22e467d1e6b48966b5 Mon Sep 17 00:00:00 2001 From: tu1h <92532497+tu1h@users.noreply.github.com> Date: Wed, 22 Mar 2023 00:38:12 +0800 Subject: [PATCH] Add download retries option (#9911) Signed-off-by: tu1h --- roles/download/defaults/main.yml | 3 +++ roles/download/tasks/download_container.yml | 4 ++-- roles/download/tasks/download_file.yml | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml index 0ace0d9f2..2a6101383 100644 --- a/roles/download/defaults/main.yml +++ b/roles/download/defaults/main.yml @@ -50,6 +50,9 @@ download_validate_certs: true # Use the first kube_control_plane if download_localhost is not set download_delegate: "{% if download_localhost %}localhost{% else %}{{ groups['kube_control_plane'][0] }}{% endif %}" +# Allow control the times of download retries for files and containers +download_retries: 4 + # The docker_image_info_command might seems weird but we are using raw/endraw and `{{ `{{` }}` to manage the double jinja2 processing docker_image_pull_command: "{{ docker_bin_dir }}/docker pull" docker_image_info_command: "{{ docker_bin_dir }}/docker images -q | xargs -i {{ '{{' }} docker_bin_dir }}/docker inspect -f {% raw %}'{{ '{{' }} if .RepoTags }}{{ '{{' }} join .RepoTags \",\" }}{{ '{{' }} end }}{{ '{{' }} if .RepoDigests }},{{ '{{' }} join .RepoDigests \",\" }}{{ '{{' }} end }}' {% endraw %} {} | tr '\n' ','" diff --git a/roles/download/tasks/download_container.yml b/roles/download/tasks/download_container.yml index 41790fe15..39e0e34c2 100644 --- a/roles/download/tasks/download_container.yml +++ b/roles/download/tasks/download_container.yml @@ -60,7 +60,7 @@ register: pull_task_result until: pull_task_result is succeeded delay: "{{ retry_stagger | random + 3 }}" - retries: 4 + retries: "{{ download_retries }}" become: "{{ user_can_become_root | default(false) or not download_localhost }}" environment: "{{ proxy_env if container_manager == 'containerd' else omit }}" when: @@ -101,7 +101,7 @@ register: upload_image failed_when: not upload_image until: upload_image is succeeded - retries: 4 + retries: "{{ download_retries }}" delay: "{{ retry_stagger | random + 3 }}" when: - pull_required diff --git a/roles/download/tasks/download_file.yml b/roles/download/tasks/download_file.yml index 376a15e8a..ee1eaad70 100644 --- a/roles/download/tasks/download_file.yml +++ b/roles/download/tasks/download_file.yml @@ -64,7 +64,7 @@ run_once: "{{ download_force_cache }}" register: uri_result until: uri_result is success - retries: 4 + retries: "{{ download_retries }}" delay: "{{ retry_stagger | default(5) }}" environment: "{{ proxy_env }}" no_log: "{{ not (unsafe_show_logs|bool) }}" @@ -97,7 +97,7 @@ register: get_url_result become: "{{ not download_localhost }}" until: "'OK' in get_url_result.msg or 'file already exists' in get_url_result.msg" - retries: 4 + retries: "{{ download_retries }}" delay: "{{ retry_stagger | default(5) }}" environment: "{{ proxy_env }}" no_log: "{{ not (unsafe_show_logs|bool) }}" @@ -122,7 +122,7 @@ register: get_task until: get_task is succeeded delay: "{{ retry_stagger | random + 3 }}" - retries: 4 + retries: "{{ download_retries }}" when: - download_force_cache