Skip to content

Commit 1460da9

Browse files
[CI] add minikubekvm integration test in prow
1 parent e4c8917 commit 1460da9

23 files changed

+1952
-1
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,3 +1260,9 @@ get-dependency-version:
12601260
.PHONY: _update-all
12611261
_update-all:
12621262
@(cd hack && go run update/update_all/update_all.go)
1263+
1264+
1265+
1266+
# targets for tests on prow
1267+
include ./hack/prow/prow.mk
1268+

hack/prow/common.sh

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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+
75+
76+
# install jq
77+
if ! type "jq" >/dev/null; then
78+
echo ">> Installing jq"
79+
if [ "${ARCH}" == "arm64" && "${OS}" == "linux" ]; then
80+
sudo apt-get install jq -y
81+
elif [ "${ARCH}" == "arm64" ]; then
82+
echo "Unable to install 'jq' automatically for arm64 on Darwin, please install 'jq' manually."
83+
exit 5
84+
elif [ "${OS}" != "darwin" ]; then
85+
curl -LO https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64 &&sudo install jq-linux64 /usr/local/bin/jq
86+
else
87+
curl -LO https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64 && sudo install jq-osx-amd64 /usr/local/bin/jq
88+
fi
89+
fi
90+
91+
}
92+
93+
function docker_setup() {
94+
95+
# clean all docker artifacts up
96+
docker system prune -a --volumes -f || true
97+
docker system df || true
98+
docker rm -f -v $(docker ps -aq) >/dev/null 2>&1 || true
99+
100+
# read only token, never expires
101+
#todo: do we need this token
102+
# docker login -u minikubebot -p "$DOCKERHUB_READONLY_TOKEN"
103+
}
104+
105+
function gvisor_image_build() {
106+
# Build the gvisor image so that we can integration test changes to pkg/gvisor
107+
chmod +x testdata/gvisor-addon
108+
# skipping gvisor mac because ofg https://github.com/kubernetes/minikube/issues/5137
109+
if [ "$(uname)" != "Darwin" ]; then
110+
# Should match GVISOR_IMAGE_VERSION in Makefile
111+
docker build -t gcr.io/k8s-minikube/gvisor-addon:2 -f testdata/gvisor-addon-Dockerfile ./testdata
112+
fi
113+
}
114+
115+
116+
117+
# this is where the script starts
118+
MINIKUBE_LOCATION="minikube_location"
119+
120+
readonly OS_ARCH="${OS}-${ARCH}"
121+
readonly TEST_ROOT="${HOME}/minikube-integration"
122+
readonly TEST_HOME="${TEST_ROOT}/${MINIKUBE_LOCATION}-$$"
123+
124+
export GOPATH="$HOME/go"
125+
export KUBECONFIG="${TEST_HOME}/kubeconfig"
126+
export PATH=$PATH:"/usr/local/bin/:/usr/local/go/bin/:$GOPATH/bin"
127+
export MINIKUBE_SUPPRESS_DOCKER_PERFORMANCE=true
128+
129+
readonly TIMEOUT=120m
130+
131+
cp -r test/integration/testdata .
132+
cp out/gvisor-addon testdata/
133+
ls testdata
134+
135+
# Add the out/ directory to the PATH, for using new drivers.
136+
export PATH="$(pwd)/out/":$PATH
137+
mkdir -p "${TEST_ROOT}"
138+
mkdir -p "${TEST_HOME}"
139+
export MINIKUBE_HOME="${TEST_HOME}/.minikube"
140+
export MINIKUBE_BIN="out/minikube-${OS_ARCH}"
141+
export E2E_BIN="out/e2e-${OS_ARCH}"
142+
143+
144+
install_dependencies
145+
docker_setup
146+
print_test_info
147+
gvisor_image_build
148+
149+
readonly TEST_OUT="${TEST_HOME}/testout.txt"
150+
readonly JSON_OUT="${TEST_HOME}/test.json"
151+
readonly JUNIT_OUT="${TEST_HOME}/junit-unit.xml"
152+
153+
touch "${TEST_OUT}"
154+
touch "${JSON_OUT}"
155+
touch "${JUNIT_OUT}"
156+
157+
e2e_start_time="$(date -u +%s)"
158+
echo ""
159+
echo ">> Starting ${E2E_BIN} at $(date)"
160+
set -x
161+
162+
EXTRA_START_ARGS="${EXTRA_START_ARGS} --container-runtime=${CONTAINER_RUNTIME}"
163+
echo $PATH
164+
gotestsum --jsonfile "${JSON_OUT}" --junitfile="${JUNIT_OUT}" -f standard-verbose --raw-command -- \
165+
go tool test2json -t \
166+
${E2E_BIN} \
167+
-minikube-start-args="--driver=${DRIVER} ${EXTRA_START_ARGS}" \
168+
-test.timeout=${TIMEOUT} -test.v \
169+
${EXTRA_TEST_ARGS} \
170+
-binary="${MINIKUBE_BIN}" 2>&1 |
171+
tee "${TEST_OUT}"
172+
173+
result=${PIPESTATUS[0]} # capture the exit code of the first cmd in pipe.
174+
set +x
175+
echo ">> ${E2E_BIN} exited with ${result} at $(date)"
176+
echo ""
177+
178+
179+
180+
# calculate the time took to finish running e2e binary test.
181+
e2e_end_time="$(date -u +%s)"
182+
elapsed=$(($e2e_end_time - $e2e_start_time))
183+
min=$(($elapsed / 60))
184+
sec=$(tail -c 3 <<<$((${elapsed}00 / 60)))
185+
elapsed=$min.$sec
186+
187+
#todo: currently we skip gopogh upload , we shall add it back
188+
#upload_to_goph
189+
190+
# according to prow's requirement, upload the test report to $ARTIFACTS
191+
cp ${TEST_OUT} .
192+
cp ${JSON_OUT} .
193+
cp ${JUNIT_OUT} .
194+
if [[ $result -eq 0 ]]; then
195+
echo "minikube: SUCCESS"
196+
else
197+
echo "minikube: FAIL"
198+
fi
199+
200+
exit "$result"

hack/prow/docker.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Image": "debian"
3+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
# Copyright 2016 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+
set -eux -o pipefail
18+
19+
ARCH=${ARCH:=amd64}
20+
21+
22+
echo "Installing latest docker"
23+
curl -fsSL https://get.docker.com -o get-docker.sh
24+
sudo sh get-docker.sh
25+
rm get-docker.sh
26+
27+
sudo usermod -aG docker minitest || true
28+
29+
echo "Installing latest kubectl"
30+
curl -LO "https://dl.k8s.io/release/$(curl -sL https://dl.k8s.io/release/stable.txt)/bin/linux/${ARCH}/kubectl"
31+
sudo install ./kubectl /usr/local/bin/kubectl
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
# This script requires two parameters:
18+
# $1. INSTALL_PATH: The path to install the golang binary
19+
# $2. GO_VERSION: The version of golang to install
20+
21+
22+
23+
set -eux -o pipefail
24+
25+
if (($# < 2)); then
26+
echo "ERROR: given ! ($#) parameters but expected 2."
27+
echo "USAGE: ./check_install_golang.sh INSTALL_PATH GO_VERSION"
28+
exit 1
29+
fi
30+
31+
VERSION_TO_INSTALL=${2}
32+
INSTALL_PATH=${1}
33+
34+
function current_arch() {
35+
case $(arch) in
36+
"x86_64" | "i386")
37+
echo "amd64"
38+
;;
39+
"aarch64" | "arm64")
40+
echo "arm64"
41+
;;
42+
*)
43+
echo "unexpected arch: $(arch). use amd64" 1>&2
44+
echo "amd64"
45+
;;
46+
esac
47+
}
48+
49+
ARCH=${ARCH:=$(current_arch)}
50+
51+
# installs or updates golang if right version doesn't exists
52+
function check_and_install_golang() {
53+
if ! go version &>/dev/null; then
54+
echo "WARNING: No golang installation found in your environment."
55+
install_golang "$VERSION_TO_INSTALL" "$INSTALL_PATH"
56+
return
57+
fi
58+
59+
sudo chown -R $USER:$USER "$INSTALL_PATH"/go
60+
61+
# golang has been installed and check its version
62+
if [[ $(go version | cut -d' ' -f 3) =~ go(([0-9]+)\.([0-9]+).([0-9]+)*) ]]; then
63+
HOST_VERSION=${BASH_REMATCH[1]}
64+
if [ $HOST_VERSION == $VERSION_TO_INSTALL ]; then
65+
echo "go version on the host looks good : $HOST_VERSION"
66+
else
67+
echo "WARNING: expected go version to be $VERSION_TO_INSTALL but got $HOST_VERSION"
68+
install_golang "$VERSION_TO_INSTALL" "$INSTALL_PATH"
69+
fi
70+
else
71+
echo "ERROR: Failed to parse golang version: $(go version)"
72+
return
73+
fi
74+
}
75+
76+
# install_golang takes two parameters version and path to install.
77+
function install_golang() {
78+
local -r GO_VER="$1"
79+
local -r GO_DIR="$2/go"
80+
echo "Installing golang version: $GO_VER in $GO_DIR"
81+
82+
INSTALLOS=linux
83+
if [[ "$OSTYPE" == "darwin"* ]]; then
84+
INSTALLOS=darwin
85+
fi
86+
87+
local -r GO_TGZ="go${GO_VER}.${INSTALLOS}-${ARCH}.tar.gz"
88+
pushd /tmp
89+
90+
# using sudo because previously installed versions might have been installed by a different user.
91+
sudo rm -rf "$GO_TGZ"
92+
curl -qL -O "https://storage.googleapis.com/golang/$GO_TGZ"
93+
sudo rm -rf "$GO_DIR"
94+
sudo mkdir -p "$GO_DIR"
95+
sudo tar -C "$GO_DIR" --strip-components=1 -xzf "$GO_TGZ"
96+
97+
popd >/dev/null
98+
echo "installed in $GO_DIR: $($GO_DIR/bin/go version)"
99+
}
100+
101+
check_and_install_golang
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Copyright 2021 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+
set -eux -o pipefail
18+
19+
function install_gotestsum() {
20+
rm -f $(which gotestsum)
21+
sudo env "GOBIN=$GOROOT/bin" "PATH=$PATH" go install gotest.tools/gotestsum@v1.12.3
22+
}
23+
echo "Installing gotestsum"
24+
which gotestsum || install_gotestsum

hack/prow/kvm.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"GCPZone": "us-central1-b",
3+
"InstanceImage": "ubuntu-os-cloud/ubuntu-2404-lts-amd64",
4+
"InstanceType": "n2-standard-32",
5+
"DiskGiB": 300,
6+
"BoskosAcquireTimeoutSeconds": 180,
7+
"BoskosHeartbeatIntervalSeconds": 10,
8+
"BoskosLocation": "http://boskos.test-pods.svc.cluster.local"
9+
}

0 commit comments

Comments
 (0)