From 7b6ff769f03e98cb4fe42c36415177cf79643779 Mon Sep 17 00:00:00 2001 From: Max Gautier Date: Thu, 12 Jun 2025 15:59:48 +0200 Subject: [PATCH] CI: 020_check_pods -> more readable output Filter pod to describe / logs only the broken ones. --- tests/testcases/020_check-pods-running.yml | 46 +++++++++++++++------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/testcases/020_check-pods-running.yml b/tests/testcases/020_check-pods-running.yml index bde1a6198..ec2025137 100644 --- a/tests/testcases/020_check-pods-running.yml +++ b/tests/testcases/020_check-pods-running.yml @@ -6,18 +6,34 @@ command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide" changed_when: false -- name: Check that all pods are running and ready - command: "{{ bin_dir }}/kubectl get pods --all-namespaces --no-headers -o yaml" - changed_when: false - register: run_pods_log - until: - # Check that all pods are running - - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]' - # Check that all pods are ready - - '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min' - retries: 30 - delay: 10 - -- name: Check kubectl output - command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide" - changed_when: false +- name: Check pods + vars: + query_pods_not_running: "items[?status.phase != 'Running']" + query_pods_not_ready: "items[?(status.conditions[?type == 'Ready'])[0].status != 'True']" + pods_not_running: "{{ run_pods_log.stdout | from_json | json_query(query_pods_not_running + '.metadata') }}" + pods_not_ready: "{{ run_pods_log.stdout | from_json | json_query(query_pods_not_ready + '.metadata') }}" + block: + - name: Check that all pods are running + command: "{{ bin_dir }}/kubectl get pods --all-namespaces -o json" + register: run_pods_log + changed_when: false + until: + # Check that all pods are running + - run_pods_log.stdout | from_json | json_query(query_pods_not_running) == [] + # Check that all pods are ready + - run_pods_log.stdout | from_json | json_query(query_pods_not_ready) == [] + retries: 30 + delay: 10 + rescue: + - name: Describe broken pods + command: "{{ bin_dir }}/kubectl describe pod -n {{ item.namespace }} {{ item.name }}" + loop: "{{ pods_not_running + pods_not_ready }}" + loop_control: + label: "{{ item.namespace }}/{{ item.name }}" + - name: Get logs from broken pods + command: "{{ bin_dir }}/kubectl logs -n {{ item.namespace }} {{ item.pod }}" + loop: "{{ pods_not_running + pods_not_ready }}" + loop_control: + label: "{{ item.namespace }}/{{ item.name }}" + - name: Fail CI + fail: {}