diff options
author | Tibor Vass <tiborvass@users.noreply.github.com> | 2021-02-18 12:36:21 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-18 12:36:21 -0800 |
commit | caa48de224fb53c2f5473af2cec56ecc68786986 (patch) | |
tree | f83695b3edef23bb1a81a84baa6be968120a3073 /daemon | |
parent | 6a86c25cf0124909c68de637a39f95fcccd98a48 (diff) | |
parent | df2a9897690cd9c3a71a3c496bc831ee5b2af361 (diff) | |
download | docker-caa48de224fb53c2f5473af2cec56ecc68786986.tar.gz |
Merge pull request #41974 from thaJeztah/20.10_backport_for_linux_1169_plugins_custom_runtime-panic
[20.10 backport] Add shim config for custom runtimes for plugins
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/daemon.go | 8 | ||||
-rw-r--r-- | daemon/runtime_unix.go | 46 | ||||
-rw-r--r-- | daemon/runtime_windows.go | 10 | ||||
-rw-r--r-- | daemon/start_unix.go | 20 |
4 files changed, 58 insertions, 26 deletions
diff --git a/daemon/daemon.go b/daemon/daemon.go index 794ff9712d..3d8cca2880 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -965,8 +965,12 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S } var rt types.Runtime - if runtime := config.GetRuntime(config.GetDefaultRuntimeName()); runtime != nil { - rt = *runtime + if runtime.GOOS != "windows" { + rtPtr, err := d.getRuntime(config.GetDefaultRuntimeName()) + if err != nil { + return nil, err + } + rt = *rtPtr } return pluginexec.New(ctx, getPluginExecRoot(config.Root), pluginCli, config.ContainerdPluginNamespace, m, rt) } diff --git a/daemon/runtime_unix.go b/daemon/runtime_unix.go index 2f2011f2e3..6c57e2455b 100644 --- a/daemon/runtime_unix.go +++ b/daemon/runtime_unix.go @@ -10,10 +10,12 @@ import ( "path/filepath" "strings" + "github.com/containerd/cgroups" "github.com/containerd/containerd/runtime/linux/runctypes" v2runcoptions "github.com/containerd/containerd/runtime/v2/runc/options" "github.com/docker/docker/api/types" "github.com/docker/docker/daemon/config" + "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -96,14 +98,15 @@ func (daemon *Daemon) initRuntimes(runtimes map[string]types.Runtime) (err error }() for name, rt := range runtimes { - if len(rt.Args) == 0 { - continue + if len(rt.Args) > 0 { + script := filepath.Join(tmpDir, name) + content := fmt.Sprintf("#!/bin/sh\n%s %s $@\n", rt.Path, strings.Join(rt.Args, " ")) + if err := ioutil.WriteFile(script, []byte(content), 0700); err != nil { + return err + } } - - script := filepath.Join(tmpDir, name) - content := fmt.Sprintf("#!/bin/sh\n%s %s $@\n", rt.Path, strings.Join(rt.Args, " ")) - if err := ioutil.WriteFile(script, []byte(content), 0700); err != nil { - return err + if rt.Shim == nil { + rt.Shim = defaultV2ShimConfig(daemon.configStore, rt.Path) } } return nil @@ -124,3 +127,32 @@ func (daemon *Daemon) rewriteRuntimePath(name, p string, args []string) (string, return filepath.Join(daemon.configStore.Root, "runtimes", name), nil } + +func (daemon *Daemon) getRuntime(name string) (*types.Runtime, error) { + rt := daemon.configStore.GetRuntime(name) + if rt == nil { + return nil, errdefs.InvalidParameter(errors.Errorf("runtime not found in config: %s", name)) + } + + if len(rt.Args) > 0 { + p, err := daemon.rewriteRuntimePath(name, rt.Path, rt.Args) + if err != nil { + return nil, err + } + rt.Path = p + rt.Args = nil + } + + if rt.Shim == nil { + rt.Shim = defaultV2ShimConfig(daemon.configStore, rt.Path) + } + + if rt.Shim.Binary == linuxShimV1 { + if cgroups.Mode() == cgroups.Unified { + return nil, errdefs.InvalidParameter(errors.Errorf("runtime %q is not supported while cgroups v2 (unified hierarchy) is being used", name)) + } + logrus.Warnf("Configured runtime %q is deprecated and will be removed in the next release", name) + } + + return rt, nil +} diff --git a/daemon/runtime_windows.go b/daemon/runtime_windows.go new file mode 100644 index 0000000000..0787cb1155 --- /dev/null +++ b/daemon/runtime_windows.go @@ -0,0 +1,10 @@ +package daemon + +import ( + "github.com/docker/docker/api/types" + "github.com/pkg/errors" +) + +func (daemon *Daemon) getRuntime(name string) (*types.Runtime, error) { + return nil, errors.New("not implemented") +} diff --git a/daemon/start_unix.go b/daemon/start_unix.go index 7b70451162..2b4dc95106 100644 --- a/daemon/start_unix.go +++ b/daemon/start_unix.go @@ -3,11 +3,7 @@ package daemon // import "github.com/docker/docker/daemon" import ( - "github.com/containerd/cgroups" "github.com/docker/docker/container" - "github.com/docker/docker/errdefs" - "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) // getLibcontainerdCreateOptions callers must hold a lock on the container @@ -18,19 +14,9 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain container.CheckpointTo(daemon.containersReplica) } - rt := daemon.configStore.GetRuntime(container.HostConfig.Runtime) - if rt.Shim == nil { - p, err := daemon.rewriteRuntimePath(container.HostConfig.Runtime, rt.Path, rt.Args) - if err != nil { - return "", nil, translateContainerdStartErr(container.Path, container.SetExitCode, err) - } - rt.Shim = defaultV2ShimConfig(daemon.configStore, p) - } - if rt.Shim.Binary == linuxShimV1 { - if cgroups.Mode() == cgroups.Unified { - return "", nil, errdefs.InvalidParameter(errors.Errorf("runtime %q is not supported while cgroups v2 (unified hierarchy) is being used", container.HostConfig.Runtime)) - } - logrus.Warnf("Configured runtime %q is deprecated and will be removed in the next release", container.HostConfig.Runtime) + rt, err := daemon.getRuntime(container.HostConfig.Runtime) + if err != nil { + return "", nil, translateContainerdStartErr(container.Path, container.SetExitCode, err) } return rt.Shim.Binary, rt.Shim.Opts, nil |