Migrate current TOML code to github.com/pelletier/go-toml

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
Maksym Pavlenko
2021-03-25 13:13:33 -07:00
parent 499c2f7d4a
commit ddd4298a10
8 changed files with 34 additions and 21 deletions

View File

@@ -20,8 +20,8 @@ import (
"path/filepath"
"strings"
"github.com/BurntSushi/toml"
"github.com/imdario/mergo"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/containerd/containerd/errdefs"
@@ -55,7 +55,7 @@ type Config struct {
// required plugin doesn't exist or fails to be initialized or started.
RequiredPlugins []string `toml:"required_plugins"`
// Plugins provides plugin specific configuration for the initialization of a plugin
Plugins map[string]toml.Primitive `toml:"plugins"`
Plugins map[string]toml.Tree `toml:"plugins"`
// OOMScore adjust the containerd's oom score
OOMScore int `toml:"oom_score"`
// Cgroup specifies cgroup information for the containerd daemon process
@@ -209,7 +209,7 @@ func (c *Config) Decode(p *plugin.Registration) (interface{}, error) {
if !ok {
return p.Config, nil
}
if err := toml.PrimitiveDecode(data, p.Config); err != nil {
if err := data.Unmarshal(p.Config); err != nil {
return nil, err
}
return p.Config, nil
@@ -264,10 +264,16 @@ func LoadConfig(path string, out *Config) error {
// loadConfigFile decodes a TOML file at the given path
func loadConfigFile(path string) (*Config, error) {
config := &Config{}
_, err := toml.DecodeFile(path, &config)
file, err := toml.LoadFile(path)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "failed to load TOML: %s", path)
}
if err := file.Unmarshal(config); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal TOML")
}
return config, nil
}