Skip to content

Commit fdb76f5

Browse files
committed
Fix backword-compatibility issue of non-versioned config file
According to the doc about `config.toml` of containerd: ``` If no version number is specified inside the config file then it is assumed to be a version 1 config and parsed as such. ``` However, it's not true recently. This will break the backward-compatibility in some environment. This commit fixes this issue. Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
1 parent 5c6ea7f commit fdb76f5

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

cmd/containerd/command/config.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ var configCommand = cli.Command{
120120

121121
func platformAgnosticDefaultConfig() *srvconfig.Config {
122122
return &srvconfig.Config{
123-
Version: 2,
123+
// see: https://github.com/containerd/containerd/blob/5c6ea7fdc1247939edaddb1eba62a94527418687/RELEASES.md#daemon-configuration
124+
// this version MUST remain set to 1 until either there exists a means to
125+
// override / configure the default at the containerd cli .. or when
126+
// version 1 is no longer supported
127+
Version: 1,
124128
Root: defaults.DefaultRootDir,
125129
State: defaults.DefaultStateDir,
126130
GRPC: srvconfig.GRPCConfig{

services/server/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func (c *Config) ValidateV2() error {
9898
version := c.GetVersion()
9999
if version < 2 {
100100
logrus.Warnf("deprecated version : `%d`, please switch to version `2`", version)
101+
return nil
101102
}
102103
for _, p := range c.DisabledPlugins {
103104
if len(strings.Split(p, ".")) < 4 {

services/server/config/config_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,29 @@ version = 2
207207
assert.NilError(t, err)
208208
assert.Equal(t, true, pluginConfig["shim_debug"])
209209
}
210+
211+
// TestDecodePluginInV1Config tests decoding non-versioned
212+
// config (should be parsed as V1 config).
213+
func TestDecodePluginInV1Config(t *testing.T) {
214+
data := `
215+
[plugins.linux]
216+
shim_debug = true
217+
`
218+
219+
tempDir, err := ioutil.TempDir("", "containerd_")
220+
assert.NilError(t, err)
221+
defer os.RemoveAll(tempDir)
222+
223+
path := filepath.Join(tempDir, "config.toml")
224+
err = ioutil.WriteFile(path, []byte(data), 0600)
225+
assert.NilError(t, err)
226+
227+
var out Config
228+
err = LoadConfig(path, &out)
229+
assert.NilError(t, err)
230+
231+
pluginConfig := map[string]interface{}{}
232+
_, err = out.Decode(&plugin.Registration{ID: "linux", Config: &pluginConfig})
233+
assert.NilError(t, err)
234+
assert.Equal(t, true, pluginConfig["shim_debug"])
235+
}

0 commit comments

Comments
 (0)