From 025e3ea6ab9c16879738cb489255b317e76d7147 Mon Sep 17 00:00:00 2001 From: liubin Date: Wed, 29 Jun 2022 12:33:32 +0800 Subject: [PATCH] shim: set a non-zero return code if the wait process call failed. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return code is an int32 type, so if an error occurred, the default value may be zero, this value will be created as a normal exit code. Set return code to 255 will let the caller(for example Kubernetes) know that there are some problems with the pod/container. Fixes: #4419 Signed-off-by: liubin (cherry picked from commit ab5f1c9564fcdf4d5797db9b3f59333061ec6df2) Signed-off-by: Fabiano FidĂȘncio --- src/runtime/pkg/containerd-shim-v2/wait.go | 5 +++++ src/runtime/virtcontainers/sandbox.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/runtime/pkg/containerd-shim-v2/wait.go b/src/runtime/pkg/containerd-shim-v2/wait.go index 5e86149c1a..dfe880ff4e 100644 --- a/src/runtime/pkg/containerd-shim-v2/wait.go +++ b/src/runtime/pkg/containerd-shim-v2/wait.go @@ -53,6 +53,11 @@ func wait(ctx context.Context, s *service, c *container, execID string) (int32, "container": c.id, "pid": processID, }).Error("Wait for process failed") + + // set return code if wait failed + if ret == 0 { + ret = exitCode255 + } } timeStamp := time.Now() diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 9e1ac02b50..08dc8f8b10 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -1593,7 +1593,7 @@ func (s *Sandbox) ResumeContainer(ctx context.Context, containerID string) error } // createContainers registers all containers, create the -// containers in the guest and starts one shim per container. +// containers in the guest. func (s *Sandbox) createContainers(ctx context.Context) error { span, ctx := katatrace.Trace(ctx, s.Logger(), "createContainers", sandboxTracingTags, map[string]string{"sandbox_id": s.id}) defer span.End()