createCluster: Fix getHostIP edge cases

- sometimes, the exec process returns a non-zero exit code but still has
logs which are helpful for us
- sometimes everything fails and we should gracefully handle this
This commit is contained in:
iwilltry42 2020-10-07 11:02:46 +02:00
parent 11cc797922
commit c27410ea32
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
2 changed files with 11 additions and 1 deletions

View File

@ -80,6 +80,16 @@ func resolveHostnameFromInside(ctx context.Context, rtime rt.Runtime, node *k3d.
submatches := map[string]string{}
scanner := bufio.NewScanner(logreader)
if scanner == nil {
if execErr != nil {
return nil, execErr
}
return nil, fmt.Errorf("Failed to scan logs for host IP")
}
if scanner != nil && execErr != nil {
log.Debugln("Exec Process Failed, but we still got logs, so we're at least trying to get the IP from there...")
log.Tracef("-> Exec Process Error was: %+v", execErr)
}
for scanner.Scan() {
log.Tracef("Scanning Log Line '%s'", scanner.Text())
match := nsLookupAddressRegexp.FindStringSubmatch(scanner.Text())

View File

@ -308,7 +308,7 @@ func (d Docker) GetNodeLogs(ctx context.Context, node *k3d.Node, since time.Time
func (d Docker) ExecInNodeGetLogs(ctx context.Context, node *k3d.Node, cmd []string) (*bufio.Reader, error) {
resp, err := executeInNode(ctx, node, cmd)
if err != nil {
return nil, err
return resp.Reader, err
}
return resp.Reader, nil
}