Add role for collecting pods logs
Change-Id: I83f86839d15e61f815428ff7218b2a0a685c6791 Co-Authored-By: Radosław Piliszek <rpiliszek@7bulls.com>
This commit is contained in:
parent
73570b3859
commit
51027a94d5
3
playbooks/kubernetes/post.yaml
Normal file
3
playbooks/kubernetes/post.yaml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- collect-kubernetes-pods-logs
|
2
roles/collect-kubernetes-pods-logs/defaults/main.yaml
Normal file
2
roles/collect-kubernetes-pods-logs/defaults/main.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
collect_kubernetes_pods_logs_all_namespaces: false
|
||||||
|
collect_kubernetes_pods_logs_namespaces: [""]
|
@ -0,0 +1,19 @@
|
|||||||
|
- name: List pods for namespace
|
||||||
|
command: "kubectl get pod {% if namespace != '' %}-n {{ namespace }}{% endif %} -o=custom-columns=NAME:.metadata.name --no-headers"
|
||||||
|
register: zj_pods
|
||||||
|
failed_when: false
|
||||||
|
|
||||||
|
- name: Create pods logs dir for namespace
|
||||||
|
file:
|
||||||
|
path: "{{ ansible_user_dir }}/zuul-output/logs/pods_logs/{{ namespace }}"
|
||||||
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: Save pods logs for namespace
|
||||||
|
loop: "{{ zj_pods.stdout_lines | default([]) }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: zj_pod_name
|
||||||
|
shell: "kubectl logs {{ zj_pod_name }} --all-containers=true {% if namespace != '' %}-n {{ namespace }}{% endif %} &> {{ ansible_user_dir }}/zuul-output/logs/pods_logs/{{ namespace }}/{{ zj_pod_name }}.txt"
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
failed_when: false
|
30
roles/collect-kubernetes-pods-logs/tasks/main.yaml
Normal file
30
roles/collect-kubernetes-pods-logs/tasks/main.yaml
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
- name: Create pods logs dir
|
||||||
|
file:
|
||||||
|
path: "{{ ansible_user_dir }}/zuul-output/logs/pods_logs"
|
||||||
|
state: directory
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: List namespaces
|
||||||
|
command: "kubectl get namespaces -o=custom-columns=NAME:.metadata.name --no-headers"
|
||||||
|
register: zj_kubectl_get_namespaces
|
||||||
|
failed_when: false
|
||||||
|
when: collect_kubernetes_pods_logs_all_namespaces
|
||||||
|
|
||||||
|
- name: Save namespaces to a fact
|
||||||
|
set_fact:
|
||||||
|
collect_kubernetes_pods_logs_namespaces: "{{ zj_kubectl_get_namespaces.stdout_lines }}"
|
||||||
|
when: collect_kubernetes_pods_logs_all_namespaces
|
||||||
|
|
||||||
|
- name: Collect pods logs for namespace
|
||||||
|
include_tasks: collect-pods-logs-for-namespace.yaml
|
||||||
|
vars:
|
||||||
|
namespace: "{{ zj_namespace }}"
|
||||||
|
loop: "{{ collect_kubernetes_pods_logs_namespaces }}"
|
||||||
|
loop_control:
|
||||||
|
loop_var: zj_namespace
|
||||||
|
|
||||||
|
- name: Open pods logs permissions
|
||||||
|
file:
|
||||||
|
dest: "{{ ansible_user_dir }}/zuul-output/logs/pods_logs"
|
||||||
|
mode: u=rwX,g=rX,o=rX
|
||||||
|
recurse: true
|
@ -22,6 +22,7 @@
|
|||||||
roles:
|
roles:
|
||||||
- zuul: zuul/zuul-jobs
|
- zuul: zuul/zuul-jobs
|
||||||
pre-run: playbooks/helm/pre.yaml
|
pre-run: playbooks/helm/pre.yaml
|
||||||
|
post-run: playbooks/kubernetes/post.yaml
|
||||||
vars:
|
vars:
|
||||||
helm_version: *helm_version
|
helm_version: *helm_version
|
||||||
kubernetes_runtime: cri-o
|
kubernetes_runtime: cri-o
|
||||||
|
Loading…
Reference in New Issue
Block a user