From 8fb5f4d5c9b4933be31bf5371d65a95edb037261 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 19 Jun 2018 15:53:40 -0700 Subject: [PATCH] Add configuration option for containerd cri Disable cri plugin by default in containerd and allows an option to enable the plugin. This only has an effect on containerd when supervised by dockerd. When containerd is managed outside of dockerd, the configuration is not effected. Signed-off-by: Derek McGowan --- cmd/dockerd/config.go | 1 + cmd/dockerd/daemon_unix.go | 3 +++ daemon/config/config.go | 5 +++++ libcontainerd/remote_daemon_linux.go | 8 ++++++++ libcontainerd/remote_daemon_options.go | 1 + 5 files changed, 18 insertions(+) diff --git a/cmd/dockerd/config.go b/cmd/dockerd/config.go index abdac9a7fb..adf26f82a6 100644 --- a/cmd/dockerd/config.go +++ b/cmd/dockerd/config.go @@ -29,6 +29,7 @@ func installCommonConfigFlags(conf *config.Config, flags *pflag.FlagSet) { flags.StringVarP(&conf.Root, "graph", "g", defaultDataRoot, "Root of the Docker runtime") flags.StringVar(&conf.ExecRoot, "exec-root", defaultExecRoot, "Root directory for execution state files") flags.StringVar(&conf.ContainerdAddr, "containerd", "", "containerd grpc address") + flags.BoolVar(&conf.CriContainerd, "cri-containerd", false, "start containerd with cri") // "--graph" is "soft-deprecated" in favor of "data-root". This flag was added // before Docker 1.0, so won't be removed, only hidden, to discourage its usage. diff --git a/cmd/dockerd/daemon_unix.go b/cmd/dockerd/daemon_unix.go index a88bcccc0c..51e56673a0 100644 --- a/cmd/dockerd/daemon_unix.go +++ b/cmd/dockerd/daemon_unix.go @@ -56,6 +56,9 @@ func (cli *DaemonCli) getPlatformRemoteOptions() ([]libcontainerd.RemoteOption, } else { opts = append(opts, libcontainerd.WithStartDaemon(true)) } + if !cli.Config.CriContainerd { + opts = append(opts, libcontainerd.WithPlugin("cri", nil)) + } return opts, nil } diff --git a/daemon/config/config.go b/daemon/config/config.go index 6cda223a11..c397f1bc00 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -198,6 +198,11 @@ type CommonConfig struct { // ContainerAddr is the address used to connect to containerd if we're // not starting it ourselves ContainerdAddr string `json:"containerd,omitempty"` + + // CriContainerd determines whether a supervised containerd instance + // should be configured with the CRI plugin enabled. This allows using + // Docker's containerd instance directly with a Kubernetes kubelet. + CriContainerd bool `json:"cri-containerd,omitempty"` } // IsValueSet returns true if a configuration value diff --git a/libcontainerd/remote_daemon_linux.go b/libcontainerd/remote_daemon_linux.go index 5a46afb89d..e3d9640cea 100644 --- a/libcontainerd/remote_daemon_linux.go +++ b/libcontainerd/remote_daemon_linux.go @@ -31,6 +31,14 @@ func (r *remote) setDefaults() { if r.OOMScore == 0 { r.OOMScore = -999 } + + for key, conf := range r.pluginConfs.Plugins { + if conf == nil { + r.DisabledPlugins = append(r.DisabledPlugins, key) + delete(r.pluginConfs.Plugins, key) + } + } + if r.snapshotter == "" { r.snapshotter = "overlay" } diff --git a/libcontainerd/remote_daemon_options.go b/libcontainerd/remote_daemon_options.go index d40e4c0c42..f035756ed5 100644 --- a/libcontainerd/remote_daemon_options.go +++ b/libcontainerd/remote_daemon_options.go @@ -119,6 +119,7 @@ func (s snapshotter) Apply(r Remote) error { // WithPlugin allow configuring a containerd plugin // configuration values passed needs to be quoted if quotes are needed in // the toml format. +// Setting the config to nil will disable a built-in plugin func WithPlugin(name string, conf interface{}) RemoteOption { return pluginConf{ name: name,