Skip to content

Commit d58df07

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 Signed-off-by: Akhil Mohan <[email protected]>
1 parent 6674e65 commit d58df07

2 files changed

Lines changed: 9 additions & 16 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: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"path/filepath"
23-
"runtime"
2423

2524
containerd "github.com/containerd/containerd/v2/client"
2625
"github.com/containerd/containerd/v2/core/metadata"
@@ -61,6 +60,14 @@ func init() {
6160
}
6261
mdb := m.(*metadata.DB)
6362

63+
// only set the default value of config path, if both mirrors and
64+
// config path are empty.
65+
// This also makes sure that if the loaded config already contains both config path and mirrors
66+
// the validation will fail.
67+
if config.Registry.ConfigPath == "" && len(config.Registry.Mirrors) == 0 {
68+
config.Registry.ConfigPath = "/etc/containerd/certs.d:/etc/docker/certs.d"
69+
}
70+
6471
if warnings, err := criconfig.ValidateImageConfig(ic.Context, &config); err != nil {
6572
return nil, fmt.Errorf("invalid cri image config: %w", err)
6673
} else if len(warnings) > 0 {
@@ -210,18 +217,6 @@ func migrateConfig(dst, src map[string]interface{}) {
210217
dst[key] = val
211218
}
212219
}
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-
}
225220

226221
containerdConf, ok := src["containerd"]
227222
if !ok {

0 commit comments

Comments
 (0)