Skip to content

Commit

Permalink
Add logging and event collection for failed integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: Helber Belmiro <[email protected]>
  • Loading branch information
hbelmiro authored and openshift-merge-bot[bot] committed Nov 14, 2024
1 parent 166893d commit 6209cac
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 34 deletions.
58 changes: 58 additions & 0 deletions .github/scripts/tests/collect_logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

set -e

DSPA_NS=""
DSPO_NS=""

while [[ "$#" -gt 0 ]]; do
case $1 in
--dspa-ns) DSPA_NS="$2"; shift ;;
--dspo-ns) DSPO_NS="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done

if [[ -z "$DSPA_NS" || -z "$DSPO_NS" ]]; then
echo "Both --dspa-ns and --dspo-ns parameters are required."
exit 1
fi

function check_namespace {
if ! kubectl get namespace "$1" &>/dev/null; then
echo "Namespace '$1' does not exist."
exit 1
fi
}

function display_pod_info {
local NAMESPACE=$1
local POD_NAMES

POD_NAMES=$(kubectl -n "${DSPA_NS}" get pods -o custom-columns=":metadata.name")

if [[ -z "${POD_NAMES}" ]]; then
echo "No pods found in namespace '${NAMESPACE}'."
return
fi

for POD_NAME in ${POD_NAMES}; do
echo "===== Pod: ${POD_NAME} in ${NAMESPACE} ====="

echo "----- EVENTS -----"
kubectl describe pod "${POD_NAME}" -n "${NAMESPACE}" | grep -A 100 Events || echo "No events found for pod ${POD_NAME}."

echo "----- LOGS -----"
kubectl logs "${POD_NAME}" -n "${NAMESPACE}" || echo "No logs found for pod ${POD_NAME}."

echo "==========================="
echo ""
done
}

check_namespace "$DSPA_NS"
check_namespace "$DSPO_NS"

display_pod_info "$DSPA_NS"
display_pod_info "$DSPO_NS"
36 changes: 2 additions & 34 deletions .github/workflows/kind-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,39 +55,7 @@ jobs:

- name: Collect events and logs
if: steps.test.outcome != 'success'
working-directory: ${{ github.workspace }}/.github/scripts/tests
run: |
kubectl -n test-dspa get pods
kubectl -n opendatahub get pods
POD_NAMES=$(kubectl -n test-dspa get pods -o custom-columns=":metadata.name")
for POD_NAME in ${POD_NAMES}; do
echo "===== Pod: ${POD_NAME} ====="
echo "----- EVENTS -----"
kubectl describe pod ${POD_NAME} -n test-dspa | grep -A 100 Events
echo "----- LOGS -----"
kubectl logs ${POD_NAME} -n test-dspa
echo "==========================="
echo ""
done
POD_NAMES=$(kubectl -n opendatahub get pods -o custom-columns=":metadata.name")
for POD_NAME in ${POD_NAMES}; do
echo "===== Pod: ${POD_NAME} ====="
echo "----- EVENTS -----"
kubectl describe pod ${POD_NAME} -n opendatahub | grep -A 100 Events
echo "----- LOGS -----"
kubectl logs ${POD_NAME} -n opendatahub
echo "==========================="
echo ""
done
./collect_logs.sh --dspa-ns test-dspa --dspo-ns opendatahub
exit 1

0 comments on commit 6209cac

Please sign in to comment.