-
Notifications
You must be signed in to change notification settings - Fork 458
/
info.go
46 lines (37 loc) · 1.5 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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 cluster
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/cluster"
"github.com/siderolabs/talos/pkg/machinery/resources/config"
)
// InfoController looks up control plane infos.
type InfoController = transform.Controller[*config.MachineConfig, *cluster.Info]
// NewInfoController instanciates the cluster info controller.
func NewInfoController() *InfoController {
return transform.NewController(
transform.Settings[*config.MachineConfig, *cluster.Info]{
Name: "cluster.InfoController",
MapMetadataOptionalFunc: func(cfg *config.MachineConfig) optional.Optional[*cluster.Info] {
if cfg.Metadata().ID() != config.V1Alpha1ID {
return optional.None[*cluster.Info]()
}
if cfg.Config().Cluster() == nil {
return optional.None[*cluster.Info]()
}
return optional.Some(cluster.NewInfo())
},
TransformFunc: func(ctx context.Context, r controller.Reader, logger *zap.Logger, cfg *config.MachineConfig, info *cluster.Info) error {
info.TypedSpec().ClusterID = cfg.Config().Cluster().ID()
info.TypedSpec().ClusterName = cfg.Config().Cluster().Name()
return nil
},
},
)
}