From 68cf778a4c1ea03c787cca003713d6c29475952a Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Sat, 1 Jun 2024 18:03:18 +0200 Subject: [PATCH] fix: return last known pid when scaled down When the pod is scaled down we need to return the last known pid, else runc will be called, which will error as the checkpointed container cannot be found. This fixes the shim being restarted during a containerd restart. --- runc/task/service_zeropod.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runc/task/service_zeropod.go b/runc/task/service_zeropod.go index 83b3075..1f022e1 100644 --- a/runc/task/service_zeropod.go +++ b/runc/task/service_zeropod.go @@ -13,6 +13,7 @@ import ( "github.com/containerd/cgroups" taskAPI "github.com/containerd/containerd/api/runtime/task/v2" + "github.com/containerd/containerd/api/types/task" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/pkg/cri/annotations" "github.com/containerd/containerd/pkg/oom" @@ -198,6 +199,18 @@ func (w *wrapper) Exec(ctx context.Context, r *taskAPI.ExecProcessRequest) (*emp return w.service.Exec(ctx, r) } +func (w *wrapper) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.PidsResponse, error) { + zeropodContainer, ok := w.getZeropodContainer(r.ID) + if ok && zeropodContainer.ScaledDown() { + log.G(ctx).Debugf("pids of scaled down container, returning last known pid: %v", zeropodContainer.Pid()) + return &taskAPI.PidsResponse{ + Processes: []*task.ProcessInfo{{Pid: uint32(zeropodContainer.Pid())}}, + }, nil + } + + return w.service.Pids(ctx, r) +} + func (w *wrapper) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAPI.DeleteResponse, error) { zeropodContainer, ok := w.getZeropodContainer(r.ID) if !ok {