Remove confusing warning in cri runtime config migration

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
This commit is contained in:
Jin Dong
2025-01-09 02:01:35 +00:00
committed by k8s-infra-cherrypick-robot
parent b48e1080c2
commit 468079c5c4
2 changed files with 142 additions and 17 deletions

View File

@@ -51,20 +51,8 @@ func init() {
Requires: []plugin.Type{
plugins.WarningPlugin,
},
ConfigMigration: func(ctx context.Context, configVersion int, pluginConfigs map[string]interface{}) error {
if configVersion >= version.ConfigVersion {
return nil
}
c, ok := pluginConfigs[string(plugins.GRPCPlugin)+".cri"]
if !ok {
return nil
}
conf := c.(map[string]interface{})
migrateConfig(conf)
pluginConfigs[string(plugins.CRIServicePlugin)+".runtime"] = conf
return nil
},
InitFn: initCRIRuntime,
ConfigMigration: configMigration,
InitFn: initCRIRuntime,
})
}
@@ -198,12 +186,79 @@ func setGLogLevel() error {
return nil
}
func migrateConfig(conf map[string]interface{}) {
containerdConf, ok := conf["containerd"]
func configMigration(ctx context.Context, configVersion int, pluginConfigs map[string]interface{}) error {
if configVersion >= version.ConfigVersion {
return nil
}
src, ok := pluginConfigs[string(plugins.GRPCPlugin)+".cri"].(map[string]interface{})
if !ok {
return nil
}
dst, ok := pluginConfigs[string(plugins.CRIServicePlugin)+".runtime"].(map[string]interface{})
if !ok {
dst = make(map[string]interface{})
}
migrateConfig(dst, src)
pluginConfigs[string(plugins.CRIServicePlugin)+".runtime"] = dst
return nil
}
func migrateConfig(dst, src map[string]interface{}) {
for k, v := range src {
switch k {
case "containerd":
// skip (handled separately below)
continue
case
"sandbox_image",
"registry",
"image_decryption",
"max_concurrent_downloads",
"image_pull_progress_timeout",
"image_pull_with_sync_fs",
"stats_collect_period":
// skip (moved to cri image service plugin)
continue
case
"disable_tcp_service",
"stream_server_address",
"stream_server_port",
"stream_idle_timeout",
"enable_tls_streaming",
"x509_key_pair_streaming":
// skip (moved to cri ServerConfig)
continue
default:
if _, ok := dst[k]; !ok {
dst[k] = v
}
}
}
// migrate cri containerd configs
containerdConf, ok := src["containerd"].(map[string]interface{})
if !ok {
return
}
runtimesConf, ok := containerdConf.(map[string]interface{})["runtimes"]
newContainerdConf, ok := dst["containerd"].(map[string]interface{})
if !ok {
newContainerdConf = map[string]interface{}{}
}
for k, v := range containerdConf {
switch k {
case "snapshotter", "disable_snapshot_annotations", "discard_unpacked_layers":
// skip (moved to cri image service plugin)
continue
default:
if _, ok := newContainerdConf[k]; !ok {
newContainerdConf[k] = v
}
}
}
dst["containerd"] = newContainerdConf
// migrate runtimes configs
runtimesConf, ok := newContainerdConf["runtimes"]
if !ok {
return
}
@@ -212,6 +267,7 @@ func migrateConfig(conf map[string]interface{}) {
if sandboxMode, ok := runtimeConf["sandbox_mode"]; ok {
if _, ok := runtimeConf["sandboxer"]; !ok {
runtimeConf["sandboxer"] = sandboxMode
delete(runtimeConf, "sandbox_mode")
}
}
}