run_e2e.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. # Copyright 2018 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. # Shutdown the tests gracefully then save the results
  19. shutdown () {
  20. E2E_SUITE_PID=$(pgrep e2e.test)
  21. echo "sending TERM to ${E2E_SUITE_PID}"
  22. kill -s TERM "${E2E_SUITE_PID}"
  23. # Kind of a hack to wait for this pid to finish.
  24. # Since it's not a child of this shell we cannot use wait.
  25. tail --pid "${E2E_SUITE_PID}" -f /dev/null
  26. saveResults
  27. }
  28. saveResults() {
  29. cd "${RESULTS_DIR}" || exit
  30. tar -czf e2e.tar.gz ./*
  31. # mark the done file as a termination notice.
  32. echo -n "${RESULTS_DIR}/e2e.tar.gz" > "${RESULTS_DIR}/done"
  33. }
  34. # We get the TERM from kubernetes and handle it gracefully
  35. trap shutdown TERM
  36. ginkgo_args=()
  37. if [[ -n ${E2E_DRYRUN:-} ]]; then
  38. ginkgo_args+=("--dryRun=true")
  39. fi
  40. case ${E2E_PARALLEL} in
  41. 'y'|'Y'|'true')
  42. # The flag '--p' will automatically detect the optimal number of ginkgo nodes.
  43. ginkgo_args+=("--p")
  44. # Skip serial tests if parallel mode is enabled.
  45. E2E_SKIP="\\[Serial\\]|${E2E_SKIP}" ;;
  46. esac
  47. ginkgo_args+=(
  48. "--focus=${E2E_FOCUS}"
  49. "--skip=${E2E_SKIP}"
  50. "--noColor=true"
  51. )
  52. set -x
  53. /usr/local/bin/ginkgo "${ginkgo_args[@]}" /usr/local/bin/e2e.test -- --disable-log-dump --repo-root=/kubernetes --provider="${E2E_PROVIDER}" --report-dir="${RESULTS_DIR}" --kubeconfig="${KUBECONFIG}" | tee "${RESULTS_DIR}"/e2e.log &
  54. set +x
  55. # $! is the pid of tee, not ginkgo
  56. wait "$(pgrep ginkgo)" && ret=0 || ret=$?
  57. saveResults
  58. exit ${ret}