Skip to content

Commit 97d8a29

Browse files
authored
ci: add smoke test to github action (#21095)
* smoke test * add logic to detect nested VMs * increase memory to 8gb for tesT * use the network flag for both qemu and vfkit * code review comments * separate minikube download * separate minikube download * force cpu1 * add docker for smoke test * exclude envs dont need in matrix * change back to 3 * remove unused code * add info block for linux as well
1 parent b973335 commit 97d8a29

File tree

5 files changed

+143
-3
lines changed

5 files changed

+143
-3
lines changed

.github/workflows/smoke-test.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Boot Smoke Test only tests Bare VM (start,stop,delete) and not any minikube/kubernetes functionality.
2+
name: Boot Smoke Test
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
workflow_dispatch:
8+
env:
9+
GOPROXY: https://proxy.golang.org
10+
permissions:
11+
contents: read
12+
jobs:
13+
minikube-vm-boot:
14+
name: Boot Smoke Test
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- driver: qemu
21+
os: macos-13
22+
network_flag: --network socket_vmnet
23+
- driver: docker
24+
os: ubuntu-24.04
25+
network_flag: ""
26+
steps:
27+
- name: Info Block (macos)
28+
if: contains(matrix.os, 'macos')
29+
shell: bash
30+
run: |
31+
uname -a
32+
sysctl -n hw.memsize
33+
echo "$(sysctl -n hw.memsize) / 1024 / 1024 / 1024" | bc
34+
sysctl -n hw.ncpu
35+
sysctl -n machdep.cpu.brand_string
36+
sysctl hw.model
37+
sysctl -n kern.hv_vmm_present
38+
sysctl -n kern.hv_support
39+
system_profiler SPHardwareDataType
40+
sw_vers
41+
ifconfig
42+
- name: Info Block (linux)
43+
if: contains(matrix.os, 'ubuntu')
44+
shell: bash
45+
run: |
46+
uname -a
47+
grep MemTotal /proc/meminfo
48+
awk '/MemTotal/ {printf "%.2f\n", $2 / 1024 / 1024}' /proc/meminfo
49+
nproc
50+
grep 'model name' /proc/cpuinfo | head -n1
51+
# System model (requires `dmidecode`, may need sudo)
52+
sudo dmidecode -s system-product-name
53+
systemd-detect-virt
54+
# Check if KVM is available (can show virtualization support)
55+
egrep -c '(vmx|svm)' /proc/cpuinfo
56+
# Detailed hardware info (like `system_profiler`)
57+
sudo lshw -short
58+
cat /etc/os-release
59+
ip addr show
60+
ifconfig
61+
docker version
62+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
63+
- uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5
64+
with:
65+
go-version-file: go.mod
66+
cache: true
67+
- name: Download Golang Dependencies
68+
run: go mod download
69+
- name: Build Binaries
70+
run: make
71+
- name: Ensure bootpd is enabled
72+
if: contains(matrix.os, 'macos')
73+
shell: bash
74+
run: |
75+
set -x
76+
fw=/usr/libexec/ApplicationFirewall/socketfilterfw
77+
sudo $fw --remove /usr/libexec/bootpd
78+
sudo $fw --add /usr/libexec/bootpd
79+
sudo $fw --unblock /usr/libexec/bootpd
80+
- name: brew update
81+
if: contains(matrix.os, 'macos')
82+
run:
83+
brew update
84+
- name: Install qemu and socket_vmnet (macos)
85+
if: contains(matrix.os, 'macos') && matrix.driver == 'qemu'
86+
run: |
87+
brew install qemu socket_vmnet
88+
HOMEBREW=$(which brew) && sudo ${HOMEBREW} services start socket_vmnet
89+
- name: Minikube Download only (iso/image)
90+
run:
91+
./out/minikube start --download-only --driver=${{ matrix.driver }}
92+
- name: Start minikube (1st boot)
93+
run: ./out/minikube start --driver=${{ matrix.driver }} ${{ matrix.network_flag }} --memory 4gb --no-kubernetes --alsologtostderr
94+
- name: Stop minikube
95+
run: ./out/minikube stop
96+
- name: Start minikube again (2nd boot)
97+
run: ./out/minikube start --alsologtostderr
98+
- name: delete minikube
99+
run: ./out/minikube delete --alsologtostderr

pkg/drivers/hyperkit/driver.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
hyperkit "github.com/moby/hyperkit/go"
3939
"github.com/pkg/errors"
4040
pkgdrivers "k8s.io/minikube/pkg/drivers"
41+
"k8s.io/minikube/pkg/minikube/detect"
4142
)
4243

4344
const (
@@ -296,7 +297,11 @@ func (d *Driver) setupIP(mac string) error {
296297
var err error
297298

298299
// Implement a retry loop without calling any minikube code
299-
for i := 0; i < 30; i++ {
300+
multiplier := 1
301+
if detect.NestedVM() {
302+
multiplier = 3 // will help with running in Free github action Macos VMs (takes 112+ retries on average)
303+
}
304+
for i := 0; i < 60*multiplier; i++ {
300305
log.Debugf("Attempt %d", i)
301306
err = getIP()
302307
if err == nil {

pkg/drivers/qemu/qemu.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@ func (d *Driver) Start() error {
517517
return nil
518518
}
519519
// Implement a retry loop because IP address isn't added to dhcp leases file immediately
520-
for i := 0; i < 60; i++ {
520+
multiplier := 1
521+
if detect.NestedVM() {
522+
multiplier = 3 // will help with running in Free github action Macos VMs (takes 112+ retries on average)
523+
}
524+
for i := 0; i < 60*multiplier; i++ {
521525
log.Debugf("Attempt %d", i)
522526
err = getIP()
523527
if err == nil {

pkg/drivers/vfkit/vfkit.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"k8s.io/klog/v2"
4545
pkgdrivers "k8s.io/minikube/pkg/drivers"
4646
"k8s.io/minikube/pkg/drivers/vmnet"
47+
"k8s.io/minikube/pkg/minikube/detect"
4748
"k8s.io/minikube/pkg/minikube/exit"
4849
"k8s.io/minikube/pkg/minikube/firewall"
4950
"k8s.io/minikube/pkg/minikube/out"
@@ -309,7 +310,11 @@ func (d *Driver) setupIP(mac string) error {
309310
return nil
310311
}
311312
// Implement a retry loop because IP address isn't added to dhcp leases file immediately
312-
for i := 0; i < 60; i++ {
313+
multiplier := 1
314+
if detect.NestedVM() {
315+
multiplier = 3 // will help with running in Free github action Macos VMs (takes 160+ retries on average)
316+
}
317+
for i := 0; i < 60*multiplier; i++ {
313318
log.Debugf("Attempt %d", i)
314319
err = getIP()
315320
if err == nil {

pkg/minikube/detect/detect.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,30 @@ func MacOS13Plus() bool {
212212
}
213213
return major >= 13
214214
}
215+
216+
// NestedVM returns true if the current machine is running a nested VM (like in MacOs in Github Action)
217+
// this func tries its best but not guaranteed to be 100% accurate, and if not sure will return false (default behaviour).
218+
func NestedVM() bool {
219+
if runtime.GOOS == "linux" {
220+
c := exec.Command("systemd-detect-virt", "--quiet")
221+
_, err := c.Output()
222+
if err == nil {
223+
klog.Infof("nested VM detected")
224+
return true
225+
}
226+
return false // On a bare-metal system, it exits with code 1 and outputs "none".
227+
228+
}
229+
230+
if runtime.GOOS == "darwin" {
231+
c := exec.Command("sysctl", "-n", "kern.hv_vmm_present")
232+
o, err := c.Output()
233+
if err != nil {
234+
klog.Warningf("Failed to check for nested VM: %v", err)
235+
return false
236+
}
237+
klog.Infof("nested VM detected, %s", o)
238+
return true
239+
}
240+
return false
241+
}

0 commit comments

Comments
 (0)