libcontainerd: split client and supervisor
Adds a supervisor package for starting and monitoring containerd. Separates grpc connection allowing access from daemon. Signed-off-by: Derek McGowan <derek@mcgstyle.net> Upstream-commit: dd2e19ebd58cd8896d79b4b8db61144b93717b33 Component: engine
This commit is contained in:
@@ -36,7 +36,7 @@ import (
|
||||
"github.com/docker/docker/daemon/config"
|
||||
"github.com/docker/docker/daemon/listeners"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/libcontainerd"
|
||||
"github.com/docker/docker/libcontainerd/supervisor"
|
||||
dopts "github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/pkg/authorization"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
@@ -45,7 +45,6 @@ import (
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/plugin"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/go-connections/tlsconfig"
|
||||
swarmapi "github.com/docker/swarmkit/api"
|
||||
@@ -112,6 +111,10 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := system.MkdirAll(cli.Config.ExecRoot, 0700, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if cli.Pidfile != "" {
|
||||
pf, err := pidfile.New(cli.Pidfile)
|
||||
if err != nil {
|
||||
@@ -135,19 +138,27 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
return fmt.Errorf("Failed to load listeners: %v", err)
|
||||
}
|
||||
|
||||
registryService, err := registry.NewService(cli.Config.ServiceOptions)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
if cli.Config.ContainerdAddr == "" && runtime.GOOS != "windows" {
|
||||
opts, err := cli.getContainerdDaemonOpts()
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("Failed to generate containerd options: %v", err)
|
||||
}
|
||||
|
||||
rOpts, err := cli.getRemoteOptions()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to generate containerd options: %v", err)
|
||||
}
|
||||
containerdRemote, err := libcontainerd.New(filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), rOpts...)
|
||||
if err != nil {
|
||||
return err
|
||||
r, err := supervisor.Start(ctx, filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), opts...)
|
||||
if err != nil {
|
||||
cancel()
|
||||
return fmt.Errorf("Failed to start containerd: %v", err)
|
||||
}
|
||||
|
||||
cli.Config.ContainerdAddr = r.Address()
|
||||
|
||||
// Try to wait for containerd to shutdown
|
||||
defer r.WaitTimeout(10 * time.Second)
|
||||
}
|
||||
defer cancel()
|
||||
|
||||
signal.Trap(func() {
|
||||
cli.stop()
|
||||
<-stopc // wait for daemonCli.start() to return
|
||||
@@ -162,7 +173,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
logrus.Fatalf("Error creating middlewares: %v", err)
|
||||
}
|
||||
|
||||
d, err := daemon.NewDaemon(cli.Config, registryService, containerdRemote, pluginStore)
|
||||
d, err := daemon.NewDaemon(ctx, cli.Config, pluginStore)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error starting daemon: %v", err)
|
||||
}
|
||||
@@ -207,10 +218,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
|
||||
initRouter(routerOptions)
|
||||
|
||||
// process cluster change notifications
|
||||
watchCtx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
go d.ProcessClusterNotifications(watchCtx, c.GetWatchStream())
|
||||
go d.ProcessClusterNotifications(ctx, c.GetWatchStream())
|
||||
|
||||
cli.setupConfigReloadTrap()
|
||||
|
||||
@@ -227,8 +235,12 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||
// Wait for serve API to complete
|
||||
errAPI := <-serveAPIWait
|
||||
c.Cleanup()
|
||||
|
||||
shutdownDaemon(d)
|
||||
containerdRemote.Cleanup()
|
||||
|
||||
// Stop notification processing and any background processes
|
||||
cancel()
|
||||
|
||||
if errAPI != nil {
|
||||
return fmt.Errorf("Shutting down due to ServeAPI error: %v", errAPI)
|
||||
}
|
||||
@@ -511,14 +523,22 @@ func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) getRemoteOptions() ([]libcontainerd.RemoteOption, error) {
|
||||
opts := []libcontainerd.RemoteOption{}
|
||||
|
||||
pOpts, err := cli.getPlatformRemoteOptions()
|
||||
func (cli *DaemonCli) getContainerdDaemonOpts() ([]supervisor.DaemonOpt, error) {
|
||||
opts, err := cli.getPlatformContainerdDaemonOpts()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
opts = append(opts, pOpts...)
|
||||
|
||||
if cli.Config.Debug {
|
||||
opts = append(opts, supervisor.WithLogLevel("debug"))
|
||||
} else if cli.Config.LogLevel != "" {
|
||||
opts = append(opts, supervisor.WithLogLevel(cli.Config.LogLevel))
|
||||
}
|
||||
|
||||
if !cli.Config.CriContainerd {
|
||||
opts = append(opts, supervisor.WithPlugin("cri", nil))
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/containerd/containerd/runtime/linux"
|
||||
"github.com/docker/docker/cmd/dockerd/hack"
|
||||
"github.com/docker/docker/daemon"
|
||||
"github.com/docker/docker/libcontainerd"
|
||||
"github.com/docker/docker/libcontainerd/supervisor"
|
||||
"github.com/docker/libnetwork/portallocator"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -36,29 +36,16 @@ func getDaemonConfDir(_ string) string {
|
||||
return "/etc/docker"
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) getPlatformRemoteOptions() ([]libcontainerd.RemoteOption, error) {
|
||||
opts := []libcontainerd.RemoteOption{
|
||||
libcontainerd.WithOOMScore(cli.Config.OOMScoreAdjust),
|
||||
libcontainerd.WithPlugin("linux", &linux.Config{
|
||||
func (cli *DaemonCli) getPlatformContainerdDaemonOpts() ([]supervisor.DaemonOpt, error) {
|
||||
opts := []supervisor.DaemonOpt{
|
||||
supervisor.WithOOMScore(cli.Config.OOMScoreAdjust),
|
||||
supervisor.WithPlugin("linux", &linux.Config{
|
||||
Shim: daemon.DefaultShimBinary,
|
||||
Runtime: daemon.DefaultRuntimeBinary,
|
||||
RuntimeRoot: filepath.Join(cli.Config.Root, "runc"),
|
||||
ShimDebug: cli.Config.Debug,
|
||||
}),
|
||||
}
|
||||
if cli.Config.Debug {
|
||||
opts = append(opts, libcontainerd.WithLogLevel("debug"))
|
||||
} else if cli.Config.LogLevel != "" {
|
||||
opts = append(opts, libcontainerd.WithLogLevel(cli.Config.LogLevel))
|
||||
}
|
||||
if cli.Config.ContainerdAddr != "" {
|
||||
opts = append(opts, libcontainerd.WithRemoteAddr(cli.Config.ContainerdAddr))
|
||||
} else {
|
||||
opts = append(opts, libcontainerd.WithStartDaemon(true))
|
||||
}
|
||||
if !cli.Config.CriContainerd {
|
||||
opts = append(opts, libcontainerd.WithPlugin("cri", nil))
|
||||
}
|
||||
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/libcontainerd"
|
||||
"github.com/docker/docker/libcontainerd/supervisor"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
@@ -48,7 +48,7 @@ func notifyShutdown(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) getPlatformRemoteOptions() ([]libcontainerd.RemoteOption, error) {
|
||||
func (cli *DaemonCli) getPlatformContainerdDaemonOpts() ([]supervisor.DaemonOpt, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user