test-e2e-node.sh 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. #!/usr/bin/env bash
  2. # Copyright 2016 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. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
  16. source "${KUBE_ROOT}/hack/lib/init.sh"
  17. # start the cache mutation detector by default so that cache mutators will be found
  18. KUBE_CACHE_MUTATION_DETECTOR="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
  19. export KUBE_CACHE_MUTATION_DETECTOR
  20. # panic the server on watch decode errors since they are considered coder mistakes
  21. KUBE_PANIC_WATCH_DECODE_ERROR="${KUBE_PANIC_WATCH_DECODE_ERROR:-true}"
  22. export KUBE_PANIC_WATCH_DECODE_ERROR
  23. focus=${FOCUS:-""}
  24. skip=${SKIP-"\[Flaky\]|\[Slow\]|\[Serial\]"}
  25. # The number of tests that can run in parallel depends on what tests
  26. # are running and on the size of the node. Too many, and tests will
  27. # fail due to resource contention. 8 is a reasonable default for a
  28. # n1-standard-1 node.
  29. # Currently, parallelism only affects when REMOTE=true. For local test,
  30. # ginkgo default parallelism (cores - 1) is used.
  31. parallelism=${PARALLELISM:-8}
  32. artifacts="${ARTIFACTS:-"/tmp/_artifacts/$(date +%y%m%dT%H%M%S)"}"
  33. remote=${REMOTE:-"false"}
  34. runtime=${RUNTIME:-"docker"}
  35. container_runtime_endpoint=${CONTAINER_RUNTIME_ENDPOINT:-""}
  36. image_service_endpoint=${IMAGE_SERVICE_ENDPOINT:-""}
  37. run_until_failure=${RUN_UNTIL_FAILURE:-"false"}
  38. test_args=${TEST_ARGS:-""}
  39. system_spec_name=${SYSTEM_SPEC_NAME:-}
  40. extra_envs=${EXTRA_ENVS:-}
  41. # Parse the flags to pass to ginkgo
  42. ginkgoflags=""
  43. if [[ ${parallelism} -gt 1 ]]; then
  44. ginkgoflags="${ginkgoflags} -nodes=${parallelism} "
  45. fi
  46. if [[ ${focus} != "" ]]; then
  47. ginkgoflags="${ginkgoflags} -focus=\"${focus}\" "
  48. fi
  49. if [[ ${skip} != "" ]]; then
  50. ginkgoflags="${ginkgoflags} -skip=\"${skip}\" "
  51. fi
  52. if [[ ${run_until_failure} != "" ]]; then
  53. ginkgoflags="${ginkgoflags} -untilItFails=${run_until_failure} "
  54. fi
  55. # Setup the directory to copy test artifacts (logs, junit.xml, etc) from remote host to local host
  56. if [ ! -d "${artifacts}" ]; then
  57. echo "Creating artifacts directory at ${artifacts}"
  58. mkdir -p "${artifacts}"
  59. fi
  60. echo "Test artifacts will be written to ${artifacts}"
  61. if [[ ${runtime} == "remote" ]] ; then
  62. if [[ -n ${container_runtime_endpoint} ]] ; then
  63. test_args="--container-runtime-endpoint=${container_runtime_endpoint} ${test_args}"
  64. fi
  65. if [[ -n ${image_service_endpoint} ]] ; then
  66. test_args="--image-service-endpoint=${image_service_endpoint} ${test_args}"
  67. fi
  68. fi
  69. if [ "${remote}" = true ] ; then
  70. # The following options are only valid in remote run.
  71. images=${IMAGES:-""}
  72. hosts=${HOSTS:-""}
  73. image_project=${IMAGE_PROJECT:-"kubernetes-node-e2e-images"}
  74. metadata=${INSTANCE_METADATA:-""}
  75. list_images=${LIST_IMAGES:-false}
  76. if [[ ${list_images} == "true" ]]; then
  77. gcloud compute images list --project="${image_project}" | grep "e2e-node"
  78. exit 0
  79. fi
  80. gubernator=${GUBERNATOR:-"false"}
  81. image_config_file=${IMAGE_CONFIG_FILE:-""}
  82. if [[ ${hosts} == "" && ${images} == "" && ${image_config_file} == "" ]]; then
  83. image_project="${IMAGE_PROJECT:-"cos-cloud"}"
  84. gci_image=$(gcloud compute images list --project "${image_project}" \
  85. --no-standard-images --filter="name ~ 'cos-beta.*'" --format="table[no-heading](name)")
  86. images=${gci_image}
  87. metadata="user-data<${KUBE_ROOT}/test/e2e_node/jenkins/gci-init.yaml,gci-update-strategy=update_disabled"
  88. fi
  89. instance_prefix=${INSTANCE_PREFIX:-"test"}
  90. cleanup=${CLEANUP:-"true"}
  91. delete_instances=${DELETE_INSTANCES:-"false"}
  92. preemptible_instances=${PREEMPTIBLE_INSTANCES:-"false"}
  93. test_suite=${TEST_SUITE:-"default"}
  94. # Get the compute zone
  95. zone=${ZONE:-"$(gcloud info --format='value(config.properties.compute.zone)')"}
  96. if [[ ${zone} == "" ]]; then
  97. echo "Could not find gcloud compute/zone when running: \`gcloud info --format='value(config.properties.compute.zone)'\`"
  98. exit 1
  99. fi
  100. # Get the compute project
  101. project=$(gcloud info --format='value(config.project)')
  102. if [[ ${project} == "" ]]; then
  103. echo "Could not find gcloud project when running: \`gcloud info --format='value(config.project)'\`"
  104. exit 1
  105. fi
  106. # Check if any of the images specified already have running instances. If so reuse those instances
  107. # by moving the IMAGE to a HOST
  108. if [[ ${images} != "" ]]; then
  109. IFS=',' read -ra IM <<< "${images}"
  110. images=""
  111. for i in "${IM[@]}"; do
  112. if gcloud compute instances list --project="${project}" --filter="name:'${instance_prefix}-${i}' AND zone:'${zone}'" | grep "${i}"; then
  113. if [[ "${hosts}" != "" ]]; then
  114. hosts="${hosts},"
  115. fi
  116. echo "Reusing host ${instance_prefix}-${i}"
  117. hosts="${hosts}${instance_prefix}-${i}"
  118. else
  119. if [[ "${images}" != "" ]]; then
  120. images="${images},"
  121. fi
  122. images="${images}${i}"
  123. fi
  124. done
  125. fi
  126. # Output the configuration we will try to run
  127. echo "Running tests remotely using"
  128. echo "Project: ${project}"
  129. echo "Image Project: ${image_project}"
  130. echo "Compute/Zone: ${zone}"
  131. echo "Images: ${images}"
  132. echo "Hosts: ${hosts}"
  133. echo "Ginkgo Flags: ${ginkgoflags}"
  134. echo "Instance Metadata: ${metadata}"
  135. echo "Image Config File: ${image_config_file}"
  136. # Invoke the runner
  137. go run test/e2e_node/runner/remote/run_remote.go --logtostderr --vmodule=*=4 --ssh-env="gce" \
  138. --zone="${zone}" --project="${project}" --gubernator="${gubernator}" \
  139. --hosts="${hosts}" --images="${images}" --cleanup="${cleanup}" \
  140. --results-dir="${artifacts}" --ginkgo-flags="${ginkgoflags}" \
  141. --image-project="${image_project}" --instance-name-prefix="${instance_prefix}" \
  142. --delete-instances="${delete_instances}" --test_args="${test_args}" --instance-metadata="${metadata}" \
  143. --image-config-file="${image_config_file}" --system-spec-name="${system_spec_name}" \
  144. --preemptible-instances="${preemptible_instances}" --extra-envs="${extra_envs}" --test-suite="${test_suite}" \
  145. 2>&1 | tee -i "${artifacts}/build-log.txt"
  146. exit $?
  147. else
  148. # Refresh sudo credentials if needed
  149. if ping -c 1 -q metadata.google.internal &> /dev/null; then
  150. echo 'Running on GCE, not asking for sudo credentials'
  151. elif sudo --non-interactive "$(which bash)" -c true 2> /dev/null; then
  152. # if we can run bash without a password, it's a pretty safe bet that either
  153. # we can run any command without a password, or that sudo credentials
  154. # are already cached - and they've just been re-cached
  155. echo 'No need to refresh sudo credentials'
  156. else
  157. echo 'Updating sudo credentials'
  158. sudo -v || exit 1
  159. fi
  160. # Do not use any network plugin by default. User could override the flags with
  161. # test_args.
  162. test_args='--kubelet-flags="--network-plugin= --cni-bin-dir=" '${test_args}
  163. # Runtime flags
  164. test_args='--kubelet-flags="--container-runtime='${runtime}'" '${test_args}
  165. # Test using the host the script was run on
  166. # Provided for backwards compatibility
  167. go run test/e2e_node/runner/local/run_local.go \
  168. --system-spec-name="${system_spec_name}" --extra-envs="${extra_envs}" \
  169. --ginkgo-flags="${ginkgoflags}" --test-flags="--container-runtime=${runtime} \
  170. --alsologtostderr --v 4 --report-dir=${artifacts} --node-name $(hostname) \
  171. ${test_args}" --build-dependencies=true 2>&1 | tee -i "${artifacts}/build-log.txt"
  172. exit $?
  173. fi