Skip to content

Commit e461a59

Browse files
committed
fix migrateConfig for io.containerd.cri.v1.images
Signed-off-by: Shuaiyi Zhang <[email protected]>
1 parent 2dd6fa3 commit e461a59

File tree

2 files changed

+97
-27
lines changed

2 files changed

+97
-27
lines changed

plugins/cri/images/plugin.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,33 @@ func configMigration(ctx context.Context, configVersion int, pluginConfigs map[s
176176
return nil
177177
}
178178
func migrateConfig(dst, src map[string]interface{}) {
179+
var pinnedImages map[string]interface{}
180+
if v, ok := dst["pinned_images"]; ok {
181+
pinnedImages = v.(map[string]interface{})
182+
} else {
183+
pinnedImages = map[string]interface{}{}
184+
}
185+
186+
if simage, ok := src["sandbox_image"]; ok {
187+
pinnedImages["sandbox"] = simage
188+
}
189+
if len(pinnedImages) > 0 {
190+
dst["pinned_images"] = pinnedImages
191+
}
192+
193+
for _, key := range []string{
194+
"registry",
195+
"image_decryption",
196+
"max_concurrent_downloads",
197+
"image_pull_progress_timeout",
198+
"image_pull_with_sync_fs",
199+
"stats_collect_period",
200+
} {
201+
if val, ok := src[key]; ok {
202+
dst[key] = val
203+
}
204+
}
205+
179206
containerdConf, ok := src["containerd"]
180207
if !ok {
181208
return
@@ -205,20 +232,6 @@ func migrateConfig(dst, src map[string]interface{}) {
205232
dst["runtime_platform"] = runtimePlatforms
206233
}
207234

208-
var pinnedImages map[string]interface{}
209-
if v, ok := dst["pinned_images"]; ok {
210-
pinnedImages = v.(map[string]interface{})
211-
} else {
212-
pinnedImages = map[string]interface{}{}
213-
}
214-
215-
if simage, ok := src["sandbox_image"]; ok {
216-
pinnedImages["sandbox"] = simage
217-
}
218-
if len(pinnedImages) > 0 {
219-
dst["pinned_images"] = pinnedImages
220-
}
221-
222235
for _, key := range []string{
223236
"snapshotter",
224237
"disable_snapshot_annotations",
@@ -228,17 +241,4 @@ func migrateConfig(dst, src map[string]interface{}) {
228241
dst[key] = val
229242
}
230243
}
231-
232-
for _, key := range []string{
233-
"registry",
234-
"image_decryption",
235-
"max_concurrent_downloads",
236-
"image_pull_progress_timeout",
237-
"image_pull_with_sync_fs",
238-
"stats_collect_period",
239-
} {
240-
if val, ok := src[key]; ok {
241-
dst[key] = val
242-
}
243-
}
244244
}

plugins/cri/images/plugin_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package images
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/containerd/containerd/v2/plugins"
24+
"github.com/stretchr/testify/assert"
25+
"github.com/stretchr/testify/require"
26+
)
27+
28+
func TestSandboxImageConfigMigration(t *testing.T) {
29+
image := "rancher/mirrored-pause:3.9-amd64"
30+
grpcCri := map[string]interface{}{
31+
"sandbox_image": image,
32+
}
33+
pluginConfigs := map[string]interface{}{
34+
string(plugins.GRPCPlugin) + ".cri": grpcCri,
35+
}
36+
configMigration(context.Background(), 2, pluginConfigs)
37+
v, ok := pluginConfigs[string(plugins.CRIServicePlugin)+".images"]
38+
images := v.(map[string]interface{})
39+
require.True(t, ok)
40+
v, ok = images["pinned_images"]
41+
require.True(t, ok)
42+
pinnedImages := v.(map[string]interface{})
43+
v, ok = pinnedImages["sandbox"]
44+
require.True(t, ok)
45+
sandbox := v.(string)
46+
assert.Equal(t, image, sandbox)
47+
}
48+
49+
func TestRegistryConfigMigration(t *testing.T) {
50+
path := "/etc/containerd/certs.d"
51+
grpcCri := map[string]interface{}{
52+
"registry": map[string]interface{}{
53+
"config_path": path,
54+
},
55+
}
56+
pluginConfigs := map[string]interface{}{
57+
string(plugins.GRPCPlugin) + ".cri": grpcCri,
58+
}
59+
configMigration(context.Background(), 2, pluginConfigs)
60+
v, ok := pluginConfigs[string(plugins.CRIServicePlugin)+".images"]
61+
images := v.(map[string]interface{})
62+
require.True(t, ok)
63+
v, ok = images["registry"]
64+
require.True(t, ok)
65+
registry := v.(map[string]interface{})
66+
v, ok = registry["config_path"]
67+
require.True(t, ok)
68+
configPath := v.(string)
69+
assert.Equal(t, path, configPath)
70+
}

0 commit comments

Comments
 (0)