Skip to content

Commit 8313a1c

Browse files
committed
CRI: remove deprecated config properties (auths, configs, mirrors)
Remove the following config properties in `/etc/containerd/config.toml`: | Property Group | Property | Deprecation release | Target release for removal | Recommendation | |-------------------------------------------------|------------|---------------------|----------------------------|------------------------| |`[plugins."io.containerd.grpc.v1.cri".registry]` | `auths` | containerd v1.3 | containerd v2.0 ✅ | Use `ImagePullSecrets` | |`[plugins."io.containerd.grpc.v1.cri".registry]` | `configs` | containerd v1.5 | containerd v2.0 ✅ | Use `config_path` | |`[plugins."io.containerd.grpc.v1.cri".registry]` | `mirrors` | containerd v1.5 | containerd v2.0 ✅ | Use `config_path` | The toml properties are still kept for printing human-readable errors, but the properties will be completely removed in v2.1. Signed-off-by: Akihiro Suda <[email protected]>
1 parent c78d526 commit 8313a1c

6 files changed

Lines changed: 32 additions & 356 deletions

File tree

RELEASES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,9 @@ The deprecated properties in [`config.toml`](./docs/cri/config.md) are shown in
420420
|`[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.*]` | `runtime_engine` | containerd v1.3 | containerd v2.0 ✅ | Use runtime v2 |
421421
|`[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.*]` | `runtime_root` | containerd v1.3 | containerd v2.0 ✅ | Use `options.Root` |
422422
|`[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.*.options]` | `CriuPath` | containerd v1.7 | containerd v2.0 ✅ | Set `$PATH` to the `criu` binary |
423-
|`[plugins."io.containerd.grpc.v1.cri".registry]` | `auths` | containerd v1.3 | containerd v2.0 | Use [`ImagePullSecrets`](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/). See also [#8228](https://github.com/containerd/containerd/issues/8228). |
424-
|`[plugins."io.containerd.grpc.v1.cri".registry]` | `configs` | containerd v1.5 | containerd v2.0 | Use [`config_path`](./docs/hosts.md) |
425-
|`[plugins."io.containerd.grpc.v1.cri".registry]` | `mirrors` | containerd v1.5 | containerd v2.0 | Use [`config_path`](./docs/hosts.md) |
423+
|`[plugins."io.containerd.grpc.v1.cri".registry]` | `auths` | containerd v1.3 | containerd v2.0 | Use [`ImagePullSecrets`](https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/). See also [#8228](https://github.com/containerd/containerd/issues/8228). |
424+
|`[plugins."io.containerd.grpc.v1.cri".registry]` | `configs` | containerd v1.5 | containerd v2.0 | Use [`config_path`](./docs/hosts.md) |
425+
|`[plugins."io.containerd.grpc.v1.cri".registry]` | `mirrors` | containerd v1.5 | containerd v2.0 | Use [`config_path`](./docs/hosts.md) |
426426

427427
> **Note**
428428
>

integration/image_pull_timeout_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,6 @@ func testCRIImagePullTimeoutByNoDataTransferred(t *testing.T) {
276276
{
277277
ConfigPath: filepath.Dir(hostCfgDir),
278278
},
279-
// TODO(fuweid):
280-
//
281-
// Both Mirrors and Configs are deprecated in the future. And
282-
// this registryCfg should also be removed at that time.
283-
{
284-
Mirrors: map[string]criconfig.Mirror{
285-
mirrorURL.Host: {
286-
Endpoints: []string{mirrorURL.String()},
287-
},
288-
},
289-
},
290279
} {
291280
criService, err := initLocalCRIImageService(cli, tmpDir, registryCfg)
292281
assert.NoError(t, err)

internal/cri/config/config.go

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23-
"net/url"
2423
goruntime "runtime"
2524
"strconv"
2625
"time"
@@ -212,57 +211,25 @@ type CniConfig struct {
212211
IPPreference string `toml:"ip_pref" json:"ipPref"`
213212
}
214213

215-
// Mirror contains the config related to the registry mirror
216-
type Mirror struct {
217-
// Endpoints are endpoints for a namespace. CRI plugin will try the endpoints
218-
// one by one until a working one is found. The endpoint must be a valid url
219-
// with host specified.
220-
// The scheme, host and path from the endpoint URL will be used.
221-
Endpoints []string `toml:"endpoint" json:"endpoint"`
222-
}
223-
224-
// AuthConfig contains the config related to authentication to a specific registry
225-
type AuthConfig struct {
226-
// Username is the username to login the registry.
227-
Username string `toml:"username" json:"username"`
228-
// Password is the password to login the registry.
229-
Password string `toml:"password" json:"password"`
230-
// Auth is a base64 encoded string from the concatenation of the username,
231-
// a colon, and the password.
232-
Auth string `toml:"auth" json:"auth"`
233-
// IdentityToken is used to authenticate the user and get
234-
// an access token for the registry.
235-
IdentityToken string `toml:"identitytoken" json:"identitytoken"`
236-
}
237-
238214
// Registry is registry settings configured
239215
type Registry struct {
240216
// ConfigPath is a path to the root directory containing registry-specific
241217
// configurations.
242218
// If ConfigPath is set, the rest of the registry specific options are ignored.
243219
ConfigPath string `toml:"config_path" json:"configPath"`
244-
// Mirrors are namespace to mirror mapping for all namespaces.
245-
// This option will not be used when ConfigPath is provided.
246-
// DEPRECATED: Use ConfigPath instead. Remove in containerd 2.0.
247-
Mirrors map[string]Mirror `toml:"mirrors" json:"mirrors"`
248-
// Configs are configs for each registry.
249-
// The key is the domain name or IP of the registry.
250-
// DEPRECATED: Use ConfigPath instead.
251-
Configs map[string]RegistryConfig `toml:"configs" json:"configs"`
252-
// Auths are registry endpoint to auth config mapping. The registry endpoint must
253-
// be a valid url with host specified.
254-
// DEPRECATED: Use ConfigPath instead. Remove in containerd 2.0, supported in 1.x releases.
255-
Auths map[string]AuthConfig `toml:"auths" json:"auths"`
220+
// MirrorsNoLongerSupported (Mirrors) was deprecated in containerd v1.5 and removed in v2.0.
221+
// TODO: completely stop parsing this in v2.1.
222+
MirrorsNoLongerSupported map[string]any `toml:"mirrors" json:"mirrors"`
223+
// ConfigsNoLongerSupported (Configs) was deprecated in containerd v1.5 and removed in v2.0.
224+
// TODO: completely stop parsing this in v2.1.
225+
ConfigsNoLongerSupported map[string]any `toml:"configs" json:"configs"`
226+
// AuthsNoLongerSupported (Auths) was deprecated in containerd v1.3 and removed in v2.0.
227+
// TODO: completely stop parsing this in v2.1.
228+
AuthsNoLongerSupported map[string]any `toml:"auths" json:"auths"`
256229
// Headers adds additional HTTP headers that get sent to all registries
257230
Headers map[string][]string `toml:"headers" json:"headers"`
258231
}
259232

260-
// RegistryConfig contains configuration used to communicate with the registry.
261-
type RegistryConfig struct {
262-
// Auth contains information to authenticate to the registry.
263-
Auth *AuthConfig `toml:"auth" json:"auth"`
264-
}
265-
266233
// ImageDecryption contains configuration to handling decryption of encrypted container images.
267234
type ImageDecryption struct {
268235
// KeyModel specifies the trust model of where keys should reside.
@@ -486,41 +453,17 @@ const (
486453
func ValidateImageConfig(ctx context.Context, c *ImageConfig) ([]deprecation.Warning, error) {
487454
var warnings []deprecation.Warning
488455

489-
useConfigPath := c.Registry.ConfigPath != ""
490-
if len(c.Registry.Mirrors) > 0 {
491-
if useConfigPath {
492-
return warnings, errors.New("`mirrors` cannot be set when `config_path` is provided")
493-
}
494-
warnings = append(warnings, deprecation.CRIRegistryMirrors)
495-
log.G(ctx).Warning("`mirrors` is deprecated, please use `config_path` instead")
456+
if len(c.Registry.MirrorsNoLongerSupported) > 0 {
457+
return warnings, errors.New("`mirrors` is no longer supported since containerd v2.0, please use `config_path` instead")
496458
}
497459

498-
if len(c.Registry.Configs) != 0 {
499-
warnings = append(warnings, deprecation.CRIRegistryConfigs)
500-
log.G(ctx).Warning("`configs` is deprecated, please use `config_path` instead")
460+
if len(c.Registry.ConfigsNoLongerSupported) != 0 {
461+
return warnings, errors.New("`configs` is no longer supported since containerd v2.0, please use `config_path` instead")
501462
}
502463

503464
// Validation for deprecated auths options and mapping it to configs.
504-
if len(c.Registry.Auths) != 0 {
505-
if c.Registry.Configs == nil {
506-
c.Registry.Configs = make(map[string]RegistryConfig)
507-
}
508-
for endpoint, auth := range c.Registry.Auths {
509-
auth := auth
510-
u, err := url.Parse(endpoint)
511-
if err != nil {
512-
return warnings, fmt.Errorf("failed to parse registry url %q from `registry.auths`: %w", endpoint, err)
513-
}
514-
if u.Scheme != "" {
515-
// Do not include the scheme in the new registry config.
516-
endpoint = u.Host
517-
}
518-
config := c.Registry.Configs[endpoint]
519-
config.Auth = &auth
520-
c.Registry.Configs[endpoint] = config
521-
}
522-
warnings = append(warnings, deprecation.CRIRegistryAuths)
523-
log.G(ctx).Warning("`auths` is deprecated, please use `ImagePullSecrets` instead")
465+
if len(c.Registry.AuthsNoLongerSupported) != 0 {
466+
return warnings, errors.New("`auths` is no longer supported since containerd v2.0, please use `ImagePullSecrets` instead")
524467
}
525468

526469
// Validation for image_pull_progress_timeout

internal/cri/config/config_test.go

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,12 @@ func TestValidateConfig(t *testing.T) {
7373
},
7474
imageConfig: &ImageConfig{
7575
Registry: Registry{
76-
Auths: map[string]AuthConfig{
77-
"https://gcr.io": {Username: "test"},
76+
AuthsNoLongerSupported: map[string]any{
77+
"https://gcr.io": map[string]any{"username": "test"},
7878
},
7979
},
8080
},
81-
imageExpected: &ImageConfig{
82-
Registry: Registry{
83-
Configs: map[string]RegistryConfig{
84-
"gcr.io": {
85-
Auth: &AuthConfig{
86-
Username: "test",
87-
},
88-
},
89-
},
90-
Auths: map[string]AuthConfig{
91-
"https://gcr.io": {Username: "test"},
92-
},
93-
},
94-
},
95-
warnings: []deprecation.Warning{deprecation.CRIRegistryAuths},
81+
imageExpectedErr: "`auths` is no longer supported since containerd v2.0",
9682
},
9783
"invalid stream_idle_timeout": {
9884
serverConfig: &ServerConfig{
@@ -104,12 +90,12 @@ func TestValidateConfig(t *testing.T) {
10490
imageConfig: &ImageConfig{
10591
Registry: Registry{
10692
ConfigPath: "/etc/containerd/conf.d",
107-
Mirrors: map[string]Mirror{
108-
"something.io": {},
93+
MirrorsNoLongerSupported: map[string]any{
94+
"something.io": map[string]any{},
10995
},
11096
},
11197
},
112-
imageExpectedErr: "`mirrors` cannot be set when `config_path` is provided",
98+
imageExpectedErr: "`mirrors` is no longer supported since containerd v2.0",
11399
},
114100
"deprecated mirrors": {
115101
runtimeConfig: &RuntimeConfig{
@@ -122,8 +108,8 @@ func TestValidateConfig(t *testing.T) {
122108
},
123109
imageConfig: &ImageConfig{
124110
Registry: Registry{
125-
Mirrors: map[string]Mirror{
126-
"example.com": {},
111+
MirrorsNoLongerSupported: map[string]any{
112+
"example.com": map[string]any{},
127113
},
128114
},
129115
},
@@ -137,14 +123,7 @@ func TestValidateConfig(t *testing.T) {
137123
},
138124
},
139125
},
140-
imageExpected: &ImageConfig{
141-
Registry: Registry{
142-
Mirrors: map[string]Mirror{
143-
"example.com": {},
144-
},
145-
},
146-
},
147-
warnings: []deprecation.Warning{deprecation.CRIRegistryMirrors},
126+
imageExpectedErr: "`mirrors` is no longer supported since containerd v2.0",
148127
},
149128
"deprecated configs": {
150129
runtimeConfig: &RuntimeConfig{
@@ -157,10 +136,10 @@ func TestValidateConfig(t *testing.T) {
157136
},
158137
imageConfig: &ImageConfig{
159138
Registry: Registry{
160-
Configs: map[string]RegistryConfig{
161-
"gcr.io": {
162-
Auth: &AuthConfig{
163-
Username: "test",
139+
ConfigsNoLongerSupported: map[string]any{
140+
"gcr.io": map[string]any{
141+
"auth": map[string]any{
142+
"username": "test",
164143
},
165144
},
166145
},
@@ -176,18 +155,7 @@ func TestValidateConfig(t *testing.T) {
176155
},
177156
},
178157
},
179-
imageExpected: &ImageConfig{
180-
Registry: Registry{
181-
Configs: map[string]RegistryConfig{
182-
"gcr.io": {
183-
Auth: &AuthConfig{
184-
Username: "test",
185-
},
186-
},
187-
},
188-
},
189-
},
190-
warnings: []deprecation.Warning{deprecation.CRIRegistryConfigs},
158+
imageExpectedErr: "`configs` is no longer supported since containerd v2.0",
191159
},
192160
"privileged_without_host_devices_all_devices_allowed without privileged_without_host_devices": {
193161
runtimeConfig: &RuntimeConfig{

internal/cri/server/images/image_pull.go

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ import (
4545
"github.com/containerd/containerd/v2/core/remotes/docker"
4646
"github.com/containerd/containerd/v2/core/remotes/docker/config"
4747
"github.com/containerd/containerd/v2/internal/cri/annotations"
48-
criconfig "github.com/containerd/containerd/v2/internal/cri/config"
4948
crilabels "github.com/containerd/containerd/v2/internal/cri/labels"
5049
snpkg "github.com/containerd/containerd/v2/pkg/snapshotters"
5150
"github.com/containerd/containerd/v2/pkg/tracing"
@@ -100,12 +99,6 @@ func (c *GRPCCRIImageService) PullImage(ctx context.Context, r *runtime.PullImag
10099

101100
credentials := func(host string) (string, string, error) {
102101
hostauth := r.GetAuth()
103-
if hostauth == nil {
104-
config := c.config.Registry.Configs[host]
105-
if config.Auth != nil {
106-
hostauth = toRuntimeAuthConfig(*config.Auth)
107-
}
108-
}
109102
return ParseAuth(hostauth, host)
110103
}
111104

@@ -444,7 +437,6 @@ func (c *CRIImageService) registryHosts(ctx context.Context, credentials func(ho
444437
var (
445438
transport = newTransport()
446439
client = &http.Client{Transport: transport}
447-
config = c.config.Registry.Configs[u.Host]
448440
)
449441

450442
if docker.IsLocalhost(host) && u.Scheme == "http" {
@@ -457,13 +449,6 @@ func (c *CRIImageService) registryHosts(ctx context.Context, credentials func(ho
457449
// Make a copy of `credentials`, so that different authorizers would not reference
458450
// the same credentials variable.
459451
credentials := credentials
460-
if credentials == nil && config.Auth != nil {
461-
auth := toRuntimeAuthConfig(*config.Auth)
462-
credentials = func(host string) (string, string, error) {
463-
return ParseAuth(auth, host)
464-
}
465-
466-
}
467452

468453
if updateClientFn != nil {
469454
if err := updateClientFn(client); err != nil {
@@ -492,16 +477,6 @@ func (c *CRIImageService) registryHosts(ctx context.Context, credentials func(ho
492477
}
493478
}
494479

495-
// toRuntimeAuthConfig converts cri plugin auth config to runtime auth config.
496-
func toRuntimeAuthConfig(a criconfig.AuthConfig) *runtime.AuthConfig {
497-
return &runtime.AuthConfig{
498-
Username: a.Username,
499-
Password: a.Password,
500-
Auth: a.Auth,
501-
IdentityToken: a.IdentityToken,
502-
}
503-
}
504-
505480
// defaultScheme returns the default scheme for a registry host.
506481
func defaultScheme(host string) string {
507482
if docker.IsLocalhost(host) {
@@ -510,51 +485,13 @@ func defaultScheme(host string) string {
510485
return "https"
511486
}
512487

513-
// addDefaultScheme returns the endpoint with default scheme
514-
func addDefaultScheme(endpoint string) (string, error) {
515-
if strings.Contains(endpoint, "://") {
516-
return endpoint, nil
517-
}
518-
ue := "dummy://" + endpoint
519-
u, err := url.Parse(ue)
520-
if err != nil {
521-
return "", err
522-
}
523-
return fmt.Sprintf("%s://%s", defaultScheme(u.Host), endpoint), nil
524-
}
525-
526488
// registryEndpoints returns endpoints for a given host.
527-
// It adds default registry endpoint if it does not exist in the passed-in endpoint list.
528-
// It also supports wildcard host matching with `*`.
529489
func (c *CRIImageService) registryEndpoints(host string) ([]string, error) {
530490
var endpoints []string
531-
_, ok := c.config.Registry.Mirrors[host]
532-
if ok {
533-
endpoints = c.config.Registry.Mirrors[host].Endpoints
534-
} else {
535-
endpoints = c.config.Registry.Mirrors["*"].Endpoints
536-
}
537491
defaultHost, err := docker.DefaultHost(host)
538492
if err != nil {
539493
return nil, fmt.Errorf("get default host: %w", err)
540494
}
541-
for i := range endpoints {
542-
en, err := addDefaultScheme(endpoints[i])
543-
if err != nil {
544-
return nil, fmt.Errorf("parse endpoint url: %w", err)
545-
}
546-
endpoints[i] = en
547-
}
548-
for _, e := range endpoints {
549-
u, err := url.Parse(e)
550-
if err != nil {
551-
return nil, fmt.Errorf("parse endpoint url: %w", err)
552-
}
553-
if u.Host == host {
554-
// Do not add default if the endpoint already exists.
555-
return endpoints, nil
556-
}
557-
}
558495
return append(endpoints, defaultScheme(defaultHost)+"://"+defaultHost), nil
559496
}
560497

0 commit comments

Comments
 (0)