From 3d6fe5ad182673cf7e6002b9d9f5ab2852882b6e Mon Sep 17 00:00:00 2001 From: Lantao Liu Date: Fri, 19 Jan 2018 08:56:34 +0000 Subject: [PATCH] Print default plugin config. Signed-off-by: Lantao Liu --- cmd/containerd/config.go | 33 ++++++++++++++++++++++++++++++++- server/config.go | 13 ------------- server/server.go | 6 ++++-- 3 files changed, 36 insertions(+), 16 deletions(-) diff --git a/cmd/containerd/config.go b/cmd/containerd/config.go index cac902a6a..54a28a722 100644 --- a/cmd/containerd/config.go +++ b/cmd/containerd/config.go @@ -1,11 +1,26 @@ package main import ( + "io" "os" + "github.com/BurntSushi/toml" + "github.com/containerd/containerd/server" "github.com/urfave/cli" ) +// Config is a wrapper of server config for printing out. +type Config struct { + *server.Config + // Plugins overrides `Plugins map[string]toml.Primitive` in server config. + Plugins map[string]interface{} `toml:"plugins"` +} + +// WriteTo marshals the config to the provided writer +func (c *Config) WriteTo(w io.Writer) (int64, error) { + return 0, toml.NewEncoder(w).Encode(c) +} + var configCommand = cli.Command{ Name: "config", Usage: "information on the containerd config", @@ -14,7 +29,23 @@ var configCommand = cli.Command{ Name: "default", Usage: "see the output of the default config", Action: func(context *cli.Context) error { - _, err := defaultConfig().WriteTo(os.Stdout) + config := &Config{ + Config: defaultConfig(), + } + plugins, err := server.LoadPlugins(config.Config) + if err != nil { + return err + } + if len(plugins) != 0 { + config.Plugins = make(map[string]interface{}) + for _, p := range plugins { + if p.Config == nil { + continue + } + config.Plugins[p.ID] = p.Config + } + } + _, err = config.WriteTo(os.Stdout) return err }, }, diff --git a/server/config.go b/server/config.go index 14bd591c0..4cf635ed4 100644 --- a/server/config.go +++ b/server/config.go @@ -1,9 +1,6 @@ package server import ( - "bytes" - "io" - "github.com/BurntSushi/toml" "github.com/containerd/containerd/errdefs" "github.com/pkg/errors" @@ -69,16 +66,6 @@ func (c *Config) Decode(id string, v interface{}) (interface{}, error) { return v, nil } -// WriteTo marshals the config to the provided writer -func (c *Config) WriteTo(w io.Writer) (int64, error) { - buf := bytes.NewBuffer(nil) - e := toml.NewEncoder(buf) - if err := e.Encode(c); err != nil { - return 0, err - } - return io.Copy(w, buf) -} - // LoadConfig loads the containerd server config from the provided path func LoadConfig(path string, v *Config) error { if v == nil { diff --git a/server/server.go b/server/server.go index 1b94a9be3..4da8211b2 100644 --- a/server/server.go +++ b/server/server.go @@ -45,7 +45,7 @@ func New(ctx context.Context, config *Config) (*Server, error) { if err := apply(ctx, config); err != nil { return nil, err } - plugins, err := loadPlugins(config) + plugins, err := LoadPlugins(config) if err != nil { return nil, err } @@ -158,7 +158,9 @@ func (s *Server) Stop() { s.rpc.Stop() } -func loadPlugins(config *Config) ([]*plugin.Registration, error) { +// LoadPlugins loads all plugins into containerd and generates an ordered graph +// of all plugins. +func LoadPlugins(config *Config) ([]*plugin.Registration, error) { // load all plugins into containerd if err := plugin.Load(filepath.Join(config.Root, "plugins")); err != nil { return nil, err