Skip to content

Commit 01155b1

Browse files
authored
Merge pull request #12319 from andriyDev/UseWSLIP
Select WSL VM IP when performing mounting
2 parents c8a405a + 4052359 commit 01155b1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

cmd/minikube/cmd/mount.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/spf13/cobra"
3232
"k8s.io/klog/v2"
3333
"k8s.io/minikube/pkg/minikube/cluster"
34+
"k8s.io/minikube/pkg/minikube/detect"
3435
"k8s.io/minikube/pkg/minikube/driver"
3536
"k8s.io/minikube/pkg/minikube/exit"
3637
"k8s.io/minikube/pkg/minikube/mustload"
@@ -111,7 +112,19 @@ var mountCmd = &cobra.Command{
111112
var ip net.IP
112113
var err error
113114
if mountIP == "" {
114-
ip, err = cluster.HostIP(co.CP.Host, co.Config.Name)
115+
if detect.IsMicrosoftWSL() {
116+
klog.Infof("Selecting IP for WSL. This may be incorrect...")
117+
ip, err = func() (net.IP, error) {
118+
conn, err := net.Dial("udp", "8.8.8.8:80")
119+
if err != nil {
120+
return nil, err
121+
}
122+
defer conn.Close()
123+
return conn.LocalAddr().(*net.UDPAddr).IP, nil
124+
}()
125+
} else {
126+
ip, err = cluster.HostIP(co.CP.Host, co.Config.Name)
127+
}
115128
if err != nil {
116129
exit.Error(reason.IfHostIP, "Error getting the host IP address to use from within the VM", err)
117130
}

0 commit comments

Comments
 (0)