Set SystemTemp env var to config temp on Windows#13667
Conversation
There was a problem hiding this comment.
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
SystemTemptoconfig.TempDiralongside the existingTEMP/TMPoverrides. - 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.
955acaf to
7ea5731
Compare
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]>
7ea5731 to
faff4d6
Compare
|
@thaJeztah maybe? |
|
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 |
|
/cherry-pick release/2.3 |
|
(let's see if it applies cleanly |
|
@thaJeztah: new pull request created: #13694 DetailsIn response to this:
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. |
Yes, this should probably be backported. |
|
/cherry-pick release/2.2 |
|
@samuelkarp: #13667 failed to apply on top of branch "release/1.7": DetailsIn response to this:
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: #13667 failed to apply on top of branch "release/2.0": DetailsIn response to this:
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: #13667 failed to apply on top of branch "release/2.1": DetailsIn response to this:
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: #13667 failed to apply on top of branch "release/2.2": DetailsIn response to this:
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. |
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