Skip to content

Set SystemTemp env var to config temp on Windows#13667

Merged
samuelkarp merged 1 commit into
containerd:mainfrom
anmaxvl:windows-systemtemp-from-toml
Jun 30, 2026
Merged

Set SystemTemp env var to config temp on Windows#13667
samuelkarp merged 1 commit into
containerd:mainfrom
anmaxvl:windows-systemtemp-from-toml

Conversation

@anmaxvl

@anmaxvl anmaxvl commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Since Go 1.21, os.MkdirTemp/os.TempDir resolve the temp directory via Windows' GetTempPath2W. For processes running as SYSTEM (as containerd does when running under the SCM), that API reads the temp location from the SystemTemp environment variable rather than TMP/TEMP. As a result, the existing TMP/TEMP overrides no longer steer the layer-extraction tempdir for the containerd service, so it falls back to the default C:\Windows\SystemTemp and unpacks on the SystemDrive, reintroducing the cross-volume copy the 'temp' config option was meant to avoid.

Set SystemTemp to config.TempDir alongside TEMP/TMP so the override keeps working on Go 1.21+.

Factor the env-var setting out of CreateTopLevelDirectories into a small
setTempDirEnv helper and add a focused unit test (TestSetTempDirEnv) that
verifies the expected variables are set: TEMP/TMP/SystemTemp on Windows,
TMPDIR on other platforms.

Ref: https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/os/file_windows.go

Copilot AI review requested due to automatic review settings June 25, 2026 07:50
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Jun 25, 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

This PR updates containerd’s temp directory override behavior on Windows so that, when running as the SYSTEM account (typical for the containerd Windows service), Go 1.21+ still uses the configured temp directory instead of falling back to the default system temp path.

Changes:

  • On Windows, set SystemTemp to config.TempDir alongside the existing TEMP/TMP overrides.
  • Add inline rationale and a link to Go 1.21’s Windows tempdir resolution code for maintainability.

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

Comment thread cmd/containerd/server/server.go Outdated
@anmaxvl
anmaxvl force-pushed the windows-systemtemp-from-toml branch from 955acaf to 7ea5731 Compare June 25, 2026 07:53
Since Go 1.21, os.MkdirTemp/os.TempDir resolve the temp directory via
Windows' GetTempPath2W. For processes running as SYSTEM (as containerd
does when running under the SCM), that API reads the temp location from
the SystemTemp environment variable rather than TMP/TEMP. As a result,
the existing TMP/TEMP overrides no longer steer the layer-extraction
tempdir for the containerd service, so it falls back to the default
C:\\Windows\\SystemTemp and unpacks on the SystemDrive, reintroducing the
cross-volume copy the 'temp' config option was meant to avoid.

Set SystemTemp to config.TempDir alongside TEMP/TMP so the override keeps
working on Go 1.21+.

Factor the env-var setting out of CreateTopLevelDirectories into a small
setTempDirEnv helper and add a focused unit test (TestSetTempDirEnv) that
verifies the expected variables are set: TEMP/TMP/SystemTemp on Windows,
TMPDIR on other platforms.

Ref: https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/os/file_windows.go
Signed-off-by: Maksim An <[email protected]>
@anmaxvl
anmaxvl force-pushed the windows-systemtemp-from-toml branch from 7ea5731 to faff4d6 Compare June 25, 2026 08:08
Copilot AI review requested due to automatic review settings June 25, 2026 08:08
@kubernetes-prow kubernetes-prow Bot added size/M and removed size/XS labels Jun 25, 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

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

@anmaxvl

anmaxvl commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@kiashok , @apurv15 this one as well?

@anmaxvl

anmaxvl commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

@thaJeztah maybe?

@anmaxvl

anmaxvl commented Jun 29, 2026

Copy link
Copy Markdown
Contributor Author

@cpuguy83 ?

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jun 30, 2026
@samuelkarp
samuelkarp added this pull request to the merge queue Jun 30, 2026
Merged via the queue into containerd:main with commit 288f0d9 Jun 30, 2026
88 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jun 30, 2026
@thaJeztah

Copy link
Copy Markdown
Member

Ah, I somehow missed this one (sorry!) yes this is similar to what we did in moby;

I recall I left a comment on something similar here;#13008 (comment) probably needs to be double checked.

I would consider backporting this, as it lilely was a regression in containerd when it switched to go 1.21

@thaJeztah

Copy link
Copy Markdown
Member

/cherry-pick release/2.3

@thaJeztah

Copy link
Copy Markdown
Member

(let's see if it applies cleanly ☺️)

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@thaJeztah: new pull request created: #13694

Details

In response to this:

/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp

Copy link
Copy Markdown
Member

I would consider backporting this, as it lilely was a regression in containerd when it switched to go 1.21

Yes, this should probably be backported.

@samuelkarp

Copy link
Copy Markdown
Member

/cherry-pick release/2.2
/cherry-pick release/2.1
/cherry-pick release/2.0
/cherry-pick release/1.7

@samuelkarp samuelkarp added cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.1.x Change to be cherry picked to release/2.1 branch cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Jun 30, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13667 failed to apply on top of branch "release/1.7":

Applying: Set SystemTemp env var to config temp on Windows
Using index info to reconstruct a base tree...
A	cmd/containerd/server/server.go
A	cmd/containerd/server/server_test.go
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): cmd/containerd/server/server.go deleted in HEAD and modified in Set SystemTemp env var to config temp on Windows.  Version Set SystemTemp env var to config temp on Windows of cmd/containerd/server/server.go left in tree.
CONFLICT (modify/delete): cmd/containerd/server/server_test.go deleted in HEAD and modified in Set SystemTemp env var to config temp on Windows.  Version Set SystemTemp env var to config temp on Windows of cmd/containerd/server/server_test.go left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Set SystemTemp env var to config temp on Windows

Details

In response to this:

/cherry-pick release/2.2
/cherry-pick release/2.1
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13667 failed to apply on top of branch "release/2.0":

Applying: Set SystemTemp env var to config temp on Windows
Using index info to reconstruct a base tree...
M	cmd/containerd/server/server.go
M	cmd/containerd/server/server_test.go
Falling back to patching base and 3-way merge...
Auto-merging cmd/containerd/server/server.go
Auto-merging cmd/containerd/server/server_test.go
CONFLICT (content): Merge conflict in cmd/containerd/server/server_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Set SystemTemp env var to config temp on Windows

Details

In response to this:

/cherry-pick release/2.2
/cherry-pick release/2.1
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13667 failed to apply on top of branch "release/2.1":

Applying: Set SystemTemp env var to config temp on Windows
Using index info to reconstruct a base tree...
M	cmd/containerd/server/server.go
M	cmd/containerd/server/server_test.go
Falling back to patching base and 3-way merge...
Auto-merging cmd/containerd/server/server.go
Auto-merging cmd/containerd/server/server_test.go
CONFLICT (content): Merge conflict in cmd/containerd/server/server_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Set SystemTemp env var to config temp on Windows

Details

In response to this:

/cherry-pick release/2.2
/cherry-pick release/2.1
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: #13667 failed to apply on top of branch "release/2.2":

Applying: Set SystemTemp env var to config temp on Windows
Using index info to reconstruct a base tree...
M	cmd/containerd/server/server.go
M	cmd/containerd/server/server_test.go
Falling back to patching base and 3-way merge...
Auto-merging cmd/containerd/server/server.go
Auto-merging cmd/containerd/server/server_test.go
CONFLICT (content): Merge conflict in cmd/containerd/server/server_test.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Set SystemTemp env var to config temp on Windows

Details

In response to this:

/cherry-pick release/2.2
/cherry-pick release/2.1
/cherry-pick release/2.0
/cherry-pick release/1.7

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@anmaxvl
anmaxvl deleted the windows-systemtemp-from-toml branch June 30, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick/1.7.x Change to be cherry picked to release/1.7 branch cherry-pick/2.0.x Change to be cherry picked to release/2.0 branch cherry-pick/2.1.x Change to be cherry picked to release/2.1 branch cherry-pick/2.2.x Change to be cherry picked to release/2.2 branch cherry-pick/2.3.x Change to be cherry picked to release/2.3 size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants