e2e-k8s.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. #!/bin/bash
  2. # Licensed to the LF AI & Data foundation under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. SOURCE="${BASH_SOURCE[0]}"
  18. while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  19. DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
  20. SOURCE="$(readlink "$SOURCE")"
  21. [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
  22. done
  23. ROOT="$( cd -P "$( dirname "$SOURCE" )/../.." && pwd )"
  24. # Exit immediately for non zero status
  25. set -e
  26. # Check unset variables
  27. set -u
  28. # Print commands
  29. set -x
  30. # shellcheck source=build/lib.sh
  31. source "${ROOT}/build/lib.sh"
  32. setup_and_export_git_sha
  33. # shellcheck source=build/kind_provisioner.sh
  34. source "${ROOT}/build/kind_provisioner.sh"
  35. # shellcheck source=ci-util.sh
  36. source "${ROOT}/tests/scripts/ci-util.sh"
  37. TOPOLOGY=SINGLE_CLUSTER
  38. NODE_IMAGE="kindest/node:v1.20.2"
  39. KIND_CONFIG=""
  40. INSTALL_EXTRA_ARG=""
  41. TEST_EXTRA_ARG=""
  42. CLUSTER_TOPOLOGY_CONFIG_FILE="${ROOT}/build/config/topology/multicluster.json"
  43. while (( "$#" )); do
  44. case "$1" in
  45. # Node images can be found at https://github.com/kubernetes-sigs/kind/releases
  46. # For example, kindest/node:v1.14.0
  47. --node-image)
  48. NODE_IMAGE=$2
  49. shift 2
  50. ;;
  51. # Config for enabling different Kubernetes features in KinD (see build/config/topology/trustworthy-jwt.yaml).
  52. --kind-config)
  53. KIND_CONFIG=$2
  54. shift 2
  55. ;;
  56. --build-command)
  57. BUILD_COMMAND=$2
  58. shift 2
  59. ;;
  60. --install-extra-arg)
  61. INSTALL_EXTRA_ARG=$2
  62. shift 2
  63. ;;
  64. --test-extra-arg)
  65. TEST_EXTRA_ARG=$2
  66. shift 2
  67. ;;
  68. --test-timeout)
  69. TEST_TIMEOUT=$2
  70. shift 2
  71. ;;
  72. --skip-setup)
  73. SKIP_SETUP=true
  74. shift
  75. ;;
  76. --skip-install)
  77. SKIP_INSTALL=true
  78. shift
  79. ;;
  80. --skip-cleanup)
  81. SKIP_CLEANUP=true
  82. shift
  83. ;;
  84. --skip-build)
  85. SKIP_BUILD=true
  86. shift
  87. ;;
  88. --skip-build-image)
  89. SKIP_BUILD_IMAGE=true
  90. shift
  91. ;;
  92. --skip-test)
  93. SKIP_TEST=true
  94. shift
  95. ;;
  96. --skip-export-logs)
  97. SKIP_EXPORT_LOGS=true
  98. shift
  99. ;;
  100. --disable-kind)
  101. DISABLE_KIND=true
  102. shift
  103. ;;
  104. --manual)
  105. MANUAL=true
  106. shift
  107. ;;
  108. --gpu)
  109. GPU_BUILD=true
  110. shift
  111. ;;
  112. --topology)
  113. case $2 in
  114. SINGLE_CLUSTER | MULTICLUSTER_SINGLE_NETWORK | MULTICLUSTER )
  115. TOPOLOGY=$2
  116. echo "Running with topology ${TOPOLOGY}"
  117. ;;
  118. *)
  119. echo "Error: Unsupported topology ${TOPOLOGY}" >&2
  120. exit 1
  121. ;;
  122. esac
  123. shift 2
  124. ;;
  125. --topology-config)
  126. CLUSTER_TOPOLOGY_CONFIG_FILE="${ROOT}/${2}"
  127. shift 2
  128. ;;
  129. -h|--help)
  130. { set +x; } 2>/dev/null
  131. HELP="
  132. Usage:
  133. $0 [flags] [Arguments]
  134. --node-image Kubernetes in Docker (KinD) Node image
  135. The image is a Docker image for running nested containers, systemd, and Kubernetes components.
  136. Node images can be found at https://github.com/kubernetes-sigs/kind/releases.
  137. Default: \"kindest/node:v1.20.2\"
  138. --kind-config Config for enabling different Kubernetes features in KinD
  139. --build-command Specified build milvus command
  140. --install-extra-arg Install Milvus Helm Chart extra configuration. (see https://github.com/zilliztech/milvus-helm-charts/blob/main/charts/milvus-ha/values.yaml)
  141. To override values in a chart, use either the '--values' flag and pass in a file or use the '--set' flag and pass configuration from the command line, to force a string value use '--set-string'.
  142. Refer: https://helm.sh/docs/helm/helm_install/#helm-install
  143. --test-extra-arg Run e2e test extra configuration
  144. For example, \"--tags=L0\"
  145. --test-timeout To specify timeout period of e2e test. Timeout time is specified in seconds.
  146. --topology KinD cluster topology of deployments
  147. Provides three classes: \"SINGLE_CLUSTER\", \"MULTICLUSTER_SINGLE_NETWORK\", \"MULTICLUSTER\"
  148. Default: \"SINGLE_CLUSTER\"
  149. --topology-config KinD cluster topology configuration file
  150. --skip-setup Skip setup KinD cluster
  151. --skip-install Skip install Milvus Helm Chart
  152. --skip-cleanup Skip cleanup KinD cluster
  153. --skip-build Skip build Milvus binary
  154. --skip-build-image Skip build Milvus image
  155. --skip-test Skip e2e test
  156. --skip-export-logs Skip kind export logs
  157. --manual Manual Mode
  158. --disable-kind Remove KinD cluster
  159. -h or --help Print help information
  160. Use \"$0 --help\" for more information about a given command.
  161. "
  162. echo -e "${HELP}" ; exit 0
  163. ;;
  164. -*)
  165. echo "Error: Unsupported flag $1" >&2
  166. exit 1
  167. ;;
  168. *) # preserve positional arguments
  169. PARAMS+=("$1")
  170. shift
  171. ;;
  172. esac
  173. done
  174. if [[ -n "${GPU_BUILD:-}" ]]; then
  175. export BUILD_COMMAND="${BUILD_COMMAND:-make gpu-install}"
  176. export BUILD_SCRIPT="builder_gpu.sh"
  177. export BUILD_IMAGE_SCRIPT="build_image_gpu.sh"
  178. export TAG="${TAG:-gpu-latest}"
  179. export MODE="gpu"
  180. else
  181. export BUILD_COMMAND="${BUILD_COMMAND:-make install use_disk_index=ON}"
  182. export BUILD_SCRIPT="builder.sh"
  183. export BUILD_IMAGE_SCRIPT="build_image.sh"
  184. export TAG="${TAG:-latest}"
  185. export MODE="cpu"
  186. fi
  187. export MANUAL="${MANUAL:-}"
  188. # Default IP family of the cluster is IPv4
  189. export IP_FAMILY="${IP_FAMILY:-ipv4}"
  190. # KinD will not have a LoadBalancer, so we need to disable it
  191. export TEST_ENV=kind
  192. # LoadBalancer in Kind is supported using metallb if not ipv6.
  193. if [ "${IP_FAMILY}" != "ipv6" ]; then
  194. export TEST_ENV=kind-metallb
  195. fi
  196. # See https://kind.sigs.k8s.io/docs/user/quick-start/#loading-an-image-into-your-cluster
  197. export PULL_POLICY=IfNotPresent
  198. # We run a local-registry in a docker container that KinD nodes pull from
  199. # These values must match what are in config/trustworthy-jwt.yaml
  200. export KIND_REGISTRY_NAME="kind-registry"
  201. export KIND_REGISTRY_PORT="5000"
  202. export KIND_REGISTRY="localhost:${KIND_REGISTRY_PORT}"
  203. export ARTIFACTS="${ARTIFACTS:-$(mktemp -d)}"
  204. export SINGLE_CLUSTER_NAME="${SINGLE_CLUSTER_NAME:-kind}"
  205. export HUB="${HUB:-milvusdb}"
  206. export CI="true"
  207. export IS_NETWORK_MODE_HOST=true
  208. if [[ ! -d "${ARTIFACTS}" ]];then
  209. mkdir -p "${ARTIFACTS}"
  210. fi
  211. if [[ ! -x "$(command -v kubectl)" ]]; then
  212. KUBECTL_DIR="${KUBECTL_DIR:-"${HOME}/tool_cache/kubectl"}"
  213. KUBECTL_VERSION="v1.20.2"
  214. export PATH="${KUBECTL_DIR}:${PATH}"
  215. if [[ ! -x "$(command -v kubectl)" ]]; then
  216. install_kubectl "${KUBECTL_DIR}" "${KUBECTL_VERSION}"
  217. fi
  218. fi
  219. if [[ -z "${DISABLE_KIND:-}" ]];then
  220. if [[ ! -x "$(command -v kind)" ]]; then
  221. KIND_DIR="${KIND_DIR:-"${HOME}/tool_cache/kind"}"
  222. KIND_VERSION="v0.11.1"
  223. export PATH="${KIND_DIR}:${PATH}"
  224. if [[ ! -x "$(command -v kind)" ]]; then
  225. install_kind "${KIND_DIR}" "${KIND_VERSION}"
  226. fi
  227. fi
  228. fi
  229. if [[ -z "${SKIP_SETUP:-}" ]]; then
  230. export DEFAULT_CLUSTER_YAML="${ROOT}/build/config/topology/trustworthy-jwt.yaml"
  231. export METRICS_SERVER_CONFIG_DIR="${ROOT}/build/config/metrics"
  232. if ! docker info > /dev/null 2>&1; then
  233. echo "KinD need docker to set up cluster - please start docker and try again!"
  234. exit 1
  235. fi
  236. if [[ "${TOPOLOGY}" == "SINGLE_CLUSTER" ]]; then
  237. trace "setup kind cluster" setup_kind_cluster "${SINGLE_CLUSTER_NAME}" "${NODE_IMAGE}" "${KIND_CONFIG}"
  238. else
  239. trace "load cluster topology" load_cluster_topology "${CLUSTER_TOPOLOGY_CONFIG_FILE}"
  240. trace "setup kind clusters" setup_kind_clusters "${NODE_IMAGE}" "${IP_FAMILY}"
  241. TOPOLOGY_JSON=$(cat "${CLUSTER_TOPOLOGY_CONFIG_FILE}")
  242. for i in $(seq 0 $((${#CLUSTER_NAMES[@]} - 1))); do
  243. CLUSTER="${CLUSTER_NAMES[i]}"
  244. KCONFIG="${KUBECONFIGS[i]}"
  245. TOPOLOGY_JSON=$(set_topology_value "${TOPOLOGY_JSON}" "${CLUSTER}" "meta.kubeconfig" "${KCONFIG}")
  246. done
  247. RUNTIME_TOPOLOGY_CONFIG_FILE="${ARTIFACTS}/topology-config.json"
  248. echo "${TOPOLOGY_JSON}" > "${RUNTIME_TOPOLOGY_CONFIG_FILE}"
  249. export INTEGRATION_TEST_TOPOLOGY_FILE
  250. INTEGRATION_TEST_TOPOLOGY_FILE="${RUNTIME_TOPOLOGY_CONFIG_FILE}"
  251. export INTEGRATION_TEST_KUBECONFIG
  252. INTEGRATION_TEST_KUBECONFIG=NONE
  253. fi
  254. fi
  255. if [[ -z "${SKIP_BUILD:-}" ]]; then
  256. #If disable_kind exist, do not need kind registry
  257. if [[ -n "${DISABLE_KIND:-}" ]]; then
  258. echo "do not set up kind registry when disable_kind exist"
  259. else
  260. trace "setup kind registry" setup_kind_registry
  261. fi
  262. pushd "${ROOT}"
  263. trace "build milvus" "${ROOT}/build/${BUILD_SCRIPT}" /bin/bash -c "${BUILD_COMMAND}"
  264. popd
  265. fi
  266. if [[ -n "${DISABLE_KIND:-}" ]]; then
  267. export MILVUS_IMAGE_TAG="${TAG}"
  268. export MILVUS_IMAGE_REPO="${HUB}/milvus"
  269. fi
  270. if [[ -z "${SKIP_BUILD_IMAGE:-}" ]]; then
  271. # If disable_kind exist,login ci docker registry instead
  272. if [[ -n "${DISABLE_KIND:-}" ]]; then
  273. trace "docker login in ci registry" docker_login_ci_registry
  274. else
  275. # If we're not intending to pull from an actual remote registry, use the local kind registry
  276. running="$(docker inspect -f '{{.State.Running}}' "${KIND_REGISTRY_NAME}" 2>/dev/null || true)"
  277. if [[ "${running}" == 'true' ]]; then
  278. HUB="${KIND_REGISTRY}"
  279. export HUB
  280. fi
  281. export MILVUS_IMAGE_REPO="${HUB}/milvus"
  282. export MILVUS_IMAGE_TAG="${TAG}"
  283. fi
  284. pushd "${ROOT}"
  285. # Build Milvus Docker Image
  286. trace "build milvus image" "${ROOT}/build/${BUILD_IMAGE_SCRIPT}"
  287. trace "push milvus image" docker push "${MILVUS_IMAGE_REPO}:${MILVUS_IMAGE_TAG}"
  288. popd
  289. fi
  290. if [[ -z "${SKIP_INSTALL:-}" ]]; then
  291. if [[ ! -x "$(command -v helm)" ]]; then
  292. HELM_DIR="${HELM_DIR:-"${HOME}/tool_cache/helm"}"
  293. HELM_VERSION="v3.5.4"
  294. export PATH="${HELM_DIR}:${PATH}"
  295. if [[ ! -x "$(command -v helm)" ]]; then
  296. install_helm "${HELM_DIR}" "${HELM_VERSION}"
  297. fi
  298. fi
  299. export MILVUS_HELM_RELEASE_NAME=$(./get_release_name.sh)
  300. echo "[debug] helm install ${MILVUS_HELM_RELEASE_NAME}"
  301. trace "install milvus helm chart" "${ROOT}/tests/scripts/install_milvus.sh" "${INSTALL_EXTRA_ARG}"
  302. fi
  303. if [[ -z "${SKIP_TEST:-}" ]]; then
  304. if [[ -n "${TEST_TIMEOUT:-}" ]]; then
  305. if [[ -n "${DISABLE_KIND:-}" ]]; then
  306. trace "e2e test" "timeout" "${TEST_TIMEOUT}" "${ROOT}/tests/scripts/e2e.sh" "${TEST_EXTRA_ARG}"
  307. else
  308. trace "e2e test" "timeout" "-v" "${TEST_TIMEOUT}" "${ROOT}/tests/scripts/e2e.sh" "${TEST_EXTRA_ARG}"
  309. fi
  310. else
  311. trace "e2e test" "${ROOT}/tests/scripts/e2e.sh" "${TEST_EXTRA_ARG}"
  312. fi
  313. fi
  314. # Check if the user is running the clusters in manual mode.
  315. if [[ -n "${MANUAL:-}" ]]; then
  316. echo "Running cluster(s) in manual mode. Press any key to shutdown and exit..."
  317. read -rsn1
  318. exit 0
  319. fi