From e167426aa3e209315717b0e2fdfb3d3a7028ca11 Mon Sep 17 00:00:00 2001 From: RainbowMango Date: Wed, 30 Jun 2021 10:49:56 +0800 Subject: [PATCH] enable log collection for e2e testing Signed-off-by: RainbowMango --- .github/workflows/ci.yml | 8 ++++++++ hack/run-e2e.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 590fd4917076..d62b53c6ff71 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,8 @@ jobs: name: e2e test needs: build runs-on: ubuntu-18.04 + env: + ARTIFACTS_PATH: ${{ github.workspace }}/karmada-e2e-logs/ steps: - name: checkout code uses: actions/checkout@v2 @@ -76,3 +78,9 @@ jobs: run: hack/karmada-bootstrap.sh - name: run e2e run: hack/run-e2e.sh + - name: upload logs + if: always() + uses: actions/upload-artifact@v2 + with: + name: karmada_e2e_log + path: ${{ github.workspace }}/karmada-e2e-logs/ diff --git a/hack/run-e2e.sh b/hack/run-e2e.sh index 8e6ff9ddd77a..47382cac323a 100755 --- a/hack/run-e2e.sh +++ b/hack/run-e2e.sh @@ -16,6 +16,16 @@ KUBECONFIG_PATH=${KUBECONFIG_PATH:-"${HOME}/.kube"} KARMADA_APISERVER_KUBECONFIG=${KARMADA_APISERVER_KUBECONFIG:-"$KUBECONFIG_PATH/karmada.config"} PULL_BASED_CLUSTERS=${PULL_BASED_CLUSTERS:-"member3:$KUBECONFIG_PATH/members.config"} +# KARMADA_RUNNING_ON_KIND indicates if current testing against on karmada that installed on a kind cluster. +# Defaults to true. +# For kind cluster, the kind related logs will be collected after the testing. +KARMADA_RUNNING_ON_KIND=${KARMADA_RUNNING_ON_KIND:-true} + +KARMADA_HOST_CLUSTER_NAME=${KARMADA_HOST_CLUSTER_NAME:-"karmada-host"} + +ARTIFACTS_PATH=${ARTIFACTS_PATH:-"${HOME}/karmada-e2e-logs"} +mkdir -p "$ARTIFACTS_PATH" + # Install ginkgo GO111MODULE=on go install github.com/onsi/ginkgo/ginkgo @@ -23,5 +33,21 @@ GO111MODULE=on go install github.com/onsi/ginkgo/ginkgo export KUBECONFIG=${KARMADA_APISERVER_KUBECONFIG} export PULL_BASED_CLUSTERS=${PULL_BASED_CLUSTERS} +set +e ginkgo -v -race -failFast ./test/e2e/ +TESTING_RESULT=$? + +# Collect logs +echo "Collect logs to $ARTIFACTS_PATH..." +cp "$KARMADA_APISERVER_KUBECONFIG" "$ARTIFACTS_PATH" + +if [ "$KARMADA_RUNNING_ON_KIND" = true ]; then + echo "Collecting $KARMADA_HOST_CLUSTER_NAME logs..." + mkdir -p "$ARTIFACTS_PATH/$KARMADA_HOST_CLUSTER_NAME" + kind export logs --name="$KARMADA_HOST_CLUSTER_NAME" "$ARTIFACTS_PATH/$KARMADA_HOST_CLUSTER_NAME" +fi + +echo "Collected logs at $ARTIFACTS_PATH:" +ls -al "$ARTIFACTS_PATH" +exit $TESTING_RESULT