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>
This commit is contained in:
		| @@ -207,3 +207,29 @@ version = 2 | ||||
| 	assert.NilError(t, err) | ||||
| 	assert.Equal(t, true, pluginConfig["shim_debug"]) | ||||
| } | ||||
|  | ||||
| // TestDecodePluginInV1Config tests decoding non-versioned | ||||
| // config (should be parsed as V1 config). | ||||
| func TestDecodePluginInV1Config(t *testing.T) { | ||||
| 	data := ` | ||||
| [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"]) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ktock
					ktock