Skip to content

Commit be5eda0

Browse files
djdongjink8s-infra-cherrypick-robot
authored andcommitted
complete cri grpc config migration
Signed-off-by: Jin Dong <[email protected]>
1 parent d93ae62 commit be5eda0

File tree

2 files changed

+99
-23
lines changed

2 files changed

+99
-23
lines changed

plugins/cri/cri.go

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,9 @@ func init() {
5858
plugins.TransferPlugin,
5959
plugins.WarningPlugin,
6060
},
61-
Config: &defaultConfig,
62-
ConfigMigration: func(ctx context.Context, configVersion int, pluginConfigs map[string]interface{}) error {
63-
if configVersion >= version.ConfigVersion {
64-
return nil
65-
}
66-
const pluginName = string(plugins.GRPCPlugin) + ".cri"
67-
original, ok := pluginConfigs[pluginName]
68-
if !ok {
69-
return nil
70-
}
71-
src := original.(map[string]interface{})
72-
73-
// Currently only a single key migrated
74-
if val, ok := src["disable_tcp_service"]; ok {
75-
pluginConfigs[pluginName] = map[string]interface{}{
76-
"disable_tcp_service": val,
77-
}
78-
} else {
79-
delete(pluginConfigs, pluginName)
80-
}
81-
return nil
82-
},
83-
InitFn: initCRIService,
61+
Config: &defaultConfig,
62+
ConfigMigration: configMigration,
63+
InitFn: initCRIService,
8464
})
8565
}
8666

@@ -255,3 +235,31 @@ func getSandboxControllers(ic *plugin.InitContext) (map[string]sandbox.Controlle
255235
}
256236
return sc, nil
257237
}
238+
239+
func configMigration(ctx context.Context, configVersion int, pluginConfigs map[string]interface{}) error {
240+
if configVersion >= version.ConfigVersion {
241+
return nil
242+
}
243+
const pluginName = string(plugins.GRPCPlugin) + ".cri"
244+
src, ok := pluginConfigs[pluginName].(map[string]interface{})
245+
if !ok {
246+
return nil
247+
}
248+
249+
dst := map[string]interface{}{}
250+
for _, k := range []string{
251+
"disable_tcp_service",
252+
"stream_server_address",
253+
"stream_server_port",
254+
"stream_idle_timeout",
255+
"enable_tls_streaming",
256+
"x509_key_pair_streaming",
257+
} {
258+
if val, ok := src[k]; ok {
259+
dst[k] = val
260+
}
261+
}
262+
263+
pluginConfigs[pluginName] = dst
264+
return nil
265+
}

plugins/cri/cri_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 cri
18+
19+
import (
20+
"context"
21+
"testing"
22+
23+
"github.com/containerd/containerd/v2/plugins"
24+
"github.com/stretchr/testify/assert"
25+
)
26+
27+
func TestCRIGRPCServerConfigMigration(t *testing.T) {
28+
pluginName := string(plugins.GRPCPlugin) + ".cri"
29+
30+
src := map[string]interface{}{
31+
// these should be removed in the new cri grpc config
32+
"registry": map[string]interface{}{
33+
"config_path": "/etc/containerd/certs.d",
34+
},
35+
"containerd": map[string]interface{}{
36+
"default_runtime_name": "runc",
37+
},
38+
39+
// these should be kept in the new cri grpc config
40+
"disable_tcp_service": false,
41+
"stream_server_address": "127.0.0.2",
42+
"stream_server_port": "10000",
43+
"stream_idle_timeout": "3h0m0s",
44+
"enable_tls_streaming": true,
45+
"x509_key_pair_streaming": map[string]interface{}{
46+
"cert_file": "/etc/containerd/certs.d/server.crt",
47+
"key_file": "/etc/containerd/certs.d/server.key",
48+
},
49+
}
50+
pluginConfigs := map[string]interface{}{
51+
pluginName: src,
52+
}
53+
configMigration(context.Background(), 2, pluginConfigs)
54+
55+
dst, ok := pluginConfigs[pluginName].(map[string]interface{})
56+
assert.True(t, ok)
57+
assert.NotNil(t, dst)
58+
59+
for _, k := range []string{"registry", "containerd"} {
60+
_, ok := dst[k]
61+
assert.False(t, ok)
62+
delete(src, k)
63+
}
64+
65+
for k, v := range src {
66+
assert.Equal(t, v, dst[k])
67+
}
68+
}

0 commit comments

Comments
 (0)