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:
parent
483724b0df
commit
06616dab00
@ -23,12 +23,13 @@ import (
|
|||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/containerd/containerd/services/server"
|
"github.com/containerd/containerd/services/server"
|
||||||
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is a wrapper of server config for printing out.
|
// Config is a wrapper of server config for printing out.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
*server.Config
|
*srvconfig.Config
|
||||||
// Plugins overrides `Plugins map[string]toml.Primitive` in server config.
|
// Plugins overrides `Plugins map[string]toml.Primitive` in server config.
|
||||||
Plugins map[string]interface{} `toml:"plugins"`
|
Plugins map[string]interface{} `toml:"plugins"`
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,14 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd/defaults"
|
"github.com/containerd/containerd/defaults"
|
||||||
"github.com/containerd/containerd/services/server"
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultConfig() *server.Config {
|
func defaultConfig() *srvconfig.Config {
|
||||||
return &server.Config{
|
return &srvconfig.Config{
|
||||||
Root: defaults.DefaultRootDir,
|
Root: defaults.DefaultRootDir,
|
||||||
State: defaults.DefaultStateDir,
|
State: defaults.DefaultStateDir,
|
||||||
GRPC: server.GRPCConfig{
|
GRPC: srvconfig.GRPCConfig{
|
||||||
Address: defaults.DefaultAddress,
|
Address: defaults.DefaultAddress,
|
||||||
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
||||||
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
||||||
|
@ -20,17 +20,17 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd/defaults"
|
"github.com/containerd/containerd/defaults"
|
||||||
"github.com/containerd/containerd/services/server"
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultConfig() *server.Config {
|
func defaultConfig() *srvconfig.Config {
|
||||||
return &server.Config{
|
return &srvconfig.Config{
|
||||||
Root: defaults.DefaultRootDir,
|
Root: defaults.DefaultRootDir,
|
||||||
State: defaults.DefaultStateDir,
|
State: defaults.DefaultStateDir,
|
||||||
GRPC: server.GRPCConfig{
|
GRPC: srvconfig.GRPCConfig{
|
||||||
Address: defaults.DefaultAddress,
|
Address: defaults.DefaultAddress,
|
||||||
},
|
},
|
||||||
Debug: server.Debug{
|
Debug: srvconfig.Debug{
|
||||||
Level: "info",
|
Level: "info",
|
||||||
Address: defaults.DefaultDebugAddress,
|
Address: defaults.DefaultDebugAddress,
|
||||||
},
|
},
|
||||||
|
@ -18,14 +18,14 @@ package command
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/containerd/containerd/defaults"
|
"github.com/containerd/containerd/defaults"
|
||||||
"github.com/containerd/containerd/services/server"
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultConfig() *server.Config {
|
func defaultConfig() *srvconfig.Config {
|
||||||
return &server.Config{
|
return &srvconfig.Config{
|
||||||
Root: defaults.DefaultRootDir,
|
Root: defaults.DefaultRootDir,
|
||||||
State: defaults.DefaultStateDir,
|
State: defaults.DefaultStateDir,
|
||||||
GRPC: server.GRPCConfig{
|
GRPC: srvconfig.GRPCConfig{
|
||||||
Address: defaults.DefaultAddress,
|
Address: defaults.DefaultAddress,
|
||||||
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
MaxRecvMsgSize: defaults.DefaultMaxRecvMsgSize,
|
||||||
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
MaxSendMsgSize: defaults.DefaultMaxSendMsgSize,
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/services/server"
|
"github.com/containerd/containerd/services/server"
|
||||||
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
"github.com/containerd/containerd/version"
|
"github.com/containerd/containerd/version"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -109,7 +110,7 @@ func App() *cli.App {
|
|||||||
// we don't miss any signals during boot
|
// we don't miss any signals during boot
|
||||||
signal.Notify(signals, handledSignals...)
|
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
|
return err
|
||||||
}
|
}
|
||||||
// apply flags to the config
|
// 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 order for config vs flag values is that flags will always override
|
||||||
// the config values if they are set
|
// the config values if they are set
|
||||||
if err := setLevel(context, config); err != nil {
|
if err := setLevel(context, config); err != nil {
|
||||||
@ -217,7 +218,7 @@ func applyFlags(context *cli.Context, config *server.Config) error {
|
|||||||
return nil
|
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")
|
l := context.GlobalString("log-level")
|
||||||
if l == "" {
|
if l == "" {
|
||||||
l = config.Debug.Level
|
l = config.Debug.Level
|
||||||
|
@ -30,7 +30,7 @@ import (
|
|||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/containerd/pkg/testutil"
|
"github.com/containerd/containerd/pkg/testutil"
|
||||||
"github.com/containerd/containerd/runtime/v2/runc/options"
|
"github.com/containerd/containerd/runtime/v2/runc/options"
|
||||||
"github.com/containerd/containerd/services/server"
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// the following nolint is for shutting up gometalinter on non-linux.
|
// the following nolint is for shutting up gometalinter on non-linux.
|
||||||
@ -42,7 +42,7 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
|
|||||||
testutil.RequiresRoot(t)
|
testutil.RequiresRoot(t)
|
||||||
var (
|
var (
|
||||||
ctrd = daemon{}
|
ctrd = daemon{}
|
||||||
configTOMLDecoded server.Config
|
configTOMLDecoded srvconfig.Config
|
||||||
buf = bytes.NewBuffer(nil)
|
buf = bytes.NewBuffer(nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func newDaemonWithConfig(t *testing.T, configTOML string) (*Client, *daemon, fun
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = server.LoadConfig(configTOMLFile, &configTOMLDecoded); err != nil {
|
if err = srvconfig.LoadConfig(configTOMLFile, &configTOMLDecoded); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package server
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
@ -40,6 +40,7 @@ import (
|
|||||||
"github.com/containerd/containerd/metadata"
|
"github.com/containerd/containerd/metadata"
|
||||||
"github.com/containerd/containerd/pkg/dialer"
|
"github.com/containerd/containerd/pkg/dialer"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
"github.com/containerd/containerd/snapshots"
|
"github.com/containerd/containerd/snapshots"
|
||||||
ssproxy "github.com/containerd/containerd/snapshots/proxy"
|
ssproxy "github.com/containerd/containerd/snapshots/proxy"
|
||||||
metrics "github.com/docker/go-metrics"
|
metrics "github.com/docker/go-metrics"
|
||||||
@ -50,7 +51,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// New creates and initializes a new containerd server
|
// New creates and initializes a new containerd server
|
||||||
func New(ctx context.Context, config *Config) (*Server, error) {
|
func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
||||||
switch {
|
switch {
|
||||||
case config.Root == "":
|
case config.Root == "":
|
||||||
return nil, errors.New("root must be specified")
|
return nil, errors.New("root must be specified")
|
||||||
@ -149,7 +150,7 @@ func New(ctx context.Context, config *Config) (*Server, error) {
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
rpc *grpc.Server
|
rpc *grpc.Server
|
||||||
events *exchange.Exchange
|
events *exchange.Exchange
|
||||||
config *Config
|
config *srvconfig.Config
|
||||||
plugins []*plugin.Plugin
|
plugins []*plugin.Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,7 +212,7 @@ func (s *Server) Stop() {
|
|||||||
|
|
||||||
// LoadPlugins loads all plugins into containerd and generates an ordered graph
|
// LoadPlugins loads all plugins into containerd and generates an ordered graph
|
||||||
// of all plugins.
|
// of all plugins.
|
||||||
func LoadPlugins(ctx context.Context, config *Config) ([]*plugin.Registration, error) {
|
func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Registration, error) {
|
||||||
// load all plugins into containerd
|
// load all plugins into containerd
|
||||||
if err := plugin.Load(filepath.Join(config.Root, "plugins")); err != nil {
|
if err := plugin.Load(filepath.Join(config.Root, "plugins")); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -22,12 +22,13 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/cgroups"
|
"github.com/containerd/cgroups"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
// apply sets config settings on the server process
|
// apply sets config settings on the server process
|
||||||
func apply(ctx context.Context, config *Config) error {
|
func apply(ctx context.Context, config *srvconfig.Config) error {
|
||||||
if config.OOMScore != 0 {
|
if config.OOMScore != 0 {
|
||||||
log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore)
|
log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore)
|
||||||
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
|
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
|
||||||
|
@ -16,8 +16,12 @@
|
|||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import "context"
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
func apply(_ context.Context, _ *Config) error {
|
srvconfig "github.com/containerd/containerd/server/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func apply(_ context.Context, _ *srvconfig.Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -20,13 +20,14 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
is "gotest.tools/assert/cmp"
|
is "gotest.tools/assert/cmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewErrorsWithSamePathForRootAndState(t *testing.T) {
|
func TestNewErrorsWithSamePathForRootAndState(t *testing.T) {
|
||||||
path := "/tmp/path/for/testing"
|
path := "/tmp/path/for/testing"
|
||||||
_, err := New(context.Background(), &Config{
|
_, err := New(context.Background(), &srvconfig.Config{
|
||||||
Root: path,
|
Root: path,
|
||||||
State: path,
|
State: path,
|
||||||
})
|
})
|
||||||
|
@ -18,8 +18,12 @@
|
|||||||
|
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import "context"
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
func apply(_ context.Context, _ *Config) error {
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
func apply(_ context.Context, _ *srvconfig.Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,10 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func apply(_ context.Context, _ *Config) error {
|
func apply(_ context.Context, _ *srvconfig.Config) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user