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())
|
||||
waitForContainerDShutdown, err := cli.initContainerD(ctx)
|
||||
waitForContainerDShutdown, err := cli.initContainerd(ctx)
|
||||
if waitForContainerDShutdown != nil {
|
||||
defer waitForContainerDShutdown(10 * time.Second)
|
||||
}
|
||||
|
|
|
@ -132,32 +132,34 @@ func newCgroupParent(config *config.Config) string {
|
|||
return cgroupParent
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) initContainerD(ctx context.Context) (func(time.Duration) error, error) {
|
||||
var waitForShutdown func(time.Duration) error
|
||||
if cli.Config.ContainerdAddr == "" {
|
||||
systemContainerdAddr, ok, err := systemContainerdRunning(honorXDG)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not determine whether the system containerd is running")
|
||||
}
|
||||
if !ok {
|
||||
logrus.Info("containerd not running, starting managed containerd")
|
||||
opts, err := cli.getContainerdDaemonOpts()
|
||||
if err != nil {
|
||||
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...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to start containerd")
|
||||
}
|
||||
cli.Config.ContainerdAddr = r.Address()
|
||||
|
||||
// Try to wait for containerd to shutdown
|
||||
waitForShutdown = r.WaitTimeout
|
||||
} else {
|
||||
cli.Config.ContainerdAddr = systemContainerdAddr
|
||||
}
|
||||
func (cli *DaemonCli) initContainerd(ctx context.Context) (func(time.Duration) error, error) {
|
||||
if cli.ContainerdAddr != "" {
|
||||
// use system containerd at the given address.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return waitForShutdown, nil
|
||||
systemContainerdAddr, ok, err := systemContainerdRunning(honorXDG)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not determine whether the system containerd is running")
|
||||
}
|
||||
if ok {
|
||||
// detected a system containerd at the given address.
|
||||
cli.ContainerdAddr = systemContainerdAddr
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
logrus.Info("containerd not running, starting managed containerd")
|
||||
opts, err := cli.getContainerdDaemonOpts()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to generate containerd options")
|
||||
}
|
||||
|
||||
r, err := supervisor.Start(ctx, filepath.Join(cli.Root, "containerd"), filepath.Join(cli.ExecRoot, "containerd"), opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to start containerd")
|
||||
}
|
||||
cli.ContainerdAddr = r.Address()
|
||||
|
||||
// Try to wait for containerd to shutdown
|
||||
return r.WaitTimeout, nil
|
||||
}
|
||||
|
|
|
@ -93,8 +93,8 @@ func newCgroupParent(config *config.Config) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) initContainerD(_ context.Context) (func(time.Duration) error, error) {
|
||||
system.InitContainerdRuntime(cli.Config.ContainerdAddr)
|
||||
func (cli *DaemonCli) initContainerd(_ context.Context) (func(time.Duration) error, error) {
|
||||
system.InitContainerdRuntime(cli.ContainerdAddr)
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue