Skip to content

Commit

Permalink
Attempt to print out Redpanda's stderr on failure to start.
Browse files Browse the repository at this point in the history
(cherry picked from commit 7bc34ba)
  • Loading branch information
voutilad authored and r-vasquez committed Apr 10, 2024
1 parent 404efaf commit 7494186
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/go/rpk/pkg/cli/container/common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ type Client interface {
options types.ContainerListOptions,
) ([]types.Container, error)

ContainerLogs(
ctx context.Context,
containerID string,
options types.ContainerLogsOptions,
) (io.ReadCloser, error)

ContainerInspect(
ctx context.Context,
containerID string,
Expand Down
35 changes: 34 additions & 1 deletion src/go/rpk/pkg/cli/container/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package container

import (
"bufio"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -336,7 +337,39 @@ func restartCluster(
}
err = waitForCluster(check(nodes), retries)
if err != nil {
return nil, err
// Attempt to fetch the latest stderr output from the first
// Redpanda node. It may reveal reasons for failing to start.
ctx, _ := common.DefaultCtx()
state := states[0]

json, errInspect := c.ContainerInspect(ctx, state.ContainerID)
if errInspect != nil {
return nil, fmt.Errorf("%v\n%v", err, errInspect)
}

reader, errLogs := c.ContainerLogs(
ctx,
state.ContainerID,
types.ContainerLogsOptions{
ShowStdout: false,
ShowStderr: true,
Since: json.State.StartedAt,
},
)
if errLogs != nil {
return nil, fmt.Errorf("%v\nCould not get container logs: %v", err, errLogs)
}

scanner := bufio.NewScanner(reader)
errStr := ""
for scanner.Scan() {
errStr += scanner.Text() + "\n"
}
return nil, fmt.Errorf(
"%v\nErrors reported from the Docker container:\n%v",
err,
errors.New(errStr),
)
}
return nodes, nil
}
Expand Down

0 comments on commit 7494186

Please sign in to comment.