-
Notifications
You must be signed in to change notification settings - Fork 451
/
nodeip.go
58 lines (46 loc) · 1.65 KB
/
nodeip.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
47
48
49
50
51
52
53
54
55
56
57
58
// 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 k8s
import (
"net/netip"
"github.com/cosi-project/runtime/pkg/resource"
"github.com/cosi-project/runtime/pkg/resource/meta"
"github.com/cosi-project/runtime/pkg/resource/protobuf"
"github.com/cosi-project/runtime/pkg/resource/typed"
"github.com/siderolabs/talos/pkg/machinery/proto"
)
// NodeIPType is type of NodeIP resource.
const NodeIPType = resource.Type("NodeIPs.kubernetes.talos.dev")
// NodeIP resource holds definition of Node IP specification.
type NodeIP = typed.Resource[NodeIPSpec, NodeIPExtension]
// NodeIPSpec holds the Node IP specification.
//
//gotagsrewrite:gen
type NodeIPSpec struct {
Addresses []netip.Addr `yaml:"addresses" protobuf:"1"`
}
// NewNodeIP initializes an empty NodeIP resource.
func NewNodeIP(namespace resource.Namespace, id resource.ID) *NodeIP {
return typed.NewResource[NodeIPSpec, NodeIPExtension](
resource.NewMetadata(namespace, NodeIPType, id, resource.VersionUndefined),
NodeIPSpec{},
)
}
// NodeIPExtension provides auxiliary methods for NodeIP.
type NodeIPExtension struct{}
// ResourceDefinition implements [typed.Extension] interface.
func (NodeIPExtension) ResourceDefinition() meta.ResourceDefinitionSpec {
return meta.ResourceDefinitionSpec{
Type: NodeIPType,
Aliases: []resource.Type{},
DefaultNamespace: NamespaceName,
}
}
func init() {
proto.RegisterDefaultTypes()
err := protobuf.RegisterDynamic[NodeIPSpec](NodeIPType, &NodeIP{})
if err != nil {
panic(err)
}
}