talos

Форк
0
/
request.go 
233 строки · 5.4 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package provision
6

7
import (
8
	"errors"
9
	"net/netip"
10
	"slices"
11
	"time"
12

13
	"github.com/google/uuid"
14
	"github.com/siderolabs/go-procfs/procfs"
15

16
	"github.com/siderolabs/talos/pkg/machinery/config"
17
	"github.com/siderolabs/talos/pkg/machinery/config/machine"
18
	"github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1"
19
)
20

21
// ClusterRequest is the root object describing cluster to be provisioned.
22
type ClusterRequest struct {
23
	Name string
24

25
	Network NetworkRequest
26
	Nodes   NodeRequests
27

28
	// Docker specific parameters.
29
	Image string
30

31
	// Boot options (QEMU).
32
	KernelPath     string
33
	InitramfsPath  string
34
	ISOPath        string
35
	DiskImagePath  string
36
	IPXEBootScript string
37

38
	// Encryption
39
	KMSEndpoint string
40

41
	// Path to talosctl executable to re-execute itself as needed.
42
	SelfExecutable string
43

44
	// Path to root of state directory (~/.talos/clusters by default).
45
	StateDirectory string
46

47
	SiderolinkRequest SiderolinkRequest
48
}
49

50
// CNIConfig describes CNI part of NetworkRequest.
51
type CNIConfig struct {
52
	BinPath  []string
53
	ConfDir  string
54
	CacheDir string
55

56
	BundleURL string
57
}
58

59
// NetworkRequest describes cluster network.
60
type NetworkRequest struct {
61
	Name              string
62
	CIDRs             []netip.Prefix
63
	NoMasqueradeCIDRs []netip.Prefix
64
	GatewayAddrs      []netip.Addr
65
	MTU               int
66
	Nameservers       []netip.Addr
67

68
	LoadBalancerPorts []int
69

70
	// CNI-specific parameters.
71
	CNI CNIConfig
72

73
	// DHCP options
74
	DHCPSkipHostname bool
75

76
	// Docker-specific parameters.
77
	DockerDisableIPv6 bool
78

79
	// Network chaos parameters.
80
	NetworkChaos  bool
81
	Jitter        time.Duration
82
	Latency       time.Duration
83
	PacketLoss    float64
84
	PacketReorder float64
85
	PacketCorrupt float64
86
	Bandwidth     int
87
}
88

89
// NodeRequests is a list of NodeRequest.
90
type NodeRequests []NodeRequest
91

92
// FindInitNode looks up init node, it returns an error if no init node is present or if it's duplicate.
93
func (reqs NodeRequests) FindInitNode() (req NodeRequest, err error) {
94
	found := false
95

96
	for i := range reqs {
97
		if reqs[i].Config == nil {
98
			continue
99
		}
100

101
		if reqs[i].Config.Machine().Type() == machine.TypeInit {
102
			if found {
103
				err = errors.New("duplicate init node in requests")
104

105
				return
106
			}
107

108
			req = reqs[i]
109
			found = true
110
		}
111
	}
112

113
	if !found {
114
		err = errors.New("no init node found in requests")
115
	}
116

117
	return
118
}
119

120
// ControlPlaneNodes returns subset of nodes which are Init/ControlPlane type.
121
func (reqs NodeRequests) ControlPlaneNodes() (nodes []NodeRequest) {
122
	for i := range reqs {
123
		if reqs[i].Type == machine.TypeInit || reqs[i].Type == machine.TypeControlPlane {
124
			nodes = append(nodes, reqs[i])
125
		}
126
	}
127

128
	return
129
}
130

131
// WorkerNodes returns subset of nodes which are Init/ControlPlane type.
132
func (reqs NodeRequests) WorkerNodes() (nodes []NodeRequest) {
133
	for i := range reqs {
134
		if reqs[i].Type == machine.TypeWorker {
135
			nodes = append(nodes, reqs[i])
136
		}
137
	}
138

139
	return
140
}
141

142
// PXENodes returns subset of nodes which are PXE booted.
143
func (reqs NodeRequests) PXENodes() (nodes []NodeRequest) {
144
	for i := range reqs {
145
		if reqs[i].PXEBooted {
146
			nodes = append(nodes, reqs[i])
147
		}
148
	}
149

150
	return
151
}
152

153
// Disk represents a disk size and name in NodeRequest.
154
type Disk struct {
155
	// Size in bytes.
156
	Size uint64
157
	// Whether to skip preallocating the disk space.
158
	SkipPreallocate bool
159
	// Partitions represents the list of partitions.
160
	Partitions []*v1alpha1.DiskPartition
161
	// Driver for the disk.
162
	//
163
	// Supported types: "virtio", "ide", "ahci", "scsi", "nvme".
164
	Driver string
165
}
166

167
// NodeRequest describes a request for a node.
168
type NodeRequest struct {
169
	Name   string
170
	IPs    []netip.Addr
171
	Config config.Provider
172
	Type   machine.Type
173

174
	// Share of CPUs, in 1e-9 fractions
175
	NanoCPUs int64
176
	// Memory limit in bytes
177
	Memory int64
178
	// Disks (volumes), if applicable
179
	Disks []*Disk
180
	// Ports
181
	Ports []string
182
	// SkipInjectingConfig disables reading configuration from http server
183
	SkipInjectingConfig bool
184
	// DefaultBootOrder overrides default boot order "cn" (disk, then network boot).
185
	//
186
	// BootOrder can be forced to be "nc" (PXE boot) via the API in QEMU provisioner.
187
	DefaultBootOrder string
188

189
	// ExtraKernelArgs passes additional kernel args
190
	// to the initial boot from initramfs and vmlinuz.
191
	//
192
	// This doesn't apply to boots from ISO or from the disk image.
193
	ExtraKernelArgs *procfs.Cmdline
194

195
	// UUID allows to specify the UUID of the node (VMs only).
196
	//
197
	// If not specified, a random UUID will be generated.
198
	UUID *uuid.UUID
199

200
	// Testing features
201

202
	// BadRTC resets RTC to well known time in the past (QEMU provisioner).
203
	BadRTC bool
204

205
	// PXE-booted VMs
206
	PXEBooted        bool
207
	TFTPServer       string
208
	IPXEBootFilename string
209
}
210

211
// SiderolinkRequest describes a request for SideroLink agent.
212
type SiderolinkRequest struct {
213
	WireguardEndpoint string
214
	APIEndpoint       string
215
	SinkEndpoint      string
216
	LogEndpoint       string
217
	SiderolinkBind    []SiderolinkBind
218
}
219

220
// GetAddr returns the address for the given UUID.
221
func (sr *SiderolinkRequest) GetAddr(u *uuid.UUID) (netip.Addr, bool) {
222
	if idx := slices.IndexFunc(sr.SiderolinkBind, func(sb SiderolinkBind) bool { return sb.UUID == *u }); idx != -1 {
223
		return sr.SiderolinkBind[idx].Addr, true
224
	}
225

226
	return netip.Addr{}, false
227
}
228

229
// SiderolinkBind describes a pair of prebinded UUID->Addr for SideroLink agent.
230
type SiderolinkBind struct {
231
	UUID uuid.UUID
232
	Addr netip.Addr
233
}
234

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.