Skip to content

cri: skip pause image pull for shim sandboxer - #13424

Merged
mxpv merged 1 commit into
containerd:mainfrom
Apokleos:sb-without-pause
May 27, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
Apokleos:sb-without-pause

Conversation

@Apokleos

@Apokleos Apokleos commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Background

When using the Sandbox API with sandboxer = "shim" (e.g. Kata Containers), ensurePauseImageExists()
unconditionally pulls the pause image even though the shim controller never uses it. This PR skips the pull for
non-podsandbox sandboxers.

Solution

Gate the ensurePauseImageExists() call on sandbox.Sandboxer == "podsandbox":

type Runtime struct {
     ...
     DisablePullPauseImage bool `toml:"disable_pull_pause_image" json:"disablePullPauseImage"`
     ...
}

 if !ociRuntime.DisablePullPauseImage {
     if err := c.ensurePauseImageExists(ctx, r.GetConfig(), r.GetRuntimeHandler()); err != nil {
        return nil, err
      }
}

And the containerd config.toml with the disable_pull_pause_image looks like as below:

      [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes]
        [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.kata]
          runtime_type = 'io.containerd.kata.v2'
          runtime_path = ''
          pod_annotations = []
          container_annotations = []
          privileged_without_host_devices = false
          privileged_without_host_devices_all_devices_allowed = false
          cgroup_writable = false
          base_runtime_spec = ''
          cni_conf_dir = ''
          cni_max_conf_num = 0
          snapshotter = ''
          sandboxer = 'shim'
         disable_pull_pause_image = true
          io_type = ''

        [plugins.'io.containerd.cri.v1.runtime'.containerd.runtimes.runc]
          runtime_type = 'io.containerd.runc.v2'
          runtime_path = ''
          pod_annotations = []
          container_annotations = []
          privileged_without_host_devices = false
          privileged_without_host_devices_all_devices_allowed = false
          cgroup_writable = false
          base_runtime_spec = ''
          cni_conf_dir = ''
          cni_max_conf_num = 0
          snapshotter = ''
          sandboxer = 'podsandbox'
         disable_pull_pause_image = true
          io_type = ''

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the CRI RunPodSandbox flow to avoid pre-pulling the pause image when the sandbox is managed by a non-podsandbox controller (e.g., shim-based sandboxers like Kata), since those controllers do not use the pause image.

Changes:

  • Gate ensurePauseImageExists() so it runs only when sandbox.Sandboxer is the podsandbox controller.
  • Update the surrounding comment to clarify why the pause image pull is controller-specific.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cri/server/sandbox_run.go Resolved
Comment thread internal/cri/server/sandbox_run.go Resolved
@Apokleos
Apokleos force-pushed the sb-without-pause branch from 1492524 to d114ea9 Compare May 19, 2026 07:35
@Apokleos

Copy link
Copy Markdown
Contributor Author

hey @fuweid @mxpv @dmcgowan Could you please help review this PR ? Thx very much.

Copilot AI review requested due to automatic review settings May 19, 2026 07:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread internal/cri/server/sandbox_run_test.go Resolved
@Apokleos
Apokleos force-pushed the sb-without-pause branch from 90481bd to 9704986 Compare May 19, 2026 08:12
Copilot AI review requested due to automatic review settings May 19, 2026 08:13
@Apokleos
Apokleos force-pushed the sb-without-pause branch from 9704986 to 9089238 Compare May 19, 2026 08:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comment thread internal/cri/server/sandbox_run.go Outdated
}

func (c *criService) maybePullPauseImage(ctx context.Context, sandboxer string, config *runtime.PodSandboxConfig, runtimeHandler string) error {
if sandboxer != string(criconfig.ModePodSandbox) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how existing sandbox shims use this. Just feel like it's breaking change.

@Apokleos Apokleos May 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @fuweid. maybe we will have such concerns. If so, an alternative choice is adding a knob which is responsible for explicitly enabling it in containerd runtimeclass.

The code looks like as:

type Runtime struct {
     ...
     DisablePullPauseImage bool `toml:"disable_pull_pause_image" json:"disablePullPauseImage"`
     ...
}

 if !ociRuntime.DisablePullPauseImage {
     if err := c.ensurePauseImageExists(ctx, r.GetConfig(), r.GetRuntimeHandler()); err != nil {
        return nil, err
      }
}

The DisablePullPauseImage is set default false and it will skip the pause image handling logic only when it's set with true in config.toml .

With this design, it will not break the original pause image handling logic, it will just skip when you set disable_pull_pause_image = true in config.toml. WDYT ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @mxpv

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mxpv Looking forward to your feedback. Thx.

@mikebrow mikebrow May 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree to the idea of improving the sandboxer config by providing one..

Maybe something like this:

[plugins.'io.containerd.sandboxer.v1.podsandbox']
   disable_ensuring_pod_image = false  # if set to true the sandbox config does not require the sandbox container image to be ensured
   pod_image = `` # if specified (non-nil) overloads the default sandbox container image

[plugins.'io.containerd.sandboxer.v1.anothersandbox']
   disable_ensuring_pod_image = true  # if set to true the sandbox config does not require the sandbox container image to be ensured

possibly a sandboxer config .. right now podsandbox has some config/setup expectations and obviously those won't always match up.

@mxpv mxpv May 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long term desire is to offload pause container image pulling down to shim level (CRI calls Controller, implementation does the pull), so strictly speaking the originally proposed approach in this PR is more aligned (if not podsandbox, skip pull). Originally this code lived in podsandbox/ package, but moved back to CRI because of refactoring complexity (more context here #12849). Also I don't think having pause container outside of podsandbox containers brings a lot to the table. That said, I agree this is going to be a behavior change and if we want to be strict about it, then the config flag is the way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @mxpv for your professional advice and IMHO, I agree without breaking changes. I will update the code changes as like the snipt showed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree to the idea of improving the sandboxer config by providing one..

Maybe something like this:

[plugins.'io.containerd.sandboxer.v1.podsandbox']
   disable_ensuring_pod_image = false  # if set to true the sandbox config does not require the sandbox container image to be ensured
   pod_image = `` # if specified (non-nil) overloads the default sandbox container image

[plugins.'io.containerd.sandboxer.v1.anothersandbox']
   disable_ensuring_pod_image = true  # if set to true the sandbox config does not require the sandbox container image to be ensured

possibly a sandboxer config .. right now podsandbox has some config/setup expectations and obviously those won't always match up.

Thx @mikebrow for your advice.

@Apokleos
Apokleos force-pushed the sb-without-pause branch from 9089238 to 4ec99aa Compare May 22, 2026 02:33
@Apokleos
Apokleos requested review from fuweid, mikebrow and mxpv May 22, 2026 02:33
@Apokleos

Copy link
Copy Markdown
Contributor Author

Hey @fuweid @mxpv @mikebrow Could u please help review the updated codes. Thx

@mikebrow mikebrow left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

over here https://github.com/containerd/containerd/blob/main/docs/cri/config.md?plain=1#L296

on the next line after sandboxer = 'podsandbox'
add disable_pull_pause_image = false'

otherwise LGTM

@fuweid

fuweid commented May 22, 2026

Copy link
Copy Markdown
Member

It looks good but please squash your commits into one. Thanks

Copilot AI review requested due to automatic review settings May 25, 2026 01:31
@Apokleos
Apokleos force-pushed the sb-without-pause branch from 4ec99aa to 1f82f69 Compare May 25, 2026 01:31
@Apokleos
Apokleos requested a review from mikebrow May 25, 2026 01:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comment thread internal/cri/server/sandbox_run_test.go Resolved
Comment thread internal/cri/server/sandbox_run.go Resolved
Comment thread docs/cri/config.md Resolved
@Apokleos

Copy link
Copy Markdown
Contributor Author

@fuweid @mxpv @mikebrow I have updated the codes as your advice. PTAL. Appreciate it.

@Apokleos
Apokleos force-pushed the sb-without-pause branch from 1f82f69 to 93fa5b4 Compare May 25, 2026 02:20
Comment thread internal/cri/config/config.go Resolved
Comment thread docs/cri/config.md Resolved
Copilot AI review requested due to automatic review settings May 27, 2026 01:27
@Apokleos
Apokleos force-pushed the sb-without-pause branch from 93fa5b4 to 1d7ca38 Compare May 27, 2026 01:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread internal/cri/server/sandbox_run_test.go Resolved
Comment thread internal/cri/config/config.go Resolved
@Apokleos
Apokleos force-pushed the sb-without-pause branch from 1d7ca38 to 85cd3d1 Compare May 27, 2026 01:30
@Apokleos
Apokleos requested a review from mxpv May 27, 2026 01:31
The RunPodSandbox unconditionally pre-pulls the pause container
image via ensurePauseImageExists() before starting any sandbox.
However, only the "podsandbox" controller actually uses the pause
image to create a pause container holding namespaces. Shim-based
sandbox controllers (e.g. Kata Containers) manage the sandbox
lifecycle entirely at the shim level and never reference the pause
image.

Add a DisablePauseImagePull flag to the Runtime config that gates
ensurePauseImageExists(). When a sandboxer is not "podsandbox", the
flag skips the unnecessary pre-pull, avoiding wasted network/storage
overhead and reducing sandbox startup latency.

The long-term direction is to offload image pulling entirely to the
controller implementation (shim level); this flag is an incremental
step toward that goal without introducing a breaking behavior change.

Also add unit tests to verify that ensurePauseImageExists is only
invoked for the "podsandbox" sandboxer and correctly skipped otherwise.

Signed-off-by: Alex Lyn <[email protected]>
Copilot AI review requested due to automatic review settings May 27, 2026 20:53
@mikebrow
mikebrow force-pushed the sb-without-pause branch from 85cd3d1 to 8f7c7fb Compare May 27, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review May 27, 2026
@mxpv
mxpv added this pull request to the merge queue May 27, 2026
Merged via the queue into containerd:main with commit 54d5999 May 27, 2026
85 of 88 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants