Andrey Smirnov dc6764871c
refactor: move around config interfaces, make RawV1Alpha1 typed
See #7230

Refactor more config interfaces, move config accessor interfaces
to different package to break the dependency loop.

Make `.RawV1Alpha1()` method typed to avoid type assertions everywhere.

No functional changes.

Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
2023-05-23 22:08:58 +04: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/siderolabs/talos/pkg/machinery/config/config"
"github.com/siderolabs/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
}