@@ -40,6 +40,39 @@ func (c *Config) WriteTo(w io.Writer) (int64, error) {
4040 return 0 , toml .NewEncoder (w ).Encode (c )
4141}
4242
43+ func outputConfig (cfg * srvconfig.Config ) error {
44+ config := & Config {
45+ Config : cfg ,
46+ }
47+
48+ // for the time being, keep the defaultConfig's version set at 1 so that
49+ // when a config without a version is loaded from disk and has no version
50+ // set, we assume it's a v1 config. But when generating new configs via
51+ // this command, generate the v2 config
52+ config .Config .Version = 2
53+ plugins , err := server .LoadPlugins (gocontext .Background (), config .Config )
54+ if err != nil {
55+ return err
56+ }
57+ if len (plugins ) != 0 {
58+ config .Plugins = make (map [string ]interface {})
59+ for _ , p := range plugins {
60+ if p .Config == nil {
61+ continue
62+ }
63+ config .Plugins [p .URI ()] = p .Config
64+ }
65+ }
66+ timeouts := timeout .All ()
67+ config .Timeouts = make (map [string ]string )
68+ for k , v := range timeouts {
69+ config .Timeouts [k ] = v .String ()
70+ }
71+
72+ _ , err = config .WriteTo (os .Stdout )
73+ return err
74+ }
75+
4376var configCommand = cli.Command {
4477 Name : "config" ,
4578 Usage : "information on the containerd config" ,
@@ -48,35 +81,19 @@ var configCommand = cli.Command{
4881 Name : "default" ,
4982 Usage : "see the output of the default config" ,
5083 Action : func (context * cli.Context ) error {
51- config := & Config {
52- Config : defaultConfig (),
53- }
54- // for the time being, keep the defaultConfig's version set at 1 so that
55- // when a config without a version is loaded from disk and has no version
56- // set, we assume it's a v1 config. But when generating new configs via
57- // this command, generate the v2 config
58- config .Config .Version = 2
59- plugins , err := server .LoadPlugins (gocontext .Background (), config .Config )
60- if err != nil {
84+ return outputConfig (defaultConfig ())
85+ },
86+ },
87+ {
88+ Name : "dump" ,
89+ Usage : "see the output of the final main config with imported in subconfig files" ,
90+ Action : func (context * cli.Context ) error {
91+ config := defaultConfig ()
92+ if err := srvconfig .LoadConfig (context .GlobalString ("config" ), config ); err != nil && ! os .IsNotExist (err ) {
6193 return err
6294 }
63- if len (plugins ) != 0 {
64- config .Plugins = make (map [string ]interface {})
65- for _ , p := range plugins {
66- if p .Config == nil {
67- continue
68- }
69- config .Plugins [p .URI ()] = p .Config
70- }
71- }
72- timeouts := timeout .All ()
73- config .Timeouts = make (map [string ]string )
74- for k , v := range timeouts {
75- config .Timeouts [k ] = v .String ()
76- }
7795
78- _ , err = config .WriteTo (os .Stdout )
79- return err
96+ return outputConfig (config )
8097 },
8198 },
8299 },
0 commit comments