Skip to content

Commit 7e72292

Browse files
committed
ci: collect the logs on failure
If the CI test fails, collect the logs to check the failure Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
1 parent 1748098 commit 7e72292

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

.github/workflows/test-charts.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,29 @@ jobs:
7272
./kubernetes/test/bin/e2e.test \
7373
-- \
7474
-storage.testdriver="$(pwd)/test/scripts/k8s-storage/driver-${{ matrix.driver }}.yaml"
75+
76+
- name: Collect logs on failure
77+
if: failure()
78+
run: |
79+
LOG_DIR="${GITHUB_WORKSPACE}/logs-${{ matrix.driver }}"
80+
mkdir -p "${LOG_DIR}"
81+
82+
kubectl get pods --all-namespaces -o wide > "${LOG_DIR}/all-pods.txt" 2>&1 || true
83+
kubectl get events --all-namespaces --sort-by='.lastTimestamp' > "${LOG_DIR}/all-events.txt" 2>&1 || true
84+
kubectl describe pods --all-namespaces > "${LOG_DIR}/all-pods-describe.txt" 2>&1 || true
85+
86+
for ns in $(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}'); do
87+
for pod in $(kubectl get pods -n "${ns}" -o jsonpath='{.items[*].metadata.name}'); do
88+
for container in $(kubectl get pod "${pod}" -n "${ns}" -o jsonpath='{.spec.containers[*].name}'); do
89+
kubectl logs "${pod}" -n "${ns}" -c "${container}" --tail=500 \
90+
> "${LOG_DIR}/${ns}_${pod}_${container}.log" 2>&1 || true
91+
done
92+
done
93+
done
94+
95+
- name: Upload logs on failure
96+
if: failure()
97+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
98+
with:
99+
name: e2e-logs-${{ matrix.driver }}
100+
path: logs-${{ matrix.driver }}

0 commit comments

Comments
 (0)