mirror of
https://github.com/containerd/containerd.git
synced 2026-11-06 05:17:02 +00:00
Merge pull request #14425 from mikebrow/release-2-0-fix-runtime-platforms-migration
[release/2.0] fixes for runtime_platforms migration
This commit is contained in:
2 files changed
+46
-5
No files matched your search
@@ -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{
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
Reference in new issue
Block a user