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