diff --git a/plugins/cri/images/plugin.go b/plugins/cri/images/plugin.go index 844fe74398..9fd7051291 100644 --- a/plugins/cri/images/plugin.go +++ b/plugins/cri/images/plugin.go @@ -209,22 +209,22 @@ func migrateConfig(dst, src map[string]interface{}) { } var runtimePlatforms map[string]interface{} - if v, ok := dst["runtime_platform"]; ok { + if v, ok := dst["runtime_platforms"]; ok { runtimePlatforms = v.(map[string]interface{}) } else { runtimePlatforms = map[string]interface{}{} } for runtime, v := range runtimesConf.(map[string]interface{}) { runtimeConf := v.(map[string]interface{}) - if snapshotter, ok := runtimeConf["snapshot"]; ok && snapshotter != "" { + if snapshotter, ok := runtimeConf["snapshotter"]; ok && snapshotter != "" { runtimePlatforms[runtime] = map[string]interface{}{ - "platform": platforms.DefaultStrict(), + "platform": platforms.DefaultString(), "snapshotter": snapshotter, } } } if len(runtimePlatforms) > 0 { - dst["runtime_platform"] = runtimePlatforms + dst["runtime_platforms"] = runtimePlatforms } for _, key := range []string{ diff --git a/plugins/cri/images/plugin_test.go b/plugins/cri/images/plugin_test.go index 7e9f0d7ede..a7c14795f9 100644 --- a/plugins/cri/images/plugin_test.go +++ b/plugins/cri/images/plugin_test.go @@ -20,9 +20,11 @@ import ( "context" "testing" - "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/platforms" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/containerd/containerd/v2/plugins" ) func TestSandboxImageConfigMigration(t *testing.T) { @@ -68,3 +70,42 @@ func TestRegistryConfigMigration(t *testing.T) { configPath := v.(string) assert.Equal(t, path, configPath) } + +func TestRuntimePlatformsConfigMigration(t *testing.T) { + snapshotter := "devmapper" + grpcCri := map[string]any{ + "containerd": map[string]any{ + "runtimes": map[string]any{ + "kata": map[string]any{ + // Old per-runtime snapshotter key is "snapshotter", not "snapshot". + "snapshotter": snapshotter, + }, + // Runtime with no snapshotter should not appear in runtime_platforms. + "runc": map[string]any{}, + }, + }, + } + pluginConfigs := map[string]any{ + string(plugins.GRPCPlugin) + ".cri": grpcCri, + } + configMigration(context.Background(), 2, pluginConfigs) + + v, ok := pluginConfigs[string(plugins.CRIServicePlugin)+".images"] + require.True(t, ok) + images := v.(map[string]any) + + // The destination key is "runtime_platforms" (plural), matching the TOML + // tag on ImageConfig.RuntimePlatforms. + v, ok = images["runtime_platforms"] + require.True(t, ok, "runtime_platforms key must be present after migration") + runtimePlatforms := v.(map[string]any) + + kata, ok := runtimePlatforms["kata"] + require.True(t, ok, "kata runtime must be present in runtime_platforms") + kataConf := kata.(map[string]any) + assert.Equal(t, platforms.DefaultString(), kataConf["platform"]) + assert.Equal(t, snapshotter, kataConf["snapshotter"]) + + _, ok = runtimePlatforms["runc"] + assert.False(t, ok, "runc has no snapshotter and must not appear in runtime_platforms") +}