Andrey Smirnov d4b8445935
feat: support CRI configuration merging and reimplement registry config
Containerd doesn't support merging plugin configuration from multiple
sources, and Talos has several pieces which configure CRI plugin:
(see https://github.com/containerd/containerd/issues/5837)

* base config
* registry mirror config
* system extensions
* ...

So we implement our own simple way of merging config parts (by simply
concatenating text files) to build a final `cri.toml`.

At the same time containerd migrated to a new format to specify registry
mirror configuration, while old way (via CRI config) is going to be
removed in 1.7.0. New way also allows to apply most of registry
configuration (except for auth) on the fly.

Also, containerd was updated to 1.6.0-rc.0 and runc to 1.1.0.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2022-01-20 23:05:20 +03:00

48 lines
1.4 KiB
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Package containerd provides support for containerd CRI plugin
package containerd
import (
"bytes"
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/talos-systems/talos/pkg/machinery/config"
"github.com/talos-systems/talos/pkg/machinery/constants"
)
// GenerateCRIConfig returns a part of CRI config for registry auth.
//
// Once containerd supports different way of supplying auth info, this should be updated.
func GenerateCRIConfig(r config.Registries) ([]byte, error) {
var ctrdCfg Config
ctrdCfg.Plugins.CRI.Registry.ConfigPath = filepath.Join(constants.CRIConfdPath, "hosts")
ctrdCfg.Plugins.CRI.Registry.Configs = make(map[string]RegistryConfig)
for registryHost, hostConfig := range r.Config() {
if hostConfig.Auth() != nil {
cfg := RegistryConfig{}
cfg.Auth = &AuthConfig{
Username: hostConfig.Auth().Username(),
Password: hostConfig.Auth().Password(),
Auth: hostConfig.Auth().Auth(),
IdentityToken: hostConfig.Auth().IdentityToken(),
}
ctrdCfg.Plugins.CRI.Registry.Configs[registryHost] = cfg
}
}
var buf bytes.Buffer
if err := toml.NewEncoder(&buf).Encode(&ctrdCfg); err != nil {
return nil, err
}
return buf.Bytes(), nil
}