Skip to content

Commit

Permalink
Merge pull request #9342 from tstromberg/logs-api
Browse files Browse the repository at this point in the history
hyperv: Make interface search name match case-insensitive
  • Loading branch information
medyagh authored Sep 29, 2020
2 parents 0d6b6fc + d34a240 commit 09dd4b7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/minikube/cluster/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func HostIP(host *host.Host) (net.IP, error) {
for i := 0; i < v.NumField(); i++ {
if v.Type().Field(i).Name == "VSwitch" {
hypervVirtualSwitch = v.Field(i).Interface().(string)

break
}
}
Expand All @@ -59,6 +60,7 @@ func HostIP(host *host.Host) (net.IP, error) {
if err != nil {
return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch))
}

return ip, nil
case driver.VirtualBox:
vBoxManageCmd := driver.VBoxManagePath()
Expand All @@ -74,6 +76,7 @@ func HostIP(host *host.Host) (net.IP, error) {
}
re = regexp.MustCompile(`(?sm)Name:\s*` + iface + `\s*$.+?IPAddress:\s*(\S+)`)
ip := re.FindStringSubmatch(string(ipList))[1]

return net.ParseIP(ip), nil
case driver.Parallels:
bin := "prlsrvctl"
Expand All @@ -93,6 +96,7 @@ func HostIP(host *host.Host) (net.IP, error) {
return []byte{}, errors.Wrap(err, "Error getting the IP address of Parallels Shared network interface")
}
ip := ipMatch[1]

return net.ParseIP(ip), nil
case driver.HyperKit:
return net.ParseIP("192.168.64.1"), nil
Expand Down Expand Up @@ -136,26 +140,33 @@ func DriverIP(api libmachine.API, machineName string) (net.IP, error) {

// Based on code from http://stackoverflow.com/questions/23529663/how-to-get-all-addresses-and-masks-from-local-interfaces-in-go
func getIPForInterface(name string) (net.IP, error) {
glog.Infof("getIPForInterface: searching for %q", name)
ints, err := net.Interfaces()
if err != nil {
return nil, err
}

var i net.Interface
for _, in := range ints {
if strings.HasPrefix(in.Name, name) {
if strings.HasPrefix(strings.ToLower(in.Name), strings.ToLower(name)) {
glog.Infof("found prefix matching interface for %q: %q", name, in.Name)
i = in

break
}
glog.Infof("%q does not match prefix %q", in.Name, name)
}

// Didn't find prefix, let's try any substring
if i.Name == "" {
for _, in := range ints {
if strings.Contains(in.Name, name) {
if strings.Contains(strings.ToLower(in.Name), strings.ToLower(name)) {
glog.Infof("found substring matching interface for %q: %q", name, in.Name)
i = in

break
}
glog.Infof("%q does not match substring %q", in.Name, name)
}
}

Expand All @@ -164,14 +175,15 @@ func getIPForInterface(name string) (net.IP, error) {
return nil, errors.Errorf("Could not find interface %s inside %+v", name, ints)
}

glog.Infof("Found hyperv interface: %+v\n", i)
glog.Infof("Found interface: %+v\n", i)
addrs, _ := i.Addrs()
for _, a := range addrs {
glog.Infof("interface addr: %+v", a)
if ipnet, ok := a.(*net.IPNet); ok {
if ip := ipnet.IP.To4(); ip != nil {
return ip, nil
}
}
}
return nil, errors.Errorf("Error finding IPV4 address for %s", name)
return nil, errors.Errorf("Unable to find a IPv4 address for interface %q", name)
}

0 comments on commit 09dd4b7

Please sign in to comment.