ginkgo-e2e.sh 5.9 KB

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