-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split
config.Registry
into the separate resource
Required for #9614 Closes #9766 Signed-off-by: Dmitriy Matrenichev <[email protected]>
- Loading branch information
Showing
11 changed files
with
2,199 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
syntax = "proto3"; | ||
|
||
package talos.resource.definitions.registry; | ||
|
||
option go_package = "github.com/siderolabs/talos/pkg/machinery/api/resource/definitions/registry"; | ||
option java_package = "dev.talos.api.resource.definitions.registry"; | ||
|
||
import "common/common.proto"; | ||
|
||
// AuthConfig specifies authentication configuration for a registry. | ||
message AuthConfig { | ||
string registry_username = 1; | ||
string registry_password = 2; | ||
string registry_auth = 3; | ||
string registry_identity_token = 4; | ||
} | ||
|
||
// Config specifies auth & TLS config per registry. | ||
message Config { | ||
TLSConfig registry_tls = 1; | ||
AuthConfig registry_auth = 2; | ||
} | ||
|
||
// MirrorConfig represents mirror configuration for a registry. | ||
message MirrorConfig { | ||
repeated string mirror_endpoints = 1; | ||
bool mirror_override_path = 2; | ||
bool mirror_skip_fallback = 3; | ||
} | ||
|
||
// RegistriesSpecSpec describes status of rendered secrets. | ||
message RegistriesSpecSpec { | ||
map<string, MirrorConfig> registry_mirrors = 1; | ||
map<string, Config> registry_config = 2; | ||
} | ||
|
||
// TLSConfig specifies TLS config for HTTPS registries. | ||
message TLSConfig { | ||
common.PEMEncodedCertificateAndKey tls_client_identity = 1; | ||
bytes tlsca = 2; | ||
bool tls_insecure_skip_verify = 3; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
internal/app/machined/pkg/controllers/registry/registry.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// 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 registry provides controllers for registry configuration. | ||
package registry | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cosi-project/runtime/pkg/controller" | ||
"github.com/cosi-project/runtime/pkg/controller/generic/transform" | ||
"github.com/siderolabs/gen/optional" | ||
"go.uber.org/zap" | ||
|
||
"github.com/siderolabs/talos/pkg/machinery/resources/config" | ||
"github.com/siderolabs/talos/pkg/machinery/resources/registry" | ||
) | ||
|
||
// ConfigController watches v1alpha1.Config, updates registry.RegistriesSpec. | ||
type ConfigController = transform.Controller[*config.MachineConfig, *registry.RegistriesSpec] | ||
|
||
// NewConfigController instanciates the config controller. | ||
func NewConfigController() *ConfigController { | ||
return transform.NewController( | ||
transform.Settings[*config.MachineConfig, *registry.RegistriesSpec]{ | ||
Name: "registry.ConfigController", | ||
MapMetadataOptionalFunc: func(cfg *config.MachineConfig) optional.Optional[*registry.RegistriesSpec] { | ||
if cfg.Metadata().ID() != config.V1Alpha1ID { | ||
return optional.None[*registry.RegistriesSpec]() | ||
} | ||
|
||
if cfg.Config().Machine() == nil { | ||
return optional.None[*registry.RegistriesSpec]() | ||
} | ||
|
||
return optional.Some(registry.NewRegistriesSpec()) | ||
}, | ||
TransformFunc: func(ctx context.Context, r controller.Reader, logger *zap.Logger, cfg *config.MachineConfig, res *registry.RegistriesSpec) error { | ||
spec := res.TypedSpec() | ||
|
||
if cfg != nil && cfg.Config().Machine() != nil { | ||
clear(spec.RegistryConfig) | ||
clear(spec.RegistryMirrors) | ||
|
||
// I have no idea how to bypass `RawV1Alpha1` since I need original types and not interfaces. | ||
mr := cfg.Provider().RawV1Alpha1().MachineConfig.MachineRegistries | ||
|
||
for k, v := range mr.RegistryConfig { | ||
if spec.RegistryConfig == nil { | ||
spec.RegistryConfig = make(map[string]*registry.Config, len(mr.RegistryConfig)) | ||
} | ||
|
||
spec.RegistryConfig[k] = ®istry.Config{ | ||
RegistryTLS: ®istry.TLSConfig{ | ||
TLSClientIdentity: v.RegistryTLS.TLSClientIdentity, | ||
TLSCA: v.RegistryTLS.TLSCA, | ||
TLSInsecureSkipVerify: v.RegistryTLS.TLSInsecureSkipVerify, | ||
}, | ||
RegistryAuth: ®istry.AuthConfig{ | ||
RegistryUsername: v.RegistryAuth.RegistryUsername, | ||
RegistryPassword: v.RegistryAuth.RegistryPassword, | ||
RegistryAuth: v.RegistryAuth.RegistryAuth, | ||
RegistryIdentityToken: v.RegistryAuth.RegistryIdentityToken, | ||
}, | ||
} | ||
} | ||
|
||
for k, v := range mr.RegistryMirrors { | ||
if spec.RegistryMirrors == nil { | ||
spec.RegistryMirrors = make(map[string]*registry.MirrorConfig, len(mr.RegistryMirrors)) | ||
} | ||
|
||
spec.RegistryMirrors[k] = ®istry.MirrorConfig{ | ||
MirrorEndpoints: v.MirrorEndpoints, | ||
MirrorOverridePath: v.MirrorOverridePath, | ||
MirrorSkipFallback: v.MirrorSkipFallback, | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.