Skip to content

Commit

Permalink
waitForLogs: enrich error with scanner error if any
Browse files Browse the repository at this point in the history
  • Loading branch information
iwilltry42 committed Dec 4, 2021
1 parent 61f52cc commit ca47fac
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/client/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,9 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node *

}(ctx, runtime, node, since, donechan)

// pre-building error message in case the node stops returning logs for some reason: to be enriched with scanner error
errMsg := fmt.Errorf("error waiting for log line `%s` from node '%s': stopped returning log lines", message, node.Name)

// Start loop to check log stream for specified log message.
// We're looping here, as sometimes the containers run into a crash loop, but *may* recover from that
// e.g. when a new server is joining an existing cluster and has to wait for another member to finish learning.
Expand Down Expand Up @@ -792,6 +795,10 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node *

}

if e := scanner.Err(); e != nil {
errMsg = fmt.Errorf("%v: %w", errMsg, e)
}

out.Close() // no more input on scanner, but target log not yet found -> close current logreader (precautionary)

// we got here, because the logstream ended (no more input on scanner), so we check if maybe the container crashed
Expand All @@ -806,7 +813,7 @@ func NodeWaitForLogMessage(ctx context.Context, runtime runtimes.Runtime, node *
break
}
}
return fmt.Errorf("error waiting for log line `%s` from node '%s': stopped returning log lines", message, node.Name)
return errMsg
}

// NodeFilterByRoles filters a list of nodes by their roles
Expand Down

0 comments on commit ca47fac

Please sign in to comment.