containerd: missing config creates a default

This fixes silently ignore the config file not existing as well.

```bash
sudo ./bin/containerd --config farts
$ sudo ./bin/containerd --config farts
INFO[0000] config "farts" does not exist. Creating it.   module=containerd
INFO[0000] starting containerd boot...                   module=containerd
INFO[0000] starting debug API...                         debug="/run/containerd/debug.sock" module=containerd
INFO[0000] loading monitor plugin "cgroups"...           module=containerd
INFO[0000] loading runtime plugin "linux"...             module=containerd
INFO[0000] loading snapshot plugin "snapshot-overlay"...  module=containerd
INFO[0000] loading grpc service plugin "content-grpc"...  module=containerd
INFO[0000] loading grpc service plugin "metrics-grpc"...  module=containerd
INFO[0000] loading grpc service plugin "runtime-grpc"...  module=containerd
INFO[0000] loading grpc service plugin "healthcheck-grpc"...  module=containerd
INFO[0000] loading grpc service plugin "rootfs-grpc"...  module=containerd
INFO[0000] starting GRPC API server...                   module=containerd
INFO[0000] containerd successfully booted in 0.001465s   module=containerd
^C$ cat farts
state = "/run/containerd"
root = "/var/lib/containerd"
snapshotter = "overlay"
subreaper = false

[grpc]
  socket = "/run/containerd/containerd.sock"
  uid = 0
  gid = 0

[debug]
  socket = "/run/containerd/debug.sock"
  level = "info"

[metrics]
  address = ""
```

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2017-04-04 15:31:35 -04:00
parent 28d012ea00
commit 93417d446c
Signed by: vbatts
GPG key ID: 10937E57733F1362

View file

@ -162,10 +162,22 @@ func before(context *cli.Context) error {
log.G(global).Infof("containerd default config written to %q", fh.Name())
os.Exit(0)
}
if err := loadConfig(context.GlobalString("config")); err != nil &&
!os.IsNotExist(err) {
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 config values if they are set
if err := setLevel(context); err != nil {