From 81b584d5a120e76e6a3fce6fed99d02fa95493e9 Mon Sep 17 00:00:00 2001 From: okozachenko Date: Wed, 27 May 2020 23:17:53 +0300 Subject: [PATCH] Add namespace in the collect-k8s-logs role Specify namespace to collect logs, so no need to change the context Change-Id: If26bb9aa517bbd6462fbb93eb6cca99929e7e6aa --- roles/collect-kubernetes-logs/README.rst | 8 +++++++- roles/collect-kubernetes-logs/tasks/main.yaml | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/roles/collect-kubernetes-logs/README.rst b/roles/collect-kubernetes-logs/README.rst index 6213477f7..5717e8574 100755 --- a/roles/collect-kubernetes-logs/README.rst +++ b/roles/collect-kubernetes-logs/README.rst @@ -1 +1,7 @@ -An ansible role to collect all pod descriptions and kubelet logs. +An ansible role to collect all pod descriptions in the current namespace and kubelet logs. + +.. zuul:rolevar:: collect_kubernetes_logs_namespace + + Name of the specified namespace to collect logs. + If not specified explicitly, the namespace in the context + would be used. \ No newline at end of file diff --git a/roles/collect-kubernetes-logs/tasks/main.yaml b/roles/collect-kubernetes-logs/tasks/main.yaml index a8ed08fbf..f183e3aa5 100755 --- a/roles/collect-kubernetes-logs/tasks/main.yaml +++ b/roles/collect-kubernetes-logs/tasks/main.yaml @@ -1,5 +1,5 @@ - name: List pods - command: "kubectl get pod -o=custom-columns=NAME:.metadata.name --no-headers" + command: "kubectl get pod {% if collect_kubernetes_logs_namespace %}-n {{ collect_kubernetes_logs_namespace }}{% endif %} -o=custom-columns=NAME:.metadata.name --no-headers" register: podlist failed_when: false @@ -12,7 +12,7 @@ loop: "{{ podlist.stdout_lines | default([]) }}" loop_control: loop_var: zj_pod_name - shell: "kubectl describe po {{ zj_pod_name }} &> {{ ansible_user_dir }}/zuul-output/logs/pods/{{ zj_pod_name }}.txt" + shell: "kubectl describe po {{ zj_pod_name }} {% if collect_kubernetes_logs_namespace %}-n {{ collect_kubernetes_logs_namespace }}{% endif %} &> {{ ansible_user_dir }}/zuul-output/logs/pods/{{ zj_pod_name }}.txt" args: executable: /bin/bash failed_when: false