Skip to content

Commit a20dead

Browse files
akhilermsamuelkarp
authored andcommitted
set default config_path in plugin init
move setting the config_path from default image config to plugin init. only set the default value when both mirrors and config_path are empty, in all other cases retain the existing behaviour Co-authored-by: Samuel Karp <[email protected]> Signed-off-by: Akhil Mohan <[email protected]> Signed-off-by: Samuel Karp <[email protected]>
1 parent 8b085dd commit a20dead

2 files changed

Lines changed: 11 additions & 15 deletions

File tree

internal/cri/config/config_unix.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ func DefaultImageConfig() ImageConfig {
3232
Snapshotter: defaults.DefaultSnapshotter,
3333
DisableSnapshotAnnotations: true,
3434
MaxConcurrentDownloads: 3,
35-
Registry: Registry{
36-
ConfigPath: "/etc/containerd/certs.d:/etc/docker/certs.d",
37-
},
35+
Registry: Registry{},
3836
ImageDecryption: ImageDecryption{
3937
KeyModel: KeyModelNode,
4038
},

plugins/cri/images/plugin.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ func init() {
6161
}
6262
mdb := m.(*metadata.DB)
6363

64+
// only set the default value of config path, if both mirrors and
65+
// config path are empty and we are on Linux.
66+
// This also makes sure that if the loaded config already contains both config path and mirrors
67+
// the validation will fail.
68+
if runtime.GOOS == "linux" {
69+
if config.Registry.ConfigPath == "" && len(config.Registry.Mirrors) == 0 {
70+
config.Registry.ConfigPath = "/etc/containerd/certs.d:/etc/docker/certs.d"
71+
}
72+
}
73+
6474
if warnings, err := criconfig.ValidateImageConfig(ic.Context, &config); err != nil {
6575
return nil, fmt.Errorf("invalid cri image config: %w", err)
6676
} else if len(warnings) > 0 {
@@ -210,18 +220,6 @@ func migrateConfig(dst, src map[string]interface{}) {
210220
dst[key] = val
211221
}
212222
}
213-
if runtime.GOOS == "linux" {
214-
if value, ok := dst["registry"]; ok {
215-
regMap := value.(map[string]any)
216-
if configPath, ok := regMap["config_path"]; ok {
217-
if configPath == "" {
218-
// Fill in default from config_unix.go (DefaultImageConfig)
219-
regMap["config_path"] = "/etc/containerd/certs.d:/etc/docker/certs.d"
220-
}
221-
}
222-
dst["registry"] = regMap
223-
}
224-
}
225223

226224
containerdConf, ok := src["containerd"]
227225
if !ok {

0 commit comments

Comments
 (0)