Skip to content

Commit f6367a9

Browse files
committed
Include last error when waiting for containerd failed
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]>
1 parent c03b63e commit f6367a9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

pkg/component/worker/containerd/component.go

+13-3
Original file line numberDiff line numberDiff line change
@@ -169,18 +169,28 @@ func (c *Component) Start(ctx context.Context) error {
169169
go c.watchDropinConfigs(ctx)
170170

171171
log.Debug("Waiting for containerd")
172-
return wait.ExponentialBackoffWithContext(ctx, wait.Backoff{
172+
var lastErr error
173+
err := wait.ExponentialBackoffWithContext(ctx, wait.Backoff{
173174
Duration: 100 * time.Millisecond, Factor: 1.2, Jitter: 0.05, Steps: 30,
174175
}, func(ctx context.Context) (bool, error) {
175176
rt := containerruntime.NewContainerRuntime(runtimeEndpoint)
176-
if err := rt.Ping(ctx); err != nil {
177-
log.WithError(err).Debug("Failed to ping containerd")
177+
if lastErr = rt.Ping(ctx); lastErr != nil {
178+
log.WithError(lastErr).Debug("Failed to ping containerd")
178179
return false, nil
179180
}
180181

181182
log.Debug("Successfully pinged containerd")
182183
return true, nil
183184
})
185+
186+
if err != nil {
187+
if lastErr == nil {
188+
return fmt.Errorf("failed to ping containerd: %w", err)
189+
}
190+
return fmt.Errorf("failed to ping containerd: %w (%w)", err, lastErr)
191+
}
192+
193+
return nil
184194
}
185195

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

0 commit comments

Comments
 (0)