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: 1 addition & 1 deletion cmd/minikube/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
// Force exp dependency
_ "golang.org/x/exp/ebnf"

mlog "k8s.io/minikube/pkg/libmachine/log"
mlog "k8s.io/minikube/pkg/libmachine/diagnostics"

"github.com/google/slowjam/pkg/stacklog"
"github.com/pkg/profile"
Expand Down
4 changes: 2 additions & 2 deletions pkg/drivers/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"path/filepath"
"syscall"

"k8s.io/minikube/pkg/libmachine/diagnostics"
"k8s.io/minikube/pkg/libmachine/drivers"
"k8s.io/minikube/pkg/libmachine/log"
"k8s.io/minikube/pkg/libmachine/mcnflag"
"k8s.io/minikube/pkg/libmachine/mcnutils"
"k8s.io/minikube/pkg/libmachine/ssh"
Expand Down Expand Up @@ -55,7 +55,7 @@ func ExtraDiskPath(d *drivers.BaseDriver, diskID int) string {
// path := ExtraDiskPath(baseDriver, diskID)
// err := CreateRawDisk(path, baseDriver.DiskSize)
func CreateRawDisk(diskPath string, sizeMB int) error {
log.Infof("Creating raw disk image: %s of size %vMB", diskPath, sizeMB)
diagnostics.Infof("Creating raw disk image: %s of size %vMB", diskPath, sizeMB)

_, err := os.Stat(diskPath)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions pkg/drivers/common/dhcp/lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"strings"
"time"

"k8s.io/minikube/pkg/libmachine/log"
"k8s.io/minikube/pkg/libmachine/diagnostics"
"k8s.io/minikube/pkg/minikube/detect"
)

Expand Down Expand Up @@ -65,18 +65,18 @@ func WaitForLease(mac string, timeout time.Duration) (string, error) {
return "", err
}
if detect.NestedVM() {
log.Debugf("Nested VM detected, increasing timeout from %s to %s", timeout, timeout*3)
diagnostics.Debugf("Nested VM detected, increasing timeout from %s to %s", timeout, timeout*3)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not a good change. Logs should use log, and we should close the issue - it is invalid. There is no issue with shadowing the standard go package since we don't use it.

timeout *= 3
}
log.Infof("Waiting for DHCP lease for %s (timeout %s)", mac, timeout)
diagnostics.Infof("Waiting for DHCP lease for %s (timeout %s)", mac, timeout)

start := time.Now()
deadline := start.Add(timeout)
for i := 0; ; i++ {
log.Debugf("Searching for %s in %s (attempt %d) ...", mac, leasesPath, i)
diagnostics.Debugf("Searching for %s in %s (attempt %d) ...", mac, leasesPath, i)
ip, err := ipAddressFromFile(macAddress, leasesPath)
if err == nil {
log.Infof("Found DHCP lease for %s: %s in %.3f seconds", mac, ip, time.Since(start).Seconds())
diagnostics.Infof("Found DHCP lease for %s: %s in %.3f seconds", mac, ip, time.Since(start).Seconds())
return ip, nil
}
if time.Now().After(deadline) {
Expand Down Expand Up @@ -141,7 +141,7 @@ func parseLeases(r io.Reader) ([]Entry, error) {
case "hw_address":
hwType, hwAddr, ok := strings.Cut(val, ",")
if !ok {
log.Warnf("invalid hw_address in dhcp leases file: %q", val)
diagnostics.Warnf("invalid hw_address in dhcp leases file: %q", val)
continue
}
switch hwType {
Expand All @@ -150,7 +150,7 @@ func parseLeases(r io.Reader) ([]Entry, error) {
// Example: hw_address=1,52:e9:a0:9b:7d:7b
macAddress, err := parseMAC(hwAddr)
if err != nil {
log.Warnf("unable to parse hw_address in dhcp leases file: %q: %s", val, err)
diagnostics.Warnf("unable to parse hw_address in dhcp leases file: %q: %s", val, err)
continue
}
entry.HWAddress = macAddress
Expand All @@ -160,7 +160,7 @@ func parseLeases(r io.Reader) ([]Entry, error) {
// Minikube VMs always use Ethernet so they never create these entries,
// but other VMs on the same host may.
default:
log.Warnf("unknown hw_address type in dhcp leases file: %q", val)
diagnostics.Warnf("unknown hw_address type in dhcp leases file: %q", val)
}
case "identifier":
entry.ID = val
Expand Down
16 changes: 8 additions & 8 deletions pkg/drivers/common/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"strconv"
"time"

"k8s.io/minikube/pkg/libmachine/diagnostics"
"k8s.io/minikube/pkg/libmachine/drivers"
"k8s.io/minikube/pkg/libmachine/log"
)

const (
Expand Down Expand Up @@ -60,7 +60,7 @@ func WaitForSSHAccess(d drivers.Driver) error {
return err
}
addr := net.JoinHostPort(ip, strconv.Itoa(port))
log.Infof("Waiting until SSH server %q is accessible", addr)
diagnostics.Infof("Waiting until SSH server %q is accessible", addr)

start := time.Now()
deadline := start.Add(timeout)
Expand All @@ -73,7 +73,7 @@ func WaitForSSHAccess(d drivers.Driver) error {
return err
}
if done {
log.Infof("SSH server %q is accessible in %.3f seconds", addr, time.Since(start).Seconds())
diagnostics.Infof("SSH server %q is accessible in %.3f seconds", addr, time.Since(start).Seconds())
return nil
}
if time.Since(checkStart) < retryThreshold {
Expand All @@ -91,29 +91,29 @@ func checkSSHAccess(dialer *net.Dialer, addr string) (bool, error) {
return false, fmt.Errorf("timeout waiting for SSH server %q", addr)
}

log.Debugf("Dialing to SSH server %q", addr)
diagnostics.Debugf("Dialing to SSH server %q", addr)
conn, err := dialer.Dial("tcp", addr)
if err != nil {
if errors.Is(err, os.ErrDeadlineExceeded) {
return false, fmt.Errorf("timeout dialing to SSH server %q", addr)
}
log.Debugf("Failed to dial: %v", err)
diagnostics.Debugf("Failed to dial: %v", err)
return false, nil
}

defer conn.Close()

if err := conn.SetReadDeadline(dialer.Deadline); err != nil {
log.Debugf("Failed to set timeout: %v", err)
diagnostics.Debugf("Failed to set timeout: %v", err)
return false, nil
}

log.Debugf("Reading from SSH server %q", addr)
diagnostics.Debugf("Reading from SSH server %q", addr)
if _, err := conn.Read(make([]byte, 1)); err != nil && err != io.EOF {
if errors.Is(err, os.ErrDeadlineExceeded) {
return false, fmt.Errorf("timeout reading from SSH server %q", addr)
}
log.Debugf("Failed to read: %v", err)
diagnostics.Debugf("Failed to read: %v", err)
return false, nil
}

Expand Down
36 changes: 18 additions & 18 deletions pkg/drivers/common/vmnet/vmnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
"golang.org/x/sys/unix"
"gopkg.in/yaml.v2"

"k8s.io/minikube/pkg/libmachine/log"
"k8s.io/minikube/pkg/libmachine/diagnostics"
"k8s.io/minikube/pkg/libmachine/state"
"k8s.io/minikube/pkg/minikube/detect"
"k8s.io/minikube/pkg/minikube/out"
Expand Down Expand Up @@ -142,7 +142,7 @@ func ValidateHelper(options *run.CommandOptions) error {
// is called from different places in different drivers, so the easier way
// to skip validation is to skip it here.
if options.DownloadOnly {
log.Debug("Skipping vmnet-helper validation in download-only mode")
diagnostics.Debug("Skipping vmnet-helper validation in download-only mode")
return nil
}

Expand All @@ -157,7 +157,7 @@ func ValidateHelper(options *run.CommandOptions) error {
}
}

log.Debugf("Validated vmnet-helper (path=%q, version=%q, commit=%q, needsSudo=%v)",
diagnostics.Debugf("Validated vmnet-helper (path=%q, version=%q, commit=%q, needsSudo=%v)",
helper.Path, helper.Version.Version, helper.Version.Commit, helper.NeedsSudo)

return nil
Expand Down Expand Up @@ -218,7 +218,7 @@ func (h *Helper) Start(socketPath string) error {
return fmt.Errorf("failed to start vmnet-helper: %w", err)
}

log.Infof("Started vmnet-helper (pid=%v)", cmd.Process.Pid)
diagnostics.Infof("Started vmnet-helper (pid=%v)", cmd.Process.Pid)

if err := process.WritePidfile(h.pidfilePath(), cmd.Process.Pid); err != nil {
return fmt.Errorf("failed to write vmnet-helper pidfile: %w", err)
Expand All @@ -227,16 +227,16 @@ func (h *Helper) Start(socketPath string) error {
var info interfaceInfo
if err := json.NewDecoder(stdout).Decode(&info); err != nil {
if data, err := os.ReadFile(logfile.Name()); err == nil {
log.Infof("vmnet-helper logfile %q content:\n%s", logfile.Name(), string(data))
diagnostics.Infof("vmnet-helper logfile %q content:\n%s", logfile.Name(), string(data))
} else {
log.Infof("failed to read vmnet-helper logfile %q: %s", logfile.Name(), err)
diagnostics.Infof("failed to read vmnet-helper logfile %q: %s", logfile.Name(), err)
}
return fmt.Errorf("failed to decode vmnet interface info: %w", err)
}

h.macAddress = info.MACAddress
if h.InterfaceID != "" {
log.Infof("Got mac address %q", info.MACAddress)
diagnostics.Infof("Got mac address %q", info.MACAddress)
}

return nil
Expand All @@ -250,7 +250,7 @@ func (h *Helper) GetMACAddress() string {
// Stop terminates the executable. If running with sudo, sudo will terminate the
// helper.
func (h *Helper) Stop() error {
log.Info("Stop vmnet-helper")
diagnostics.Info("Stop vmnet-helper")
pidfile := h.pidfilePath()
pid, err := process.ReadPidfile(pidfile)
if err != nil {
Expand All @@ -261,14 +261,14 @@ func (h *Helper) Stop() error {
return nil
}
name := h.executableName()
log.Debugf("Terminate %s (pid=%v)", name, pid)
diagnostics.Debugf("Terminate %s (pid=%v)", name, pid)
if err := process.Terminate(pid, name); err != nil {
if err != os.ErrProcessDone {
return err
}
// No process, stale pidfile.
if err := os.Remove(pidfile); err != nil {
log.Debugf("failed to remove %q: %s", pidfile, err)
diagnostics.Debugf("failed to remove %q: %s", pidfile, err)
}
}
return nil
Expand All @@ -277,7 +277,7 @@ func (h *Helper) Stop() error {
// Kill the entire process group. If running with sudo, both sudo and
// vmnet-helper will be killed.
func (h *Helper) Kill() error {
log.Info("Kill vmnet-helper")
diagnostics.Info("Kill vmnet-helper")
pidfile := h.pidfilePath()
pid, err := process.ReadPidfile(pidfile)
if err != nil {
Expand All @@ -295,18 +295,18 @@ func (h *Helper) Kill() error {
if !exists {
// No process, stale pidfile.
if err := os.Remove(pidfile); err != nil {
log.Debugf("failed to remove %q: %s", pidfile, err)
diagnostics.Debugf("failed to remove %q: %s", pidfile, err)
}
return nil
}
log.Debugf("Kill vmnet-helper process group (pgid=%v)", pid)
diagnostics.Debugf("Kill vmnet-helper process group (pgid=%v)", pid)
if err := syscall.Kill(-pid, syscall.SIGKILL); err != nil {
if err != syscall.ESRCH {
return err
}
// No process, stale pidfile.
if err := os.Remove(pidfile); err != nil {
log.Debugf("failed to remove %q: %s", pidfile, err)
diagnostics.Debugf("failed to remove %q: %s", pidfile, err)
}
}
return nil
Expand All @@ -331,7 +331,7 @@ func (h *Helper) GetState() (state.State, error) {
if !exists {
// No process, stale pidfile.
if err := os.Remove(pidfile); err != nil {
log.Debugf("failed to remove %q: %s", pidfile, err)
diagnostics.Debugf("failed to remove %q: %s", pidfile, err)
}
return state.Stopped, nil
}
Expand Down Expand Up @@ -408,7 +408,7 @@ func validateRunningWithSudo(helperPath string, options *run.CommandOptions) err
return &Error{Kind: reason.NotConfiguredVmnetHelper, Err: err}
}

log.Debugf("Unable to run vmnet-helper without a password: %v", err)
diagnostics.Debugf("Unable to run vmnet-helper without a password: %v", err)

// We can fall back to interactive sudo this time, but the user should
// configure a sudoers rule.
Expand All @@ -428,11 +428,11 @@ func validateRunningWithSudo(helperPath string, options *run.CommandOptions) err
return &Error{Kind: reason.NotConfiguredVmnetHelper, Err: err}
}

log.Debugf("Authenticated user with sudo")
diagnostics.Debugf("Authenticated user with sudo")
return nil
}

log.Debug("Validated running vmnet-helper without a password")
diagnostics.Debug("Validated running vmnet-helper without a password")
return nil
}

Expand Down
Loading