From 67e2abda5b3b32c92594a3680d6ad0e58169aefd Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Fri, 13 Sep 2019 09:04:36 -0400 Subject: [PATCH] fetch-output-openshift: initial role This change adds a new fetch-output-openshift role to be able to fetch-output from pod. Change-Id: I45d5115a10254432805a02a77e0ebb35d7fd2dd4 --- doc/source/log-roles.rst | 1 + roles/fetch-output-openshift/README.rst | 26 +++++++++++++++++ .../fetch-output-openshift/defaults/main.yaml | 3 ++ roles/fetch-output-openshift/tasks/main.yaml | 29 +++++++++++++++++++ roles/fetch-output-openshift/tasks/rsync.yaml | 19 ++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 roles/fetch-output-openshift/README.rst create mode 100644 roles/fetch-output-openshift/defaults/main.yaml create mode 100644 roles/fetch-output-openshift/tasks/main.yaml create mode 100644 roles/fetch-output-openshift/tasks/rsync.yaml diff --git a/doc/source/log-roles.rst b/doc/source/log-roles.rst index 579a421de..8b2e31a98 100644 --- a/doc/source/log-roles.rst +++ b/doc/source/log-roles.rst @@ -5,6 +5,7 @@ Log Roles .. zuul:autorole:: ara-report .. zuul:autorole:: ensure-output-dirs .. zuul:autorole:: fetch-output +.. zuul:autorole:: fetch-output-openshift .. zuul:autorole:: generate-zuul-manifest .. zuul:autorole:: htmlify-logs .. zuul:autorole:: merge-output-to-logs diff --git a/roles/fetch-output-openshift/README.rst b/roles/fetch-output-openshift/README.rst new file mode 100644 index 000000000..a7ae6b41b --- /dev/null +++ b/roles/fetch-output-openshift/README.rst @@ -0,0 +1,26 @@ +Collect output from build pods + +This role can be used instead of the :zuul:role:`fetch-output` role when the +synchronize module doesn't work with kubectl connection. + +This role requires the origin-client `oc` to be installed. + +**Role Variables** + +.. zuul:rolevar:: zuul_output_dir + :default: {{ ansible_user_dir }}/zuul-output + + Base directory for collecting job output. + +.. zuul:rolevar:: openshift_pods + :default: {{ zuul.resources }} + + The dictionary of pod name, pod information to copy the sources to. + +.. zuul:rolevar:: zuul_log_verbose + :default: false + + The synchronize task in this role outputs a lot of information. By + default, no_log is set to avoid overwhelming a reader of the logs. + Set this to true to disable that behavior if it becomes necessary + to debug this role. diff --git a/roles/fetch-output-openshift/defaults/main.yaml b/roles/fetch-output-openshift/defaults/main.yaml new file mode 100644 index 000000000..14e08d328 --- /dev/null +++ b/roles/fetch-output-openshift/defaults/main.yaml @@ -0,0 +1,3 @@ +openshift_pods: "{{ zuul.resources }}" +zuul_output_dir: "{{ ansible_user_dir }}/zuul-output" +zuul_log_verbose: false diff --git a/roles/fetch-output-openshift/tasks/main.yaml b/roles/fetch-output-openshift/tasks/main.yaml new file mode 100644 index 000000000..28ba3b317 --- /dev/null +++ b/roles/fetch-output-openshift/tasks/main.yaml @@ -0,0 +1,29 @@ +- name: Set log path for multiple nodes + set_fact: + log_path: "{{ zuul.executor.log_root }}/{{ inventory_hostname }}" + when: groups['all'] | length > 1 + +- name: Set log path for single node + set_fact: + log_path: "{{ zuul.executor.log_root }}" + when: log_path is not defined + +- name: Ensure local output dirs + delegate_to: localhost + file: + path: "{{ item }}" + state: directory + with_items: + - "{{ log_path }}" + - "{{ log_path }}/npm" + - "{{ zuul.executor.work_root }}/artifacts" + - "{{ zuul.executor.work_root }}/docs" + +- include_tasks: rsync.yaml + when: item.1.pod is defined + loop: "{{ openshift_pods.items()|list }}" + run_once: true + +- name: Remove empty directory + command: find "{{ zuul.executor.work_root }}" -empty -type d -delete + delegate_to: localhost diff --git a/roles/fetch-output-openshift/tasks/rsync.yaml b/roles/fetch-output-openshift/tasks/rsync.yaml new file mode 100644 index 000000000..394fafa55 --- /dev/null +++ b/roles/fetch-output-openshift/tasks/rsync.yaml @@ -0,0 +1,19 @@ +--- +- name: Fetch zuul-output from the pod + command: > + oc --context "{{ item.1.context }}" + --namespace "{{ item.1.namespace }}" + rsync -q --progress=false + {{ item.1.pod }}:{{ output.src }}/ + {{ output.dst }}/ + no_log: "{{ not zuul_log_verbose }}" + delegate_to: localhost + loop: + - src: "{{ zuul_output_dir }}/logs" + dst: "{{ log_path }}" + - src: "{{ zuul_output_dir }}/artifacts" + dst: "{{ zuul.executor.work_root }}/artifacts" + - src: "{{ zuul_output_dir }}/docs" + dst: "{{ zuul.executor.work_root }}/docs" + loop_control: + loop_var: output