Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/drivers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ func getIPAddressFromFile(mac, path string) (string, error) {
if err != nil {
return "", err
}

log.Debugf("Searching for %s in %s ...", mac, path)
file, err := os.Open(path)
if err != nil {
return "", err
Expand Down
5 changes: 3 additions & 2 deletions pkg/drivers/krunkit/krunkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,14 @@ func (d *Driver) setupIP(mac string) error {
return nil
}
// Implement a retry loop because IP address isn't added to dhcp leases file immediately
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a constant for maxAttempts since we need it twice:

const maxAttempts = 60

This will also make it more consistent with other drivers, which will make it easier to extract this loop to a helper function, since all the drivers use the similar logic.

for i := 0; i < 60; i++ {
log.Debugf("Attempt %d", i)
const maxAttempts = 60
for i := 0; i < maxAttempts; i++ {
err = getIP()
if err == nil {
break
}
time.Sleep(2 * time.Second)
log.Debugf("Searching for %s in %s (attempt %d/%d)", d.MACAddress, common.LeasesPath, i+1, maxAttempts)
}

if err == nil {
Expand Down
9 changes: 5 additions & 4 deletions pkg/drivers/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const (
isoFilename = "boot2docker.iso"
serialFileName = "serial.log"
privateNetworkName = "docker-machines"

defaultSSHUser = "docker"
defaultSSHUser = "docker"
)

type Driver struct {
Expand Down Expand Up @@ -521,13 +520,15 @@ func (d *Driver) Start() error {
if detect.NestedVM() {
multiplier = 3 // will help with running in Free github action Macos VMs (takes 112+ retries on average)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a variable instead of repeating 60*multiplier and use it in the lop and the log.

cost maxAttempts := 60 * multiplier

Same comment for vfkit.go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a variable instead of repeating 60*multiplier and use it in the lop and the log.

cost maxAttempts := 60 * multiplier

Would it be better to put maxAttempts in the const section instead of defining it at the top of the loop?
We can't do that because the multiplier is not a constant — its value isn't known at compile time.

Copy link
Contributor

@nirs nirs Oct 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it must be in the function and unfortunately const will not work in Go for local value that cannot change after setting it.

for i := 0; i < 60*multiplier; i++ {
log.Debugf("Attempt %d", i)

maxAttempts := 60 * multiplier
for i := 0; i < maxAttempts; i++ {
err = getIP()
if err == nil {
break
}
time.Sleep(2 * time.Second)
log.Debugf("Searching for %s in %s (attempt %d/%d)", d.MACAddress, common.LeasesPath, i+1, maxAttempts)
}

if err == nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/drivers/vfkit/vfkit.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,15 @@ func (d *Driver) setupIP(mac string) error {
if detect.NestedVM() {
multiplier = 3 // will help with running in Free github action Macos VMs (takes 160+ retries on average)
}
for i := 0; i < 60*multiplier; i++ {
log.Debugf("Attempt %d", i)

maxAttempts := 60 * multiplier
for i := 0; i < maxAttempts; i++ {
err = getIP()
if err == nil {
break
}
time.Sleep(2 * time.Second)
log.Debugf("Searching for %s in %s (attempt %d/%d)", d.MACAddress, common.LeasesPath, i+1, maxAttempts)
}

if err == nil {
Expand Down
Loading