mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-29 23:41:41 +01:00
This PR does those things: - It allows API calls `MetaWrite` and `MetaRead` in maintenance mode. - SystemInformation resource now waits for available META - SystemInformation resource now overwrites UUID from META if there is an override - META now supports "UUID override" and "unique token" keys - ProvisionRequest now includes unique token and Talos version For #7694 Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
57 lines
1.9 KiB
Go
57 lines
1.9 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 runtime
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/cosi-project/runtime/pkg/controller"
|
|
"github.com/cosi-project/runtime/pkg/controller/generic/transform"
|
|
"github.com/cosi-project/runtime/pkg/safe"
|
|
"github.com/cosi-project/runtime/pkg/state"
|
|
"github.com/siderolabs/gen/optional"
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/siderolabs/talos/internal/pkg/meta"
|
|
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
|
|
)
|
|
|
|
// UniqueMachineTokenController provides a unique token the machine.
|
|
type UniqueMachineTokenController = transform.Controller[*runtime.MetaLoaded, *runtime.UniqueMachineToken]
|
|
|
|
// NewUniqueMachineTokenController instanciates the controller.
|
|
func NewUniqueMachineTokenController() *UniqueMachineTokenController {
|
|
return transform.NewController(
|
|
transform.Settings[*runtime.MetaLoaded, *runtime.UniqueMachineToken]{
|
|
Name: "runtime.UniqueMachineTokenController",
|
|
MapMetadataFunc: func(in *runtime.MetaLoaded) *runtime.UniqueMachineToken {
|
|
return runtime.NewUniqueMachineToken()
|
|
},
|
|
TransformFunc: func(ctx context.Context, r controller.Reader, logger *zap.Logger, _ *runtime.MetaLoaded, out *runtime.UniqueMachineToken) error {
|
|
uniqueToken, err := safe.ReaderGetByID[*runtime.MetaKey](ctx, r, runtime.MetaKeyTagToID(meta.UniqueMachineToken))
|
|
if state.IsNotFoundError(err) {
|
|
out.TypedSpec().Token = ""
|
|
|
|
return nil
|
|
} else if err != nil {
|
|
return err
|
|
}
|
|
|
|
out.TypedSpec().Token = uniqueToken.TypedSpec().Value
|
|
|
|
return nil
|
|
},
|
|
},
|
|
transform.WithExtraInputs(
|
|
controller.Input{
|
|
Namespace: runtime.NamespaceName,
|
|
Type: runtime.MetaKeyType,
|
|
ID: optional.Some(runtime.MetaKeyTagToID(meta.UniqueMachineToken)),
|
|
Kind: controller.InputWeak,
|
|
},
|
|
),
|
|
)
|
|
}
|