Fix custom runtimes handling on Windows#50546
Conversation
3c2044e to
dd05885
Compare
|
CI says:
But I do not have permissions to change PR labels =/ |
dd05885 to
98e4f94
Compare
|
Looks like something is perhaps validating too eagerly if it's not required: |
|
Whoops. I'll put this back then. |
9043980 to
04d9ec0
Compare
|
Rebased to resolve merge conflicts. |
vvoland
left a comment
There was a problem hiding this comment.
Thanks, looks good to me!
Perhaps for a follow up - could we have an integration test that tests this with some non-standard runtime?
|
I'm not sure I can quickly find alternative runtime that can be easily distinguised by its external behavior from hcsshim... To be honest, I discovered #50542 when was trying to use my custom build of hcsshim to debug some issues. The best candidate would be runwasi, because we can easily test "either we can run a WASM image or not", but it currently does not compile on Windows. |
04d9ec0 to
8027f3b
Compare
|
I did a quick rebase, because there were merged conflicts in the imports due to the modules being merged. |
b162036 to
37df135
Compare
|
Thanks! I'm happy to see some of the kludge-y code disappear. I did make a quick pass at trying to follow the logic we have in place now, but could possibly use some more eyes. I wrote down my first pass below; I did a compare between the Unix and Windows implementations of this code, and there's one thing I noticed; on Linux, we do some extra steps;
Diff below; Detailsdiff --git a/./daemon/start_unix.go b/./daemon/start_windows.go
index 8e3c4ab07c..bc4f04c5d6 100644
--- a/./daemon/start_unix.go
+++ b/./daemon/start_windows.go
@@ -1,25 +1,23 @@
-//go:build !windows
-
package daemon
import (
- "context"
-
+ "github.com/containerd/containerd/v2/defaults"
"github.com/moby/moby/v2/daemon/container"
)
-// getLibcontainerdCreateOptions callers must hold a lock on the container
func (daemon *Daemon) getLibcontainerdCreateOptions(daemonCfg *configStore, container *container.Container) (string, interface{}, error) {
- // Ensure a runtime has been assigned to this container
- if container.HostConfig.Runtime == "" {
- container.HostConfig.Runtime = daemonCfg.Runtimes.Default
- container.CheckpointTo(context.WithoutCancel(context.TODO()), daemon.containersReplica)
+ if container.HostConfig.Runtime != "" {
+ return container.HostConfig.Runtime, nil, nil
+ }
+
+ if daemonCfg.DefaultRuntime != "" {
+ return daemonCfg.DefaultRuntime, nil, nil
}
- shim, opts, err := daemonCfg.Runtimes.Get(container.HostConfig.Runtime)
- if err != nil {
- return "", nil, setExitCodeFromError(container.SetExitCode, err)
+ if daemon.containerdClient == nil {
+ // We're running in legacy non-containerd mode, runtime doesn't affect anything
+ return "", nil, nil
}
- return shim, opts, nil
+ return defaults.DefaultRuntime, nil, nil
}👇 👉 Not all related to this PR, also looking at the Unix implementation / logic 👈 While looking at the Unix implementation👇
Not sure what's correct here, but wondering if the Windows and Unix implementations should be aligned here (and persist whatever was resolved to Disk?) For the validation, there's some interesting observations as well; I wondered what the Line 12 in 2c1d904 It looks like that's ❓ Was it left out for Windows with the assumption "Windows doesn't use containerd" (which now no longer holds true), or was this because it's legacy? Lines 32 to 48 in 2c1d904 |
I am returning
I saw that code but was not sure whether it is needed. Will add saving. |
|
Thanks! Definitely take my comments with a pinch of salt; parts of this code became quite convoluted over time to facilitate all the different situations (and/or stubbing things on Windows). I started to unravel some bits a while back as part of #49551 and #50398, but there were still (too) many abstractions in some spots making it hard to follow the logic. 😅 |
37df135 to
e1612be
Compare
Not sure about this. One might want to create a container and never start it (but instead just |
|
Forgot to say: updated PR to save container after assigning a runtime shim to it. Not sure why saving neither uses context from outer code nor why saving error is ignored, just did it the same way as in unix version. |
|
Thanks!
I would have to look; my assumptions;
I asked a colleague to have a closer look at this PR as well 🤗 |
This commit partially reverts 7ccf750 and 84965c0 Closes moby#50542 Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
e1612be to
0ded864
Compare
|
It seems, this change broke one usecase: when dockerd is started with |
- What I did
This commit gives user full control over container runtimes:
io.containerd.runhcs.v1com.docker.hcsshim.v1This commit partially reverts 7ccf750 and 84965c0
Closes #50542
- How to verify it
Scenario 1:
docker run --rm -it --runtime <...> <image>should use custom runtime to run container on Windows.Scenario 2: change default runtime to any other value than
com.docker.hcsshim.v1on Windows, and ensure that dockerd properly starts with containerd and runs containers using specified runtime.Scenario 3: by default, dockerd on Windows doesn't require containerd and uses legacy mode where it directly calls hcsshim.
- Human readable description for the release notes
- A picture of a cute animal (not mandatory but encouraged)