Merge pull request #688 from vbatts/default-config
containerd: add access to default config
This commit is contained in:
commit
21febdb0de
2 changed files with 45 additions and 5 deletions
|
@ -1,6 +1,11 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/BurntSushi/toml"
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
|
)
|
||||||
|
|
||||||
func defaultConfig() *config {
|
func defaultConfig() *config {
|
||||||
return &config{
|
return &config{
|
||||||
|
@ -58,6 +63,15 @@ func (c *config) decodePlugin(name string, v interface{}) error {
|
||||||
return c.md.PrimitiveDecode(p, v)
|
return c.md.PrimitiveDecode(p, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
type grpcConfig struct {
|
type grpcConfig struct {
|
||||||
Socket string `toml:"socket"`
|
Socket string `toml:"socket"`
|
||||||
Uid int `toml:"uid"`
|
Uid int `toml:"uid"`
|
||||||
|
|
|
@ -3,6 +3,7 @@ package main
|
||||||
import (
|
import (
|
||||||
_ "expvar"
|
_ "expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
|
@ -60,7 +61,7 @@ func main() {
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "config,c",
|
Name: "config,c",
|
||||||
Usage: "path to the configuration file",
|
Usage: "path to the configuration file (Use 'default' to output the default toml)",
|
||||||
Value: "/etc/containerd/config.toml",
|
Value: "/etc/containerd/config.toml",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
|
@ -148,10 +149,35 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func before(context *cli.Context) error {
|
func before(context *cli.Context) error {
|
||||||
if err := loadConfig(context.GlobalString("config")); err != nil &&
|
if context.GlobalString("config") == "default" {
|
||||||
!os.IsNotExist(err) {
|
fh, err := ioutil.TempFile("", "containerd-config.toml.")
|
||||||
|
if err != nil {
|
||||||
return err
|
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"))
|
||||||
|
if err != nil && !os.IsNotExist(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