Skip to content

cri: fix duplicated image env vars on checkpoint import - #13623

Merged
mxpv merged 1 commit into
containerd:mainfrom
yugstar:fix-13611-checkpoint-env-dedup
Jun 25, 2026
Merged

mxpv merged 1 commit into
containerd:mainfrom
yugstar:fix-13611-checkpoint-env-dedup

Conversation

@yugstar

@yugstar yugstar commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

CRImportCheckpoint built the combined environment (image env followed by the CRI container env) into a local slice, then re-appended that slice to imageConfig.Env, duplicating every image environment variable on the restored container.

This assigns the combined slice directly instead.

Fixes #13611

Copilot AI review requested due to automatic review settings June 18, 2026 16:06
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jun 18, 2026

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

Fixes an environment variable duplication bug during CRI checkpoint import by correctly merging image and container env vars without re-appending the image env list, and adds a Linux unit test to prevent regressions.

Changes:

  • Replace the env-building logic in CRImportCheckpoint with a dedicated mergeContainerEnvs helper to avoid duplicating image env vars.
  • Add mergeContainerEnvs helper to centralize and clarify env merge behavior (image envs first, CRI envs appended).
  • Add a Linux unit test validating ordering and no-duplication regression for checkpoint import env merging.

Reviewed changes

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

File Description
internal/cri/server/container_checkpoint_linux.go Fix env merge logic during checkpoint import and introduce mergeContainerEnvs helper.
internal/cri/server/container_checkpoint_linux_test.go Add unit test covering env ordering and the no-duplication regression.

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

Comment on lines +757 to +759
// mergeContainerEnvs returns the image's environment with the CRI container's
// environment variables appended. The image variables appear once, followed by
// the container variables; the image variables are not duplicated.
Comment on lines +58 to +61
// The input image slice must not be mutated.
if len(imageEnv) != 2 {
t.Errorf("imageEnv was mutated, len = %d, want 2", len(imageEnv))
}
@yugstar
yugstar force-pushed the fix-13611-checkpoint-env-dedup branch from bd09ab9 to 1f86afa Compare June 18, 2026 16:13
@yugstar

yugstar commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, both good points and applied in the latest push:

  1. Reworded the helper comment to describe the ordering and override semantics (image vars first, container vars appended and taking precedence on duplicate keys) and to say it does not re-append the image environment, rather than claiming it dedupes.
  2. Strengthened the non-mutation assertion to compare the image slice contents, not just its length.

Comment on lines +762 to +768
func mergeContainerEnvs(imageEnv []string, criEnvs []*runtime.KeyValue) []string {
env := append([]string{}, imageEnv...)
for _, e := range criEnvs {
env = append(env, e.GetKey()+"="+e.GetValue())
}
return env
}

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.

can we just fix this in place? i don't feel it worths a separate function TBH.

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.

Good call, done. Simplified to the in-place fix (assign the combined slice to imageConfig.Env directly) and dropped the helper and its test.

CRImportCheckpoint built the combined environment (image env followed by
the CRI container env) into a local slice, then re-appended that slice to
imageConfig.Env, duplicating every image environment variable on the
restored container. Assign the combined slice directly instead.

Fixes containerd#13611

Signed-off-by: Aman Raj <[email protected]>
Copilot AI review requested due to automatic review settings June 18, 2026 16:34
@yugstar
yugstar force-pushed the fix-13611-checkpoint-env-dedup branch from 1f86afa to 6a677e0 Compare June 18, 2026 16:34

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 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines 369 to +374
imageConfig := image.ImageSpec.Config
env := append([]string{}, imageConfig.Env...)
for _, e := range meta.Config.GetEnvs() {
env = append(env, e.GetKey()+"="+e.GetValue())
}
imageConfig.Env = append(imageConfig.Env, env...)
imageConfig.Env = env
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jun 25, 2026
@mxpv
mxpv added this pull request to the merge queue Jun 25, 2026
Merged via the queue into containerd:main with commit 99d01fc Jun 25, 2026
87 of 88 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 25, 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.

double up of image config envs on import checkpoint

6 participants