forked from ansible/awx-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storing each containers log seperately
- also add init container log gathering
- Loading branch information
1 parent
64fb262
commit 1881ae0
Showing
1 changed file
with
49 additions
and
11 deletions.
There are no files selected for viewing
60 changes: 49 additions & 11 deletions
60
molecule/default/utils/output_all_container_logs_for_pod.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,53 @@ | ||
--- | ||
- name: Get all container log in pod | ||
kubernetes.core.k8s_log: | ||
namespace: '{{ namespace }}' | ||
name: '{{ item.metadata.name }}' | ||
all_containers: true | ||
register: all_container_logs | ||
|
||
- name: Store logs in file | ||
ansible.builtin.copy: | ||
content: "{{ all_container_logs.log_lines | join('\n') }}" | ||
dest: '{{ debug_output_dir }}/{{ item.metadata.name }}.log' | ||
- name: Get all container name from pod | ||
set_fact: | ||
container_names: "{{ item.spec.containers | map(attribute='name') | list }}" | ||
when: item.spec.containers is defined | ||
|
||
- name: Get log from all container in pod | ||
block: | ||
- name: Get log from all container in pod | ||
kubernetes.core.k8s_log: | ||
namespace: '{{ namespace }}' | ||
name: '{{ item.metadata.name }}' | ||
container: '{{ container }}' | ||
register: container_log | ||
ignore_errors: true | ||
|
||
- name: Store logs in file | ||
ansible.builtin.copy: | ||
content: "{{ container_log.log_lines | join('\n') }}" | ||
dest: '{{ debug_output_dir }}/{{ item.metadata.name }}-{{ container }}.log' | ||
ignore_errors: true | ||
loop: "{{ container_names }}" | ||
loop_control: | ||
loop_var: container | ||
when: container_names is defined | ||
|
||
- name: Get all init container name from pod if any | ||
set_fact: | ||
init_container_names: "{{ item.spec.initContainers | map(attribute='name') | list }}" | ||
when: item.spec.initContainers is defined | ||
|
||
- name: Get log from all init container in pod | ||
block: | ||
- name: Get log from all init container in pod | ||
kubernetes.core.k8s_log: | ||
namespace: '{{ namespace }}' | ||
name: '{{ item.metadata.name }}' | ||
container: '{{ container }}' | ||
register: container_log | ||
ignore_errors: true | ||
|
||
- name: Store logs in file | ||
ansible.builtin.copy: | ||
content: "{{ container_log.log_lines | join('\n') }}" | ||
dest: '{{ debug_output_dir }}/{{ item.metadata.name }}-{{ container }}.log' | ||
ignore_errors: true | ||
loop: "{{ init_container_names }}" | ||
loop_control: | ||
loop_var: container | ||
when: init_container_names is defined | ||
|
||
# TODO: all_containser option dump all of the output in a single output make it hard to read we probably should iterate through each of the container to get specific logs | ||
# also we should probably investigate toolings to do OpenShift style sosreport/must-gather for kind cluster or switch to microshift where sosreport is supported |