enhance: split config from server package

The github.com/containerd/containerd/services/server has a lot of
dependencies, like content, snapshots services implementation and
docker-metrics.

For the client side, it uses the config struct from server package
to start up the containerd in background. It will import a lot of
useless packages which might be conflict with existing vendor's package.

It makes integration easier with single config package.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
This commit is contained in:
Wei Fu
2018-10-17 11:58:33 +08:00
parent 483724b0df
commit 06616dab00
13 changed files with 46 additions and 31 deletions

View File

@@ -23,12 +23,13 @@ import (
"github.com/BurntSushi/toml"
"github.com/containerd/containerd/services/server"
srvconfig "github.com/containerd/containerd/services/server/config"
"github.com/urfave/cli"
)
// Config is a wrapper of server config for printing out.
type Config struct {
*server.Config
*srvconfig.Config
// Plugins overrides `Plugins map[string]toml.Primitive` in server config.
Plugins map[string]interface{} `toml:"plugins"`
}

View File

@@ -18,14 +18,14 @@ package command
import (
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/services/server"
srvconfig "github.com/containerd/containerd/services/server/config"
)
func defaultConfig() *server.Config {
return &server.Config{
func defaultConfig() *srvconfig.Config {
return &srvconfig.Config{
Root: defaults.DefaultRootDir,
State: defaults.DefaultStateDir,
GRPC: server.GRPCConfig{
GRPC: srvconfig.GRPCConfig{
Address: defaults.DefaultAddress,
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,

View File

@@ -20,17 +20,17 @@ package command
import (
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/services/server"
srvconfig "github.com/containerd/containerd/services/server/config"
)
func defaultConfig() *server.Config {
return &server.Config{
func defaultConfig() *srvconfig.Config {
return &srvconfig.Config{
Root: defaults.DefaultRootDir,
State: defaults.DefaultStateDir,
GRPC: server.GRPCConfig{
GRPC: srvconfig.GRPCConfig{
Address: defaults.DefaultAddress,
},
Debug: server.Debug{
Debug: srvconfig.Debug{
Level: "info",
Address: defaults.DefaultDebugAddress,
},

View File

@@ -18,14 +18,14 @@ package command
import (
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/services/server"
srvconfig "github.com/containerd/containerd/services/server/config"
)
func defaultConfig() *server.Config {
return &server.Config{
func defaultConfig() *srvconfig.Config {
return &srvconfig.Config{
Root: defaults.DefaultRootDir,
State: defaults.DefaultStateDir,
GRPC: server.GRPCConfig{
GRPC: srvconfig.GRPCConfig{
Address: defaults.DefaultAddress,
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,

View File

@@ -29,6 +29,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/services/server"
srvconfig "github.com/containerd/containerd/services/server/config"
"github.com/containerd/containerd/sys"
"github.com/containerd/containerd/version"
"github.com/pkg/errors"
@@ -109,7 +110,7 @@ func App() *cli.App {
// we don't miss any signals during boot
signal.Notify(signals, handledSignals...)
if err := server.LoadConfig(context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
if err := srvconfig.LoadConfig(context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
return err
}
// apply flags to the config
@@ -187,7 +188,7 @@ func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) e
}()
}
func applyFlags(context *cli.Context, config *server.Config) error {
func applyFlags(context *cli.Context, config *srvconfig.Config) error {
// the order for config vs flag values is that flags will always override
// the config values if they are set
if err := setLevel(context, config); err != nil {
@@ -217,7 +218,7 @@ func applyFlags(context *cli.Context, config *server.Config) error {
return nil
}
func setLevel(context *cli.Context, config *server.Config) error {
func setLevel(context *cli.Context, config *srvconfig.Config) error {
l := context.GlobalString("log-level")
if l == "" {
l = config.Debug.Level