Skip to content

Commit

Permalink
Include last error when waiting for containerd failed
Browse files Browse the repository at this point in the history
Without the last error, the error message will only be "timed out
waiting for the condition", which is not helpful at all.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Feb 22, 2025
1 parent c03b63e commit f6367a9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/component/worker/containerd/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,28 @@ func (c *Component) Start(ctx context.Context) error {
go c.watchDropinConfigs(ctx)

log.Debug("Waiting for containerd")
return wait.ExponentialBackoffWithContext(ctx, wait.Backoff{
var lastErr error
err := wait.ExponentialBackoffWithContext(ctx, wait.Backoff{
Duration: 100 * time.Millisecond, Factor: 1.2, Jitter: 0.05, Steps: 30,
}, func(ctx context.Context) (bool, error) {
rt := containerruntime.NewContainerRuntime(runtimeEndpoint)
if err := rt.Ping(ctx); err != nil {
log.WithError(err).Debug("Failed to ping containerd")
if lastErr = rt.Ping(ctx); lastErr != nil {
log.WithError(lastErr).Debug("Failed to ping containerd")
return false, nil
}

log.Debug("Successfully pinged containerd")
return true, nil
})

if err != nil {
if lastErr == nil {
return fmt.Errorf("failed to ping containerd: %w", err)
}
return fmt.Errorf("failed to ping containerd: %w (%w)", err, lastErr)
}

return nil
}

func (c *Component) windowsStart(_ context.Context) error {
Expand Down

0 comments on commit f6367a9

Please sign in to comment.