Merge pull request #711 from vbatts/config-subcommand
containerd: make a config subcommand
This commit is contained in:
commit
a17c10540d
2 changed files with 20 additions and 26 deletions
|
@ -3,10 +3,27 @@ package main
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var configCommand = cli.Command{
|
||||||
|
Name: "config",
|
||||||
|
Usage: "information on the containerd config",
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
{
|
||||||
|
Name: "default",
|
||||||
|
Usage: "see the output of the default config",
|
||||||
|
Action: func(context *cli.Context) error {
|
||||||
|
_, err := conf.WriteTo(os.Stdout)
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
// loadConfig loads the config from the provided path
|
// loadConfig loads the config from the provided path
|
||||||
func loadConfig(path string) error {
|
func loadConfig(path string) error {
|
||||||
md, err := toml.DecodeFile(path, conf)
|
md, err := toml.DecodeFile(path, conf)
|
||||||
|
|
|
@ -3,7 +3,6 @@ package main
|
||||||
import (
|
import (
|
||||||
_ "expvar"
|
_ "expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
|
@ -82,6 +81,9 @@ func main() {
|
||||||
Usage: "containerd root directory",
|
Usage: "containerd root directory",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
app.Commands = []cli.Command{
|
||||||
|
configCommand,
|
||||||
|
}
|
||||||
app.Before = before
|
app.Before = before
|
||||||
app.Action = func(context *cli.Context) error {
|
app.Action = func(context *cli.Context) error {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
@ -152,35 +154,10 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func before(context *cli.Context) error {
|
func before(context *cli.Context) error {
|
||||||
if context.GlobalString("config") == "default" {
|
|
||||||
fh, err := ioutil.TempFile("", "containerd-config.toml.")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if _, err := conf.WriteTo(fh); err != nil {
|
|
||||||
fh.Close()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fh.Close()
|
|
||||||
log.G(global).Infof("containerd default config written to %q", fh.Name())
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
err := loadConfig(context.GlobalString("config"))
|
err := loadConfig(context.GlobalString("config"))
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
return err
|
return err
|
||||||
} else if err != nil && os.IsNotExist(err) {
|
|
||||||
log.G(global).Infof("config %q does not exist. Creating it.", context.GlobalString("config"))
|
|
||||||
fh, err := os.Create(context.GlobalString("config"))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if _, err := conf.WriteTo(fh); err != nil {
|
|
||||||
fh.Close()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fh.Close()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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); err != nil {
|
if err := setLevel(context); err != nil {
|
||||||
|
|
Loading…
Reference in a new issue