Skip to content

Commit ddae20c

Browse files
committed
Update libcontainerd to use containerd 1.0
Signed-off-by: Kenfe-Mickael Laventure <[email protected]>
1 parent 7acea2a commit ddae20c

113 files changed

Lines changed: 4556 additions & 3962 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/server/router/container/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (s *containerRouter) postContainerExecStart(ctx context.Context, w http.Res
126126
return err
127127
}
128128
stdout.Write([]byte(err.Error() + "\r\n"))
129-
logrus.Errorf("Error running exec in container: %v", err)
129+
logrus.Errorf("Error running exec %s in container: %v", execName, err)
130130
}
131131
return nil
132132
}

builder/dockerfile/containerbackend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (c *containerManager) Run(ctx context.Context, cID string, stdout, stderr i
102102

103103
func logCancellationError(cancelErrCh chan error, msg string) {
104104
if cancelErr := <-cancelErrCh; cancelErr != nil {
105-
logrus.Debugf("Build cancelled (%v): ", cancelErr, msg)
105+
logrus.Debugf("Build cancelled (%v): %s", cancelErr, msg)
106106
}
107107
}
108108

cmd/dockerd/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
2727
flags.Var(opts.NewNamedListOptsRef("exec-opts", &conf.ExecOptions, nil), "exec-opt", "Runtime execution options")
2828
flags.StringVarP(&conf.Pidfile, "pidfile", "p", defaultPidFile, "Path to use for daemon PID file")
2929
flags.StringVarP(&conf.Root, "graph", "g", defaultDataRoot, "Root of the Docker runtime")
30+
flags.StringVar(&conf.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
31+
flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address")
3032

3133
// "--graph" is "soft-deprecated" in favor of "data-root". This flag was added
3234
// before Docker 1.0, so won't be removed, only hidden, to discourage its usage.

cmd/dockerd/config_unix.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ func installConfigFlags(conf *config.Config, flags *pflag.FlagSet) {
2929
flags.BoolVar(&conf.BridgeConfig.EnableIPForward, "ip-forward", true, "Enable net.ipv4.ip_forward")
3030
flags.BoolVar(&conf.BridgeConfig.EnableIPMasq, "ip-masq", true, "Enable IP masquerading")
3131
flags.BoolVar(&conf.BridgeConfig.EnableIPv6, "ipv6", false, "Enable IPv6 networking")
32-
flags.StringVar(&conf.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files")
3332
flags.StringVar(&conf.BridgeConfig.FixedCIDRv6, "fixed-cidr-v6", "", "IPv6 subnet for fixed IPs")
3433
flags.BoolVar(&conf.BridgeConfig.EnableUserlandProxy, "userland-proxy", true, "Use userland proxy for loopback traffic")
3534
flags.StringVar(&conf.BridgeConfig.UserlandProxyPath, "userland-proxy-path", "", "Path to the userland proxy binary")
3635
flags.StringVar(&conf.CgroupParent, "cgroup-parent", "", "Set parent cgroup for all containers")
3736
flags.StringVar(&conf.RemappedRoot, "userns-remap", "", "User/Group setting for user namespaces")
38-
flags.StringVar(&conf.ContainerdAddr, "containerd", "", "Path to containerd socket")
3937
flags.BoolVar(&conf.LiveRestoreEnabled, "live-restore", false, "Enable live restore of docker when containers are still running")
4038
flags.IntVar(&conf.OOMScoreAdjust, "oom-score-adjust", -500, "Set the oom_score_adj for the daemon")
4139
flags.BoolVar(&conf.Init, "init", false, "Run an init in the container to forward signals and reap processes")

cmd/dockerd/config_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
var (
1212
defaultPidFile string
1313
defaultDataRoot = filepath.Join(os.Getenv("programdata"), "docker")
14+
defaultExecRoot = filepath.Join(os.Getenv("programdata"), "docker", "exec-root")
1415
)
1516

1617
// installConfigFlags adds flags to the pflag.FlagSet to configure the daemon

cmd/dockerd/daemon.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
204204
return err
205205
}
206206

207-
containerdRemote, err := libcontainerd.New(cli.getLibcontainerdRoot(), cli.getPlatformRemoteOptions()...)
207+
rOpts, err := cli.getRemoteOptions()
208+
if err != nil {
209+
return fmt.Errorf("Failed to generate containerd options: %s", err)
210+
}
211+
containerdRemote, err := libcontainerd.New(filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), rOpts...)
208212
if err != nil {
209213
return err
210214
}
@@ -560,6 +564,17 @@ func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config
560564
return nil
561565
}
562566

567+
func (cli *DaemonCli) getRemoteOptions() ([]libcontainerd.RemoteOption, error) {
568+
opts := []libcontainerd.RemoteOption{}
569+
570+
pOpts, err := cli.getPlatformRemoteOptions()
571+
if err != nil {
572+
return nil, err
573+
}
574+
opts = append(opts, pOpts...)
575+
return opts, nil
576+
}
577+
563578
// validates that the plugins requested with the --authorization-plugin flag are valid AuthzDriver
564579
// plugins present on the host and available to the daemon
565580
func validateAuthzPlugins(requestedPlugins []string, pg plugingetter.PluginGetter) error {

cmd/dockerd/daemon_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ func preNotifySystem() {
1111
// notifySystem sends a message to the host when the server is ready to be used
1212
func notifySystem() {
1313
// Tell the init daemon we are accepting requests
14-
go systemdDaemon.SdNotify("READY=1")
14+
go systemdDaemon.SdNotify(false, "READY=1")
1515
}

cmd/dockerd/daemon_solaris.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,8 @@ func preNotifySystem() {
4141
func notifySystem() {
4242
}
4343

44-
func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption {
45-
opts := []libcontainerd.RemoteOption{}
46-
if cli.Config.ContainerdAddr != "" {
47-
opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr))
48-
} else {
49-
opts = append(opts, libcontainerd.WithStartDaemon(true))
50-
}
51-
return opts
52-
}
53-
54-
// getLibcontainerdRoot gets the root directory for libcontainerd/containerd to
55-
// store their state.
56-
func (cli *DaemonCli) getLibcontainerdRoot() string {
57-
return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
44+
func (cli *DaemonCli) getPlatformRemoteOptions() ([]libcontainerd.RemoteOption, error) {
45+
return nil, nil
5846
}
5947

6048
// getSwarmRunRoot gets the root directory for swarm to store runtime state

cmd/dockerd/daemon_unix.go

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import (
1010
"path/filepath"
1111
"strconv"
1212

13+
"github.com/containerd/containerd/linux"
1314
"github.com/docker/docker/cmd/dockerd/hack"
1415
"github.com/docker/docker/daemon"
1516
"github.com/docker/docker/libcontainerd"
17+
"github.com/docker/docker/pkg/parsers/kernel"
1618
"github.com/docker/libnetwork/portallocator"
1719
"golang.org/x/sys/unix"
1820
)
@@ -35,42 +37,48 @@ func getDaemonConfDir(_ string) string {
3537
return "/etc/docker"
3638
}
3739

38-
// setupConfigReloadTrap configures the USR2 signal to reload the configuration.
39-
func (cli *DaemonCli) setupConfigReloadTrap() {
40-
c := make(chan os.Signal, 1)
41-
signal.Notify(c, unix.SIGHUP)
42-
go func() {
43-
for range c {
44-
cli.reloadConfig()
45-
}
46-
}()
47-
}
40+
func (cli *DaemonCli) getPlatformRemoteOptions() ([]libcontainerd.RemoteOption, error) {
41+
// On older kernel, letting putting the containerd-shim in its own
42+
// namespace will effectively prevent operations such as unlink, rename
43+
// and remove on mountpoints that were present at the time the shim
44+
// namespace was created. This would led to a famous EBUSY will trying to
45+
// remove shm mounts.
46+
var noNewNS bool
47+
if !kernel.CheckKernelVersion(3, 18, 0) {
48+
noNewNS = true
49+
}
4850

49-
func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption {
5051
opts := []libcontainerd.RemoteOption{
51-
libcontainerd.WithDebugLog(cli.Config.Debug),
5252
libcontainerd.WithOOMScore(cli.Config.OOMScoreAdjust),
53+
libcontainerd.WithPlugin("linux", &linux.Config{
54+
Shim: daemon.DefaultShimBinary,
55+
Runtime: daemon.DefaultRuntimeBinary,
56+
RuntimeRoot: filepath.Join(cli.Config.Root, "runc"),
57+
ShimDebug: cli.Config.Debug,
58+
ShimNoMountNS: noNewNS,
59+
}),
60+
}
61+
if cli.Config.Debug {
62+
opts = append(opts, libcontainerd.WithLogLevel("debug"))
5363
}
5464
if cli.Config.ContainerdAddr != "" {
5565
opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr))
5666
} else {
5767
opts = append(opts, libcontainerd.WithStartDaemon(true))
5868
}
59-
if daemon.UsingSystemd(cli.Config) {
60-
args := []string{"--systemd-cgroup=true"}
61-
opts = append(opts, libcontainerd.WithRuntimeArgs(args))
62-
}
63-
if cli.Config.LiveRestoreEnabled {
64-
opts = append(opts, libcontainerd.WithLiveRestore(true))
65-
}
66-
opts = append(opts, libcontainerd.WithRuntimePath(daemon.DefaultRuntimeBinary))
67-
return opts
69+
70+
return opts, nil
6871
}
6972

70-
// getLibcontainerdRoot gets the root directory for libcontainerd/containerd to
71-
// store their state.
72-
func (cli *DaemonCli) getLibcontainerdRoot() string {
73-
return filepath.Join(cli.Config.ExecRoot, "libcontainerd")
73+
// setupConfigReloadTrap configures the USR2 signal to reload the configuration.
74+
func (cli *DaemonCli) setupConfigReloadTrap() {
75+
c := make(chan os.Signal, 1)
76+
signal.Notify(c, unix.SIGHUP)
77+
go func() {
78+
for range c {
79+
cli.reloadConfig()
80+
}
81+
}()
7482
}
7583

7684
// getSwarmRunRoot gets the root directory for swarm to store runtime state

cmd/dockerd/daemon_windows.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func notifyShutdown(err error) {
4848
}
4949
}
5050

51+
func (cli *DaemonCli) getPlatformRemoteOptions() ([]libcontainerd.RemoteOption, error) {
52+
return nil, nil
53+
}
54+
5155
// setupConfigReloadTrap configures a Win32 event to reload the configuration.
5256
func (cli *DaemonCli) setupConfigReloadTrap() {
5357
go func() {
@@ -65,17 +69,6 @@ func (cli *DaemonCli) setupConfigReloadTrap() {
6569
}()
6670
}
6771

68-
func (cli *DaemonCli) getPlatformRemoteOptions() []libcontainerd.RemoteOption {
69-
return nil
70-
}
71-
72-
// getLibcontainerdRoot gets the root directory for libcontainerd to store its
73-
// state. The Windows libcontainerd implementation does not need to write a spec
74-
// or state to disk, so this is a no-op.
75-
func (cli *DaemonCli) getLibcontainerdRoot() string {
76-
return ""
77-
}
78-
7972
// getSwarmRunRoot gets the root directory for swarm to store runtime state
8073
// For example, the control socket
8174
func (cli *DaemonCli) getSwarmRunRoot() string {

0 commit comments

Comments
 (0)