ginkgo-e2e.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #!/usr/bin/env bash
  2. # Copyright 2014 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. # This script runs e2e tests on Google Cloud Platform.
  16. # Usage: `hack/ginkgo-e2e.sh`.
  17. set -o errexit
  18. set -o nounset
  19. set -o pipefail
  20. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  21. source "${KUBE_ROOT}/cluster/common.sh"
  22. source "${KUBE_ROOT}/hack/lib/init.sh"
  23. # Find the ginkgo binary build as part of the release.
  24. ginkgo=$(kube::util::find-binary "ginkgo")
  25. e2e_test=$(kube::util::find-binary "e2e.test")
  26. # --- Setup some env vars.
  27. GINKGO_PARALLEL=${GINKGO_PARALLEL:-n} # set to 'y' to run tests in parallel
  28. CLOUD_CONFIG=${CLOUD_CONFIG:-""}
  29. # If 'y', Ginkgo's reporter will not print out in color when tests are run
  30. # in parallel
  31. GINKGO_NO_COLOR=${GINKGO_NO_COLOR:-n}
  32. # If 'y', will rerun failed tests once to give them a second chance.
  33. GINKGO_TOLERATE_FLAKES=${GINKGO_TOLERATE_FLAKES:-n}
  34. : "${KUBECTL:="${KUBE_ROOT}/cluster/kubectl.sh"}"
  35. : "${KUBE_CONFIG_FILE:="config-test.sh"}"
  36. export KUBECTL KUBE_CONFIG_FILE
  37. source "${KUBE_ROOT}/cluster/kube-util.sh"
  38. function detect-master-from-kubeconfig() {
  39. export KUBECONFIG=${KUBECONFIG:-$DEFAULT_KUBECONFIG}
  40. local cc
  41. cc=$("${KUBE_ROOT}/cluster/kubectl.sh" config view -o jsonpath="{.current-context}")
  42. if [[ -n "${KUBE_CONTEXT:-}" ]]; then
  43. cc="${KUBE_CONTEXT}"
  44. fi
  45. local cluster
  46. cluster=$("${KUBE_ROOT}/cluster/kubectl.sh" config view -o jsonpath="{.contexts[?(@.name == \"${cc}\")].context.cluster}")
  47. KUBE_MASTER_URL=$("${KUBE_ROOT}/cluster/kubectl.sh" config view -o jsonpath="{.clusters[?(@.name == \"${cluster}\")].cluster.server}")
  48. }
  49. # ---- Do cloud-provider-specific setup
  50. if [[ -n "${KUBERNETES_CONFORMANCE_TEST:-}" ]]; then
  51. echo "Conformance test: not doing test setup."
  52. KUBERNETES_PROVIDER=${KUBERNETES_CONFORMANCE_PROVIDER:-"skeleton"}
  53. detect-master-from-kubeconfig
  54. auth_config=(
  55. "--kubeconfig=${KUBECONFIG}"
  56. )
  57. else
  58. echo "Setting up for KUBERNETES_PROVIDER=\"${KUBERNETES_PROVIDER}\"."
  59. prepare-e2e
  60. detect-master >/dev/null
  61. KUBE_MASTER_URL="${KUBE_MASTER_URL:-}"
  62. if [[ -z "${KUBE_MASTER_URL:-}" && -n "${KUBE_MASTER_IP:-}" ]]; then
  63. KUBE_MASTER_URL="https://${KUBE_MASTER_IP}"
  64. fi
  65. auth_config=(
  66. "--kubeconfig=${KUBECONFIG:-$DEFAULT_KUBECONFIG}"
  67. )
  68. fi
  69. if [[ -n "${NODE_INSTANCE_PREFIX:-}" ]]; then
  70. NODE_INSTANCE_GROUP="${NODE_INSTANCE_PREFIX}-group"
  71. fi
  72. if [[ "${KUBERNETES_PROVIDER}" == "gce" ]]; then
  73. set_num_migs
  74. NODE_INSTANCE_GROUP=""
  75. for ((i=1; i<=NUM_MIGS; i++)); do
  76. if [[ ${i} == "${NUM_MIGS}" ]]; then
  77. # We are assigning the same mig names as create-nodes function from cluster/gce/util.sh.
  78. NODE_INSTANCE_GROUP="${NODE_INSTANCE_GROUP}${NODE_INSTANCE_PREFIX}-group"
  79. else
  80. NODE_INSTANCE_GROUP="${NODE_INSTANCE_GROUP}${NODE_INSTANCE_PREFIX}-group-${i},"
  81. fi
  82. done
  83. fi
  84. # TODO(kubernetes/test-infra#3330): Allow NODE_INSTANCE_GROUP to be
  85. # set before we get here, which eliminates any cluster/gke use if
  86. # KUBERNETES_CONFORMANCE_PROVIDER is set to "gke".
  87. if [[ -z "${NODE_INSTANCE_GROUP:-}" ]] && [[ "${KUBERNETES_PROVIDER}" == "gke" ]]; then
  88. detect-node-instance-groups
  89. NODE_INSTANCE_GROUP=$(kube::util::join , "${NODE_INSTANCE_GROUP[@]}")
  90. fi
  91. if [[ "${KUBERNETES_PROVIDER}" == "azure" ]]; then
  92. if [[ ${CLOUD_CONFIG} == "" ]]; then
  93. echo "Missing azure cloud config"
  94. exit 1
  95. fi
  96. fi
  97. ginkgo_args=()
  98. if [[ -n "${CONFORMANCE_TEST_SKIP_REGEX:-}" ]]; then
  99. ginkgo_args+=("--skip=${CONFORMANCE_TEST_SKIP_REGEX}")
  100. ginkgo_args+=("--seed=1436380640")
  101. fi
  102. if [[ -n "${GINKGO_PARALLEL_NODES:-}" ]]; then
  103. ginkgo_args+=("--nodes=${GINKGO_PARALLEL_NODES}")
  104. elif [[ ${GINKGO_PARALLEL} =~ ^[yY]$ ]]; then
  105. ginkgo_args+=("--nodes=25")
  106. fi
  107. if [[ "${GINKGO_UNTIL_IT_FAILS:-}" == true ]]; then
  108. ginkgo_args+=("--untilItFails=true")
  109. fi
  110. FLAKE_ATTEMPTS=1
  111. if [[ "${GINKGO_TOLERATE_FLAKES}" == "y" ]]; then
  112. FLAKE_ATTEMPTS=2
  113. fi
  114. if [[ "${GINKGO_NO_COLOR}" == "y" ]]; then
  115. ginkgo_args+=("--noColor")
  116. fi
  117. # The --host setting is used only when providing --auth_config
  118. # If --kubeconfig is used, the host to use is retrieved from the .kubeconfig
  119. # file and the one provided with --host is ignored.
  120. # Add path for things like running kubectl binary.
  121. PATH=$(dirname "${e2e_test}"):"${PATH}"
  122. export PATH
  123. "${ginkgo}" "${ginkgo_args[@]:+${ginkgo_args[@]}}" "${e2e_test}" -- \
  124. "${auth_config[@]:+${auth_config[@]}}" \
  125. --ginkgo.flakeAttempts="${FLAKE_ATTEMPTS}" \
  126. --host="${KUBE_MASTER_URL}" \
  127. --provider="${KUBERNETES_PROVIDER}" \
  128. --gce-project="${PROJECT:-}" \
  129. --gce-zone="${ZONE:-}" \
  130. --gce-region="${REGION:-}" \
  131. --gce-multizone="${MULTIZONE:-false}" \
  132. --gke-cluster="${CLUSTER_NAME:-}" \
  133. --kube-master="${KUBE_MASTER:-}" \
  134. --cluster-tag="${CLUSTER_ID:-}" \
  135. --cloud-config-file="${CLOUD_CONFIG:-}" \
  136. --repo-root="${KUBE_ROOT}" \
  137. --node-instance-group="${NODE_INSTANCE_GROUP:-}" \
  138. --prefix="${KUBE_GCE_INSTANCE_PREFIX:-e2e}" \
  139. --network="${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-e2e}}" \
  140. --node-tag="${NODE_TAG:-}" \
  141. --master-tag="${MASTER_TAG:-}" \
  142. --dns-domain="${KUBE_DNS_DOMAIN:-cluster.local}" \
  143. --ginkgo.slowSpecThreshold="${GINKGO_SLOW_SPEC_THRESHOLD:-300}" \
  144. ${KUBE_CONTAINER_RUNTIME:+"--container-runtime=${KUBE_CONTAINER_RUNTIME}"} \
  145. ${MASTER_OS_DISTRIBUTION:+"--master-os-distro=${MASTER_OS_DISTRIBUTION}"} \
  146. ${NODE_OS_DISTRIBUTION:+"--node-os-distro=${NODE_OS_DISTRIBUTION}"} \
  147. ${NUM_NODES:+"--num-nodes=${NUM_NODES}"} \
  148. ${E2E_REPORT_DIR:+"--report-dir=${E2E_REPORT_DIR}"} \
  149. ${E2E_REPORT_PREFIX:+"--report-prefix=${E2E_REPORT_PREFIX}"} \
  150. "${@:-}"