From a2817ca16dbf9e03f2c6a32b203fc547d6248c57 Mon Sep 17 00:00:00 2001 From: Danny Canter Date: Mon, 28 Aug 2023 12:42:35 -0700 Subject: [PATCH] CRI: Include sandbox ID in failed to load error The failed to recover state message didn't include the ID making this not as useful as it could be.. This additionally moves some of the other logs to include the id for the sandbox/container as a field instead of part of a format string. Signed-off-by: Danny Canter --- pkg/cri/sbserver/restart.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/pkg/cri/sbserver/restart.go b/pkg/cri/sbserver/restart.go index 070e405be..f7596e9ef 100644 --- a/pkg/cri/sbserver/restart.go +++ b/pkg/cri/sbserver/restart.go @@ -76,7 +76,11 @@ func (c *criService) recover(ctx context.Context) error { eg.Go(func() error { sb, err := podSandboxLoader.RecoverContainer(ctx2, sandbox) if err != nil { - log.G(ctx2).WithError(err).Errorf("Failed to load sandbox %q", sandbox.ID()) + log.G(ctx2). + WithError(err). + WithField("sandbox", sandbox.ID()). + Error("Failed to load sandbox") + return nil } log.G(ctx2).Debugf("Loaded sandbox %+v", sb) @@ -116,7 +120,11 @@ func (c *criService) recover(ctx context.Context) error { status, err := controller.Status(ctx, sbx.ID, false) if err != nil { - log.G(ctx).WithError(err).Error("failed to recover sandbox state") + log.G(ctx). + WithError(err). + WithField("sandbox", sbx.ID). + Error("failed to recover sandbox state") + if errdefs.IsNotFound(err) { state = sandboxstore.StateNotReady } @@ -151,7 +159,11 @@ func (c *criService) recover(ctx context.Context) error { eg.Go(func() error { cntr, err := c.loadContainer(ctx2, container) if err != nil { - log.G(ctx2).WithError(err).Errorf("Failed to load container %q", container.ID()) + log.G(ctx2). + WithError(err). + WithField("container", container.ID()). + Error("Failed to load container") + return nil } log.G(ctx2).Debugf("Loaded container %+v", cntr)