Skip to content

Commit

Permalink
fix: return last known pid when scaled down
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctrox committed Jun 1, 2024
1 parent cf14cda commit 68cf778
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions runc/task/service_zeropod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 68cf778

Please sign in to comment.