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:
parent
b70cce2085
commit
4b2bca00b8
@ -133,7 +133,12 @@ func (c *Config) ValidateVersion() error {
|
|||||||
|
|
||||||
// MigrateConfig will convert the config to the latest version before using
|
// MigrateConfig will convert the config to the latest version before using
|
||||||
func (c *Config) MigrateConfig(ctx context.Context) error {
|
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 m := migrations[c.Version]; m != nil {
|
||||||
if err := m(ctx, c); err != nil {
|
if err := m(ctx, c); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -297,6 +302,15 @@ func LoadConfig(ctx context.Context, path string, out *Config) error {
|
|||||||
return err
|
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 {
|
if err := mergeConfig(out, config); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user