zuul-jobs/roles/collect-kubernetes-logs/tasks/main.yaml
Clark Boylan b16fae463e Bump the default ensure-kubernetes microk8s version to 1.31/stable
Previously we pinned to 1.28/stable due to a bug that prevented
1.29/stable from working. Now we've hit a new issue with 1.28/stable on
bookworm. The fix for that appears to simply be to upgrade to
1.31/stable so we do so here. More details can be found in this GitHub
issue:

  https://github.com/canonical/microk8s/issues/4361

The new version appears to return from the snap installation before the
k8s installation is fully ready to deal with add-on installation. This
occasionally produces errors like:

  subprocess.CalledProcessError:
  Command '('/snap/microk8s/7178/microk8s-kubectl.wrapper', 'get',
            'all,ingress', '--all-namespaces')'
  returned non-zero exit status 1.

Work around that with `microk8s status --wait-ready` to ensure that k8s
is up before adding addons.

While we are at it we also update the collect-kubernetes-logs role to
collect microk8s inspect output as that would've enabled us to debug the
above issue without holding nodes. We also update test jobs to trigger
when the collect-kubernetes-logs and collect-container-logs roles are
updated to ensure we get coverage from those jobs when updating these
roles.

Change-Id: I60022ec6468c2cadd723a71bbc583f20096b27dc
2024-09-17 15:04:05 -07:00

61 lines
2.0 KiB
YAML
Executable File

- name: List pods
command: "kubectl get pod {% if collect_kubernetes_logs_namespace is defined %}-n {{ collect_kubernetes_logs_namespace }}{% endif %} -o=custom-columns=NAME:.metadata.name --no-headers"
register: podlist
failed_when: false
- name: Create pod describe dir
file:
path: "{{ ansible_user_dir }}/zuul-output/logs/pods"
state: directory
mode: 0755
- name: Save pod descriptions
loop: "{{ podlist.stdout_lines | default([]) }}"
loop_control:
loop_var: zj_pod_name
shell: "kubectl describe po {{ zj_pod_name }} {% if collect_kubernetes_logs_namespace is defined %}-n {{ collect_kubernetes_logs_namespace }}{% endif %} &> {{ ansible_user_dir }}/zuul-output/logs/pods/{{ zj_pod_name }}.txt"
args:
executable: /bin/bash
failed_when: false
- name: Open pod descriptions permissions
file:
dest: "{{ ansible_user_dir }}/zuul-output/logs/pods"
mode: u=rwX,g=rX,o=rX
recurse: yes
- name: Create kubelet log dir
file:
path: "{{ ansible_user_dir }}/zuul-output/logs/kubelet"
state: directory
mode: 0755
- name: Save kubelet logs
shell: "journalctl -u kubelet &> {{ ansible_user_dir }}/zuul-output/logs/kubelet/kubelet.txt"
args:
executable: /bin/bash
failed_when: false
become: yes
- name: Open kubelet logs permissions
file:
dest: "{{ ansible_user_dir }}/zuul-output/logs/kubelet"
mode: u=rwX,g=rX,o=rX
recurse: yes
- name: Collect microk8s inspect tarball
shell: |
set -x -o pipefail
# The microk8s snap isnt in path by default on debian (it is on ubuntu)
export PATH=/snap/bin:$PATH
if type -p microk8s ; then
mkdir {{ ansible_user_dir }}/zuul-output/logs/microk8s
INSPECT_TARBALL="$(microk8s inspect | tee {{ ansible_user_dir }}/zuul-output/logs/microk8s/inspect.log | grep ' Report tarball is at' | cut -d' ' -f7)"
if [[ -n "$INSPECT_TARBALL" ]] ; then
cp $INSPECT_TARBALL {{ ansible_user_dir }}/zuul-output/logs/microk8s/
fi
fi
args:
executable: /bin/bash
failed_when: false