Merge pull request #5359 from ktock/v1cfg
Fix backword-compatibility issue of non-versioned config file
This commit is contained in:
		@@ -120,7 +120,11 @@ var configCommand = cli.Command{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func platformAgnosticDefaultConfig() *srvconfig.Config {
 | 
					func platformAgnosticDefaultConfig() *srvconfig.Config {
 | 
				
			||||||
	return &srvconfig.Config{
 | 
						return &srvconfig.Config{
 | 
				
			||||||
		Version: 2,
 | 
							// see: https://github.com/containerd/containerd/blob/5c6ea7fdc1247939edaddb1eba62a94527418687/RELEASES.md#daemon-configuration
 | 
				
			||||||
 | 
							// this version MUST remain set to 1 until either there exists a means to
 | 
				
			||||||
 | 
							// override / configure the default at the containerd cli .. or when
 | 
				
			||||||
 | 
							// version 1 is no longer supported
 | 
				
			||||||
 | 
							Version: 1,
 | 
				
			||||||
		Root:    defaults.DefaultRootDir,
 | 
							Root:    defaults.DefaultRootDir,
 | 
				
			||||||
		State:   defaults.DefaultStateDir,
 | 
							State:   defaults.DefaultStateDir,
 | 
				
			||||||
		GRPC: srvconfig.GRPCConfig{
 | 
							GRPC: srvconfig.GRPCConfig{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,6 +98,7 @@ func (c *Config) ValidateV2() error {
 | 
				
			|||||||
	version := c.GetVersion()
 | 
						version := c.GetVersion()
 | 
				
			||||||
	if version < 2 {
 | 
						if version < 2 {
 | 
				
			||||||
		logrus.Warnf("deprecated version : `%d`, please switch to version `2`", version)
 | 
							logrus.Warnf("deprecated version : `%d`, please switch to version `2`", version)
 | 
				
			||||||
 | 
							return nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, p := range c.DisabledPlugins {
 | 
						for _, p := range c.DisabledPlugins {
 | 
				
			||||||
		if len(strings.Split(p, ".")) < 4 {
 | 
							if len(strings.Split(p, ".")) < 4 {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -207,3 +207,29 @@ version = 2
 | 
				
			|||||||
	assert.NilError(t, err)
 | 
						assert.NilError(t, err)
 | 
				
			||||||
	assert.Equal(t, true, pluginConfig["shim_debug"])
 | 
						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