mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
Fix custom runtimes handling on Windows
This commit partially reverts7ccf750daaand84965c0752Closes #50542 Signed-off-by: Marat Radchenko <marat@slonopotamus.org>
This commit is contained in:
committed by
Sebastiaan van Stijn
parent
4b97831992
commit
0ded8645b6
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
"github.com/moby/moby/v2/daemon/config"
|
"github.com/moby/moby/v2/daemon/config"
|
||||||
"github.com/moby/moby/v2/daemon/internal/libcontainerd"
|
|
||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -101,17 +100,12 @@ func newCgroupParent(*config.Config) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cli *daemonCLI) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
|
func (cli *daemonCLI) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
|
||||||
defer func() {
|
|
||||||
if cli.Config.ContainerdAddr != "" {
|
|
||||||
libcontainerd.ContainerdRuntimeEnabled = true
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if cli.Config.ContainerdAddr != "" {
|
if cli.Config.ContainerdAddr != "" {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if cli.Config.DefaultRuntime != config.WindowsV2RuntimeName {
|
if cli.Config.DefaultRuntime == "" || cli.Config.DefaultRuntime == config.WindowsV1RuntimeName {
|
||||||
|
// Legacy non-containerd runtime is used
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,14 +17,8 @@ const (
|
|||||||
StockRuntimeName = ""
|
StockRuntimeName = ""
|
||||||
|
|
||||||
WindowsV1RuntimeName = "com.docker.hcsshim.v1"
|
WindowsV1RuntimeName = "com.docker.hcsshim.v1"
|
||||||
WindowsV2RuntimeName = "io.containerd.runhcs.v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var builtinRuntimes = map[string]bool{
|
|
||||||
WindowsV1RuntimeName: true,
|
|
||||||
WindowsV2RuntimeName: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
// BridgeConfig is meant to store all the parameters for both the bridge driver and the default bridge network. On
|
// BridgeConfig is meant to store all the parameters for both the bridge driver and the default bridge network. On
|
||||||
// Windows: 1. "bridge" in this context reference the nat driver and the default nat network; 2. the nat driver has no
|
// Windows: 1. "bridge" in this context reference the nat driver and the default nat network; 2. the nat driver has no
|
||||||
// specific parameters, so this struct effectively just stores parameters for the default nat network.
|
// specific parameters, so this struct effectively just stores parameters for the default nat network.
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import (
|
|||||||
"github.com/moby/moby/v2/daemon/internal/idtools"
|
"github.com/moby/moby/v2/daemon/internal/idtools"
|
||||||
"github.com/moby/moby/v2/daemon/internal/image"
|
"github.com/moby/moby/v2/daemon/internal/image"
|
||||||
"github.com/moby/moby/v2/daemon/internal/layer"
|
"github.com/moby/moby/v2/daemon/internal/layer"
|
||||||
|
"github.com/moby/moby/v2/daemon/internal/libcontainerd"
|
||||||
libcontainerdtypes "github.com/moby/moby/v2/daemon/internal/libcontainerd/types"
|
libcontainerdtypes "github.com/moby/moby/v2/daemon/internal/libcontainerd/types"
|
||||||
"github.com/moby/moby/v2/daemon/internal/metrics"
|
"github.com/moby/moby/v2/daemon/internal/metrics"
|
||||||
pluginexec "github.com/moby/moby/v2/daemon/internal/plugin/executor/containerd"
|
pluginexec "github.com/moby/moby/v2/daemon/internal/plugin/executor/containerd"
|
||||||
@@ -1165,7 +1166,8 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
|
|||||||
|
|
||||||
go d.execCommandGC()
|
go d.execCommandGC()
|
||||||
|
|
||||||
if err := d.initLibcontainerd(ctx, &cfgStore.Config); err != nil {
|
d.containerd, err = libcontainerd.NewClient(ctx, d.containerdClient, filepath.Join(config.ExecRoot, "containerd"), config.ContainerdNamespace, d)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import (
|
|||||||
"github.com/moby/moby/v2/daemon/config"
|
"github.com/moby/moby/v2/daemon/config"
|
||||||
"github.com/moby/moby/v2/daemon/container"
|
"github.com/moby/moby/v2/daemon/container"
|
||||||
"github.com/moby/moby/v2/daemon/initlayer"
|
"github.com/moby/moby/v2/daemon/initlayer"
|
||||||
"github.com/moby/moby/v2/daemon/internal/libcontainerd/remote"
|
|
||||||
"github.com/moby/moby/v2/daemon/internal/otelutil"
|
"github.com/moby/moby/v2/daemon/internal/otelutil"
|
||||||
"github.com/moby/moby/v2/daemon/internal/usergroup"
|
"github.com/moby/moby/v2/daemon/internal/usergroup"
|
||||||
"github.com/moby/moby/v2/daemon/libnetwork"
|
"github.com/moby/moby/v2/daemon/libnetwork"
|
||||||
@@ -1646,18 +1645,6 @@ func getSysInfo(cfg *config.Config) *sysinfo.SysInfo {
|
|||||||
return sysinfo.New(siOpts...)
|
return sysinfo.New(siOpts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) initLibcontainerd(ctx context.Context, cfg *config.Config) error {
|
|
||||||
var err error
|
|
||||||
daemon.containerd, err = remote.NewClient(
|
|
||||||
ctx,
|
|
||||||
daemon.containerdClient,
|
|
||||||
filepath.Join(cfg.ExecRoot, "containerd"),
|
|
||||||
cfg.ContainerdNamespace,
|
|
||||||
daemon,
|
|
||||||
)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func recursiveUnmount(target string) error {
|
func recursiveUnmount(target string) error {
|
||||||
return mount.RecursiveUnmount(target)
|
return mount.RecursiveUnmount(target)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,8 +16,6 @@ import (
|
|||||||
networktypes "github.com/moby/moby/api/types/network"
|
networktypes "github.com/moby/moby/api/types/network"
|
||||||
"github.com/moby/moby/v2/daemon/config"
|
"github.com/moby/moby/v2/daemon/config"
|
||||||
"github.com/moby/moby/v2/daemon/container"
|
"github.com/moby/moby/v2/daemon/container"
|
||||||
"github.com/moby/moby/v2/daemon/internal/libcontainerd/local"
|
|
||||||
"github.com/moby/moby/v2/daemon/internal/libcontainerd/remote"
|
|
||||||
"github.com/moby/moby/v2/daemon/internal/system"
|
"github.com/moby/moby/v2/daemon/internal/system"
|
||||||
"github.com/moby/moby/v2/daemon/libnetwork"
|
"github.com/moby/moby/v2/daemon/libnetwork"
|
||||||
nwconfig "github.com/moby/moby/v2/daemon/libnetwork/config"
|
nwconfig "github.com/moby/moby/v2/daemon/libnetwork/config"
|
||||||
@@ -573,36 +571,3 @@ func setupResolvConf(config *config.Config) {}
|
|||||||
func getSysInfo(*config.Config) *sysinfo.SysInfo {
|
func getSysInfo(*config.Config) *sysinfo.SysInfo {
|
||||||
return sysinfo.New()
|
return sysinfo.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) initLibcontainerd(ctx context.Context, cfg *config.Config) error {
|
|
||||||
var err error
|
|
||||||
|
|
||||||
rt := cfg.DefaultRuntime
|
|
||||||
if rt == "" {
|
|
||||||
if cfg.ContainerdAddr == "" {
|
|
||||||
rt = config.WindowsV1RuntimeName
|
|
||||||
} else {
|
|
||||||
rt = config.WindowsV2RuntimeName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch rt {
|
|
||||||
case config.WindowsV1RuntimeName:
|
|
||||||
daemon.containerd, err = local.NewClient(ctx, daemon)
|
|
||||||
case config.WindowsV2RuntimeName:
|
|
||||||
if cfg.ContainerdAddr == "" {
|
|
||||||
return fmt.Errorf("cannot use the specified runtime %q without containerd", rt)
|
|
||||||
}
|
|
||||||
daemon.containerd, err = remote.NewClient(
|
|
||||||
ctx,
|
|
||||||
daemon.containerdClient,
|
|
||||||
filepath.Join(cfg.ExecRoot, "containerd"),
|
|
||||||
cfg.ContainerdNamespace,
|
|
||||||
daemon,
|
|
||||||
)
|
|
||||||
default:
|
|
||||||
return fmt.Errorf("unknown windows runtime %s", rt)
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,14 +9,9 @@ import (
|
|||||||
libcontainerdtypes "github.com/moby/moby/v2/daemon/internal/libcontainerd/types"
|
libcontainerdtypes "github.com/moby/moby/v2/daemon/internal/libcontainerd/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ContainerdRuntimeEnabled determines whether to use containerd for runtime on Windows.
|
|
||||||
//
|
|
||||||
// TODO(thaJeztah): this value is equivalent to checking whether "cli.Config.ContainerdAddr != """ - do we really need it?
|
|
||||||
var ContainerdRuntimeEnabled = false
|
|
||||||
|
|
||||||
// NewClient creates a new libcontainerd client from a containerd client
|
// NewClient creates a new libcontainerd client from a containerd client
|
||||||
func NewClient(ctx context.Context, cli *containerd.Client, stateDir, ns string, b libcontainerdtypes.Backend) (libcontainerdtypes.Client, error) {
|
func NewClient(ctx context.Context, cli *containerd.Client, stateDir, ns string, b libcontainerdtypes.Backend) (libcontainerdtypes.Client, error) {
|
||||||
if !ContainerdRuntimeEnabled {
|
if cli == nil {
|
||||||
return local.NewClient(ctx, b)
|
return local.NewClient(ctx, b)
|
||||||
}
|
}
|
||||||
return remote.NewClient(ctx, cli, stateDir, ns, b)
|
return remote.NewClient(ctx, cli, stateDir, ns, b)
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
package daemon
|
package daemon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
|
"context"
|
||||||
"github.com/moby/moby/v2/daemon/config"
|
|
||||||
|
"github.com/containerd/containerd/v2/defaults"
|
||||||
"github.com/moby/moby/v2/daemon/container"
|
"github.com/moby/moby/v2/daemon/container"
|
||||||
"github.com/moby/moby/v2/daemon/internal/libcontainerd"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (daemon *Daemon) getLibcontainerdCreateOptions(*configStore, *container.Container) (string, any, error) {
|
func (daemon *Daemon) getLibcontainerdCreateOptions(daemonCfg *configStore, container *container.Container) (string, any, error) {
|
||||||
if libcontainerd.ContainerdRuntimeEnabled {
|
if container.HostConfig.Runtime == "" {
|
||||||
opts := &options.Options{}
|
if daemonCfg.DefaultRuntime != "" {
|
||||||
return config.WindowsV2RuntimeName, opts, nil
|
container.HostConfig.Runtime = daemonCfg.DefaultRuntime
|
||||||
|
} else {
|
||||||
|
container.HostConfig.Runtime = defaults.DefaultRuntime
|
||||||
|
}
|
||||||
|
|
||||||
|
container.CheckpointTo(context.WithoutCancel(context.TODO()), daemon.containersReplica)
|
||||||
}
|
}
|
||||||
return "", nil, nil
|
|
||||||
|
return container.HostConfig.Runtime, nil, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user