|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2025 The Kubernetes Authors All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# The script expects the following env variables: |
| 18 | +# OS: The operating system |
| 19 | +# ARCH: The architecture |
| 20 | +# DRIVER: the driver to use for the test |
| 21 | +# CONTAINER_RUNTIME: the container runtime to use for the test |
| 22 | +# EXTRA_START_ARGS: additional flags to pass into minikube start |
| 23 | +# EXTRA_TEST_ARGS: additional flags to pass into go test |
| 24 | +# JOB_NAME: the name of the logfile and check name to update on github |
| 25 | + |
| 26 | +function print_test_info() { |
| 27 | + echo ">> Starting at $(date)" |
| 28 | + echo "" |
| 29 | + echo "user: $(whoami)" |
| 30 | + echo "arch: ${OS_ARCH}" |
| 31 | + echo "build: ${MINIKUBE_LOCATION}" |
| 32 | + echo "driver: ${DRIVER}" |
| 33 | + echo "runtime: ${CONTAINER_RUNTIME}" |
| 34 | + echo "job: ${JOB_NAME}" |
| 35 | + echo "test home: ${TEST_HOME}" |
| 36 | + echo "kernel: $(uname -v)" |
| 37 | + echo "uptime: $(uptime)" |
| 38 | + # Setting KUBECONFIG prevents the version check from erroring out due to permission issues |
| 39 | + echo "kubectl: $(env KUBECONFIG=${TEST_HOME} kubectl version --client)" |
| 40 | + echo "docker: $(docker version --format '{{ .Client.Version }}')" |
| 41 | + echo "podman: $(sudo podman version --format '{{.Version}}' || true)" |
| 42 | + echo "go: $(go version || true)" |
| 43 | + |
| 44 | + case "${DRIVER}" in |
| 45 | + kvm2) |
| 46 | + echo "virsh: $(virsh --version)" |
| 47 | + ;; |
| 48 | + virtualbox) |
| 49 | + echo "vbox: $(vboxmanage --version)" |
| 50 | + ;; |
| 51 | + vfkit) |
| 52 | + echo "vfkit: $(vfkit --version)" |
| 53 | + ;; |
| 54 | + krunkit) |
| 55 | + echo "krunkit: $(krunkit --version)" |
| 56 | + ;; |
| 57 | + esac |
| 58 | + |
| 59 | + echo "" |
| 60 | +} |
| 61 | + |
| 62 | +function install_dependencies() { |
| 63 | + # We need pstree for the restart cronjobs |
| 64 | + if [ "$(uname)" != "Darwin" ]; then |
| 65 | + sudo apt-get -y install lsof psmisc dnsutils |
| 66 | + else |
| 67 | + brew install pstree coreutils pidof |
| 68 | + ln -s /usr/local/bin/gtimeout /usr/local/bin/timeout || true |
| 69 | + fi |
| 70 | + # install golang if not present |
| 71 | + sudo hack/prow/installer/check_install_golang.sh /usr/local 1.24.5 || true |
| 72 | + # install gotestsum if not present |
| 73 | + GOROOT="/usr/local/go" hack/prow/installer/check_install_gotestsum.sh || true |
| 74 | + # install gopogh |
| 75 | + hack/prow/installer/check_install_gopogh.sh || true |
| 76 | + |
| 77 | + # install jq |
| 78 | + if ! type "jq" >/dev/null; then |
| 79 | + echo ">> Installing jq" |
| 80 | + if [ "${ARCH}" == "arm64" && "${OS}" == "linux" ]; then |
| 81 | + sudo apt-get install jq -y |
| 82 | + elif [ "${ARCH}" == "arm64" ]; then |
| 83 | + echo "Unable to install 'jq' automatically for arm64 on Darwin, please install 'jq' manually." |
| 84 | + exit 5 |
| 85 | + elif [ "${OS}" != "darwin" ]; then |
| 86 | + curl -LO https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 && sudo install jq-linux64 /usr/local/bin/jq |
| 87 | + else |
| 88 | + curl -LO https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 && sudo install jq-osx-amd64 /usr/local/bin/jq |
| 89 | + fi |
| 90 | + fi |
| 91 | + |
| 92 | +} |
| 93 | + |
| 94 | +function docker_setup() { |
| 95 | + |
| 96 | + # clean all docker artifacts up |
| 97 | + docker system prune -a --volumes -f || true |
| 98 | + docker system df || true |
| 99 | + docker rm -f -v $(docker ps -aq) >/dev/null 2>&1 || true |
| 100 | + |
| 101 | + # read only token, never expires |
| 102 | + #todo: do we need this token |
| 103 | + # docker login -u minikubebot -p "$DOCKERHUB_READONLY_TOKEN" |
| 104 | +} |
| 105 | + |
| 106 | +function gvisor_image_build() { |
| 107 | + # Build the gvisor image so that we can integration test changes to pkg/gvisor |
| 108 | + chmod +x testdata/gvisor-addon |
| 109 | + # skipping gvisor mac because ofg https://github.com/kubernetes/minikube/issues/5137 |
| 110 | + if [ "$(uname)" != "Darwin" ]; then |
| 111 | + # Should match GVISOR_IMAGE_VERSION in Makefile |
| 112 | + docker build -t gcr.io/k8s-minikube/gvisor-addon:2 -f testdata/gvisor-addon-Dockerfile ./testdata |
| 113 | + fi |
| 114 | +} |
| 115 | + |
| 116 | +function run_gopogh() { |
| 117 | + # todo: currently we do not save to gopogh db |
| 118 | + echo "Not saving to DB" |
| 119 | + gopogh -in "${JSON_OUT}" -out_html "${HTML_OUT}" -out_summary "${SUMMARY_OUT}" -name "${JOB_NAME}" -pr "${MINIKUBE_LOCATION}" -repo github.com/kubernetes/minikube/ -details "${COMMIT}:$(date +%Y-%m-%d)" |
| 120 | + |
| 121 | +} |
| 122 | + |
| 123 | +# this is where the script starts |
| 124 | +readonly OS_ARCH="${OS}-${ARCH}" |
| 125 | +readonly TEST_ROOT="${HOME}/minikube-integration" |
| 126 | +readonly TEST_HOME="${TEST_ROOT}/${MINIKUBE_LOCATION}-$$" |
| 127 | + |
| 128 | +export GOPATH="$HOME/go" |
| 129 | +export KUBECONFIG="${TEST_HOME}/kubeconfig" |
| 130 | +export PATH=$PATH:"/usr/local/bin/:/usr/local/go/bin/:$GOPATH/bin" |
| 131 | +export MINIKUBE_SUPPRESS_DOCKER_PERFORMANCE=true |
| 132 | + |
| 133 | +readonly TIMEOUT=120m |
| 134 | + |
| 135 | +cp -r test/integration/testdata . |
| 136 | +cp out/gvisor-addon testdata/ |
| 137 | +ls testdata |
| 138 | + |
| 139 | +# Add the out/ directory to the PATH, for using new drivers. |
| 140 | +export PATH="$(pwd)/out/":$PATH |
| 141 | +mkdir -p "${TEST_ROOT}" |
| 142 | +mkdir -p "${TEST_HOME}" |
| 143 | +export MINIKUBE_HOME="${TEST_HOME}/.minikube" |
| 144 | +export MINIKUBE_BIN="out/minikube-${OS_ARCH}" |
| 145 | +export E2E_BIN="out/e2e-${OS_ARCH}" |
| 146 | + |
| 147 | +install_dependencies |
| 148 | +docker_setup |
| 149 | +print_test_info |
| 150 | +gvisor_image_build |
| 151 | + |
| 152 | +readonly TEST_OUT="${TEST_HOME}/testout.txt" |
| 153 | +readonly JSON_OUT="${TEST_HOME}/test.json" |
| 154 | +readonly JUNIT_OUT="${TEST_HOME}/junit-unit.xml" |
| 155 | +readonly HTML_OUT="${TEST_HOME}/test.html" |
| 156 | +readonly SUMMARY_OUT="${TEST_HOME}/test_summary.json" |
| 157 | + |
| 158 | +touch "${TEST_OUT}" |
| 159 | +touch "${JSON_OUT}" |
| 160 | +touch "${JUNIT_OUT}" |
| 161 | +touch "${HTML_OUT}" |
| 162 | +touch "${SUMMARY_OUT}" |
| 163 | + |
| 164 | +e2e_start_time="$(date -u +%s)" |
| 165 | +echo "" |
| 166 | +echo ">> Starting ${E2E_BIN} at $(date)" |
| 167 | +set -x |
| 168 | + |
| 169 | +EXTRA_START_ARGS="${EXTRA_START_ARGS} --container-runtime=${CONTAINER_RUNTIME}" |
| 170 | +echo $PATH |
| 171 | +gotestsum --jsonfile "${JSON_OUT}" --junitfile="${JUNIT_OUT}" -f standard-verbose --raw-command -- \ |
| 172 | + go tool test2json -t \ |
| 173 | + ${E2E_BIN} \ |
| 174 | + -minikube-start-args="--driver=${DRIVER} ${EXTRA_START_ARGS}" \ |
| 175 | + -test.timeout=${TIMEOUT} -test.v \ |
| 176 | + ${EXTRA_TEST_ARGS} \ |
| 177 | + -binary="${MINIKUBE_BIN}" 2>&1 | |
| 178 | + tee "${TEST_OUT}" |
| 179 | + |
| 180 | +result=${PIPESTATUS[0]} # capture the exit code of the first cmd in pipe. |
| 181 | +set +x |
| 182 | +echo ">> ${E2E_BIN} exited with ${result} at $(date)" |
| 183 | +echo "" |
| 184 | + |
| 185 | +# calculate the time took to finish running e2e binary test. |
| 186 | +e2e_end_time="$(date -u +%s)" |
| 187 | +elapsed=$(($e2e_end_time - $e2e_start_time)) |
| 188 | +min=$(($elapsed / 60)) |
| 189 | +sec=$(tail -c 3 <<<$((${elapsed}00 / 60))) |
| 190 | +elapsed=$min.$sec |
| 191 | + |
| 192 | +#todo: currently we skip gopogh upload , we shall add it back |
| 193 | +run_gopogh |
| 194 | + |
| 195 | +# according to prow's requirement, upload the test report to $ARTIFACTS |
| 196 | +cp ${TEST_OUT} . |
| 197 | +cp ${JSON_OUT} . |
| 198 | +cp ${JUNIT_OUT} . |
| 199 | +cp ${HTML_OUT} . |
| 200 | +cp ${SUMMARY_OUT} . |
| 201 | +if [[ $result -eq 0 ]]; then |
| 202 | + echo "minikube: SUCCESS" |
| 203 | +else |
| 204 | + echo "minikube: FAIL" |
| 205 | +fi |
| 206 | + |
| 207 | +exit "$result" |
0 commit comments