config: migrate version before merging
Prior to this commit, `/etc/containerd/config.toml` with no version was parsed as version 3. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
		| @@ -133,7 +133,12 @@ func (c *Config) ValidateVersion() error { | ||||
|  | ||||
| // MigrateConfig will convert the config to the latest version before using | ||||
| func (c *Config) MigrateConfig(ctx context.Context) error { | ||||
| 	for c.Version < version.ConfigVersion { | ||||
| 	return c.MigrateConfigTo(ctx, version.ConfigVersion) | ||||
| } | ||||
|  | ||||
| // MigrateConfigTo will convert the config to the target version before using | ||||
| func (c *Config) MigrateConfigTo(ctx context.Context, targetVersion int) error { | ||||
| 	for c.Version < targetVersion { | ||||
| 		if m := migrations[c.Version]; m != nil { | ||||
| 			if err := m(ctx, c); err != nil { | ||||
| 				return err | ||||
| @@ -297,6 +302,15 @@ func LoadConfig(ctx context.Context, path string, out *Config) error { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		switch config.Version { | ||||
| 		case 0, 1: | ||||
| 			if err := config.MigrateConfigTo(ctx, out.Version); err != nil { | ||||
| 				return err | ||||
| 			} | ||||
| 		default: | ||||
| 			// NOP | ||||
| 		} | ||||
|  | ||||
| 		if err := mergeConfig(out, config); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Akihiro Suda
					Akihiro Suda