execInNode: do not read logreader too early, because that clears it for other read processes

This commit is contained in:
iwilltry42 2020-10-19 14:36:49 +02:00
parent b69b874098
commit 425b9b709e
No known key found for this signature in database
GPG Key ID: 7BA57AD1CFF16110
2 changed files with 13 additions and 16 deletions

View File

@ -91,7 +91,7 @@ func resolveHostnameFromInside(ctx context.Context, rtime rt.Runtime, node *k3d.
if execErr != nil { if execErr != nil {
return nil, execErr return nil, execErr
} }
return nil, fmt.Errorf("Failed to scan logs for host IP") return nil, fmt.Errorf("Failed to scan logs for host IP: Could not create scanner from logreader")
} }
if scanner != nil && execErr != nil { 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.Debugln("Exec Process Failed, but we still got logs, so we're at least trying to get the IP from there...")

View File

@ -318,7 +318,15 @@ func (d Docker) ExecInNodeGetLogs(ctx context.Context, node *k3d.Node, cmd []str
// ExecInNode execs a command inside a node // ExecInNode execs a command inside a node
func (d Docker) ExecInNode(ctx context.Context, node *k3d.Node, cmd []string) error { func (d Docker) ExecInNode(ctx context.Context, node *k3d.Node, cmd []string) error {
_, err := executeInNode(ctx, node, cmd) execConnection, err := executeInNode(ctx, node, cmd)
if err != nil {
logs, err := ioutil.ReadAll(execConnection.Reader)
if err != nil {
log.Errorf("Failed to get logs from errored exec process in node '%s'", node.Name)
return err
}
err = fmt.Errorf("%w: Logs from failed access process:\n%s", err, string(logs))
}
return err return err
} }
@ -384,22 +392,11 @@ func executeInNode(ctx context.Context, node *k3d.Node, cmd []string) (*types.Hi
// check exitcode // check exitcode
if execInfo.ExitCode == 0 { // success if execInfo.ExitCode == 0 { // success
log.Debugf("Exec process in node '%s' exited with '0'", node.Name) log.Debugf("Exec process in node '%s' exited with '0'", node.Name)
break return &execConnection, nil
} } else { // failed
return &execConnection, fmt.Errorf("Exec process in node '%s' failed with exit code '%d'", node.Name, execInfo.ExitCode)
if execInfo.ExitCode != 0 { // failed
logs, err := ioutil.ReadAll(execConnection.Reader)
if err != nil {
log.Errorf("Failed to get logs from node '%s'", node.Name)
return &execConnection, err
}
return &execConnection, fmt.Errorf("Logs from failed access process:\n%s", string(logs))
} }
} }
return &execConnection, nil
} }