getHostIP: do not emit confusing warning that doesn't affect usability

pull/871/head
iwilltry42 3 years ago
parent 7bde77c36e
commit d78ef48932
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
  1. 19
      pkg/client/host.go

@ -84,15 +84,15 @@ func GetHostIP(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.Clust
return ip, nil
}
l.Log().Warnf("failed to resolve 'host.docker.internal' from inside the k3d-tools node: %v", err)
l.Log().Debugf("[GetHostIP on Docker Desktop] failed to resolve 'host.docker.internal' from inside the k3d-tools node: %v", err)
}
l.Log().Infof("HostIP: using network gateway...")
ip, err := runtime.GetHostIP(ctx, cluster.Network.Name)
if err != nil {
return nil, fmt.Errorf("runtime failed to get host IP: %w", err)
}
l.Log().Infof("HostIP: using network gateway %s address", ip)
return ip, nil
@ -105,20 +105,22 @@ func GetHostIP(ctx context.Context, runtime runtimes.Runtime, cluster *k3d.Clust
func resolveHostnameFromInside(ctx context.Context, rtime runtimes.Runtime, node *k3d.Node, hostname string, cmd ResolveHostCmd) (net.IP, error) {
errPrefix := fmt.Errorf("error resolving hostname %s from inside node %s", hostname, node.Name)
logreader, execErr := rtime.ExecInNodeGetLogs(ctx, node, []string{"sh", "-c", fmt.Sprintf(cmd.Cmd, hostname)})
if logreader == nil {
if execErr != nil {
return nil, execErr
return nil, fmt.Errorf("%v: %w", errPrefix, execErr)
}
return nil, fmt.Errorf("Failed to get logs from exec process")
return nil, fmt.Errorf("%w: failed to get logs from exec process", errPrefix)
}
submatches := map[string]string{}
scanner := bufio.NewScanner(logreader)
if scanner == nil {
if execErr != nil {
return nil, execErr
return nil, fmt.Errorf("%v: %w", errPrefix, execErr)
}
return nil, fmt.Errorf("Failed to scan logs for host IP: Could not create scanner from logreader")
}
@ -132,19 +134,18 @@ func resolveHostnameFromInside(ctx context.Context, rtime runtimes.Runtime, node
if len(match) == 0 {
continue
}
l.Log().Tracef("-> Match(es): '%+v'", match)
submatches = util.MapSubexpNames(cmd.LogMatcher.SubexpNames(), match)
l.Log().Tracef(" -> Submatch(es): %+v", submatches)
l.Log().Tracef("-> Match(es): '%+v' -> Submatch(es): %+v", match, submatches)
break
}
if _, ok := submatches["ip"]; !ok {
if execErr != nil {
l.Log().Errorln(execErr)
}
return nil, fmt.Errorf("Failed to read address for '%s' from command output", hostname)
return nil, fmt.Errorf("%w: failed to read address for '%s' from command output", errPrefix, hostname)
}
l.Log().Debugf("Hostname '%s' -> Address '%s'", hostname, submatches["ip"])
l.Log().Debugf("Hostname '%s' resolved to address '%s' inside node %s", hostname, submatches["ip"], node.Name)
return net.ParseIP(submatches["ip"]), nil

Loading…
Cancel
Save