mirror of
https://github.com/siderolabs/talos.git
synced 2025-12-07 02:21:14 +01:00
```text ❯ talosctl -n 10.5.0.3 get version NODE NAMESPACE TYPE ID VERSION VERSION 10.5.0.3 runtime Version version 1 v1.10.0-alpha.3-33-g84f69f043-dirty ``` Fixes: #10574 Signed-off-by: Noel Georgi <git@frezbo.dev>
54 lines
1.5 KiB
Go
54 lines
1.5 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"
|
|
"fmt"
|
|
|
|
"github.com/cosi-project/runtime/pkg/controller"
|
|
"github.com/cosi-project/runtime/pkg/safe"
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/siderolabs/talos/pkg/machinery/resources/runtime"
|
|
"github.com/siderolabs/talos/pkg/machinery/version"
|
|
)
|
|
|
|
// VersionController populates the version of currently running Talos.
|
|
type VersionController struct{}
|
|
|
|
// Name implements controller.Controller interface.
|
|
func (ctrl *VersionController) Name() string {
|
|
return "runtime.VersionController"
|
|
}
|
|
|
|
// Inputs implements controller.Controller interface.
|
|
func (ctrl *VersionController) Inputs() []controller.Input {
|
|
return nil
|
|
}
|
|
|
|
// Outputs implements controller.Controller interface.
|
|
func (ctrl *VersionController) Outputs() []controller.Output {
|
|
return []controller.Output{
|
|
{
|
|
Type: runtime.VersionType,
|
|
Kind: controller.OutputExclusive,
|
|
},
|
|
}
|
|
}
|
|
|
|
// Run implements controller.Controller interface.
|
|
func (ctrl *VersionController) Run(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
|
|
if err := safe.WriterModify(ctx, r, runtime.NewVersion(), func(status *runtime.Version) error {
|
|
status.TypedSpec().Version = version.Tag
|
|
|
|
return nil
|
|
}); err != nil {
|
|
return fmt.Errorf("failed to update version status: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|