Fix toml plugin decoding
Do not rely on toml metadata when decoding plugin's configs as it's not possible to merge toml.MetaData structs during import. Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
parent
a1e3779cad
commit
bca0857530
@ -64,8 +64,6 @@ type Config struct {
|
|||||||
Imports []string `toml:"imports"`
|
Imports []string `toml:"imports"`
|
||||||
|
|
||||||
StreamProcessors []StreamProcessor `toml:"stream_processors"`
|
StreamProcessors []StreamProcessor `toml:"stream_processors"`
|
||||||
|
|
||||||
md toml.MetaData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// StreamProcessor provides configuration for diff content processors
|
// StreamProcessor provides configuration for diff content processors
|
||||||
@ -203,7 +201,7 @@ func (c *Config) Decode(p *plugin.Registration) (interface{}, error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return p.Config, nil
|
return p.Config, nil
|
||||||
}
|
}
|
||||||
if err := c.md.PrimitiveDecode(data, p.Config); err != nil {
|
if err := toml.PrimitiveDecode(data, p.Config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return p.Config, nil
|
return p.Config, nil
|
||||||
@ -258,11 +256,10 @@ func LoadConfig(path string, out *Config) error {
|
|||||||
// loadConfigFile decodes a TOML file at the given path
|
// loadConfigFile decodes a TOML file at the given path
|
||||||
func loadConfigFile(path string) (*Config, error) {
|
func loadConfigFile(path string) (*Config, error) {
|
||||||
config := &Config{}
|
config := &Config{}
|
||||||
md, err := toml.DecodeFile(path, &config)
|
_, err := toml.DecodeFile(path, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config.md = md
|
|
||||||
return config, nil
|
return config, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/plugin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMergeConfigs(t *testing.T) {
|
func TestMergeConfigs(t *testing.T) {
|
||||||
@ -161,3 +163,28 @@ imports = ["data1.toml", "data2.toml"]
|
|||||||
filepath.Join(tempDir, "data2.toml"),
|
filepath.Join(tempDir, "data2.toml"),
|
||||||
}, out.Imports)
|
}, out.Imports)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDecodePlugin(t *testing.T) {
|
||||||
|
data := `
|
||||||
|
version = 1
|
||||||
|
[plugins.linux]
|
||||||
|
shim_debug = true
|
||||||
|
`
|
||||||
|
|
||||||
|
tempDir, err := ioutil.TempDir("", "containerd_")
|
||||||
|
assert.NilError(t, err)
|
||||||
|
defer os.RemoveAll(tempDir)
|
||||||
|
|
||||||
|
path := filepath.Join(tempDir, "config.toml")
|
||||||
|
err = ioutil.WriteFile(path, []byte(data), 0600)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
var out Config
|
||||||
|
err = LoadConfig(path, &out)
|
||||||
|
assert.NilError(t, err)
|
||||||
|
|
||||||
|
pluginConfig := map[string]interface{}{}
|
||||||
|
_, err = out.Decode(&plugin.Registration{ID: "linux", Config: &pluginConfig})
|
||||||
|
assert.NilError(t, err)
|
||||||
|
assert.Equal(t, true, pluginConfig["shim_debug"])
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user