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

@@ -14,7 +14,7 @@
limitations under the License.
*/
package server
package config
import (
"github.com/BurntSushi/toml"

View File

@@ -40,6 +40,7 @@ import (
"github.com/containerd/containerd/metadata"
"github.com/containerd/containerd/pkg/dialer"
"github.com/containerd/containerd/plugin"
srvconfig "github.com/containerd/containerd/services/server/config"
"github.com/containerd/containerd/snapshots"
ssproxy "github.com/containerd/containerd/snapshots/proxy"
metrics "github.com/docker/go-metrics"
@@ -50,7 +51,7 @@ import (
)
// 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 {
case config.Root == "":
return nil, errors.New("root must be specified")
@@ -149,7 +150,7 @@ func New(ctx context.Context, config *Config) (*Server, error) {
type Server struct {
rpc *grpc.Server
events *exchange.Exchange
config *Config
config *srvconfig.Config
plugins []*plugin.Plugin
}
@@ -211,7 +212,7 @@ func (s *Server) Stop() {
// LoadPlugins loads all plugins into containerd and generates an ordered graph
// 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
if err := plugin.Load(filepath.Join(config.Root, "plugins")); err != nil {
return nil, err

View File

@@ -22,12 +22,13 @@ import (
"github.com/containerd/cgroups"
"github.com/containerd/containerd/log"
srvconfig "github.com/containerd/containerd/services/server/config"
"github.com/containerd/containerd/sys"
specs "github.com/opencontainers/runtime-spec/specs-go"
)
// 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 {
log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore)
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {

View File

@@ -16,8 +16,12 @@
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
}

View File

@@ -20,13 +20,14 @@ import (
"context"
"testing"
srvconfig "github.com/containerd/containerd/services/server/config"
"gotest.tools/assert"
is "gotest.tools/assert/cmp"
)
func TestNewErrorsWithSamePathForRootAndState(t *testing.T) {
path := "/tmp/path/for/testing"
_, err := New(context.Background(), &Config{
_, err := New(context.Background(), &srvconfig.Config{
Root: path,
State: path,
})

View File

@@ -18,8 +18,12 @@
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
}

View File

@@ -20,8 +20,10 @@ package server
import (
"context"
srvconfig "github.com/containerd/containerd/services/server/config"
)
func apply(_ context.Context, _ *Config) error {
func apply(_ context.Context, _ *srvconfig.Config) error {
return nil
}