Skip to content

Commit bca0857

Browse files
committed
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 <[email protected]>
1 parent a1e3779 commit bca0857

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

services/server/config/config.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ type Config struct {
6464
Imports []string `toml:"imports"`
6565

6666
StreamProcessors []StreamProcessor `toml:"stream_processors"`
67-
68-
md toml.MetaData
6967
}
7068

7169
// StreamProcessor provides configuration for diff content processors
@@ -203,7 +201,7 @@ func (c *Config) Decode(p *plugin.Registration) (interface{}, error) {
203201
if !ok {
204202
return p.Config, nil
205203
}
206-
if err := c.md.PrimitiveDecode(data, p.Config); err != nil {
204+
if err := toml.PrimitiveDecode(data, p.Config); err != nil {
207205
return nil, err
208206
}
209207
return p.Config, nil
@@ -258,11 +256,10 @@ func LoadConfig(path string, out *Config) error {
258256
// loadConfigFile decodes a TOML file at the given path
259257
func loadConfigFile(path string) (*Config, error) {
260258
config := &Config{}
261-
md, err := toml.DecodeFile(path, &config)
259+
_, err := toml.DecodeFile(path, &config)
262260
if err != nil {
263261
return nil, err
264262
}
265-
config.md = md
266263
return config, nil
267264
}
268265

services/server/config/config_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
"testing"
2424

2525
"gotest.tools/assert"
26+
27+
"github.com/containerd/containerd/plugin"
2628
)
2729

2830
func TestMergeConfigs(t *testing.T) {
@@ -161,3 +163,28 @@ imports = ["data1.toml", "data2.toml"]
161163
filepath.Join(tempDir, "data2.toml"),
162164
}, out.Imports)
163165
}
166+
167+
func TestDecodePlugin(t *testing.T) {
168+
data := `
169+
version = 1
170+
[plugins.linux]
171+
shim_debug = true
172+
`
173+
174+
tempDir, err := ioutil.TempDir("", "containerd_")
175+
assert.NilError(t, err)
176+
defer os.RemoveAll(tempDir)
177+
178+
path := filepath.Join(tempDir, "config.toml")
179+
err = ioutil.WriteFile(path, []byte(data), 0600)
180+
assert.NilError(t, err)
181+
182+
var out Config
183+
err = LoadConfig(path, &out)
184+
assert.NilError(t, err)
185+
186+
pluginConfig := map[string]interface{}{}
187+
_, err = out.Decode(&plugin.Registration{ID: "linux", Config: &pluginConfig})
188+
assert.NilError(t, err)
189+
assert.Equal(t, true, pluginConfig["shim_debug"])
190+
}

0 commit comments

Comments
 (0)