mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
cmd/dockerd: initContainerd() use early return
- return early if we're expecting a system-containerd - rename `initContainerD` to `initContainerd` ':) - remove .Config to reduce verbosity Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
6560e0b136
commit
226e07144e
3 changed files with 31 additions and 29 deletions
|
@ -167,7 +167,7 @@ func (cli *DaemonCli) start(opts *daemonOptions) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
waitForContainerDShutdown, err := cli.initContainerD(ctx)
|
waitForContainerDShutdown, err := cli.initContainerd(ctx)
|
||||||
if waitForContainerDShutdown != nil {
|
if waitForContainerDShutdown != nil {
|
||||||
defer waitForContainerDShutdown(10 * time.Second)
|
defer waitForContainerDShutdown(10 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,32 +132,34 @@ func newCgroupParent(config *config.Config) string {
|
||||||
return cgroupParent
|
return cgroupParent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DaemonCli) initContainerD(ctx context.Context) (func(time.Duration) error, error) {
|
func (cli *DaemonCli) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
|
||||||
var waitForShutdown func(time.Duration) error
|
if cli.ContainerdAddr != "" {
|
||||||
if cli.Config.ContainerdAddr == "" {
|
// use system containerd at the given address.
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
systemContainerdAddr, ok, err := systemContainerdRunning(honorXDG)
|
systemContainerdAddr, ok, err := systemContainerdRunning(honorXDG)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "could not determine whether the system containerd is running")
|
return nil, errors.Wrap(err, "could not determine whether the system containerd is running")
|
||||||
}
|
}
|
||||||
if !ok {
|
if ok {
|
||||||
|
// detected a system containerd at the given address.
|
||||||
|
cli.ContainerdAddr = systemContainerdAddr
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
logrus.Info("containerd not running, starting managed containerd")
|
logrus.Info("containerd not running, starting managed containerd")
|
||||||
opts, err := cli.getContainerdDaemonOpts()
|
opts, err := cli.getContainerdDaemonOpts()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to generate containerd options")
|
return nil, errors.Wrap(err, "failed to generate containerd options")
|
||||||
}
|
}
|
||||||
|
|
||||||
r, err := supervisor.Start(ctx, filepath.Join(cli.Config.Root, "containerd"), filepath.Join(cli.Config.ExecRoot, "containerd"), opts...)
|
r, err := supervisor.Start(ctx, filepath.Join(cli.Root, "containerd"), filepath.Join(cli.ExecRoot, "containerd"), opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to start containerd")
|
return nil, errors.Wrap(err, "failed to start containerd")
|
||||||
}
|
}
|
||||||
cli.Config.ContainerdAddr = r.Address()
|
cli.ContainerdAddr = r.Address()
|
||||||
|
|
||||||
// Try to wait for containerd to shutdown
|
// Try to wait for containerd to shutdown
|
||||||
waitForShutdown = r.WaitTimeout
|
return r.WaitTimeout, nil
|
||||||
} else {
|
|
||||||
cli.Config.ContainerdAddr = systemContainerdAddr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return waitForShutdown, nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,8 +93,8 @@ func newCgroupParent(config *config.Config) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cli *DaemonCli) initContainerD(_ context.Context) (func(time.Duration) error, error) {
|
func (cli *DaemonCli) initContainerd(_ context.Context) (func(time.Duration) error, error) {
|
||||||
system.InitContainerdRuntime(cli.Config.ContainerdAddr)
|
system.InitContainerdRuntime(cli.ContainerdAddr)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue