-
Notifications
You must be signed in to change notification settings - Fork 457
/
options.go
327 lines (254 loc) · 8.04 KB
/
options.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
// 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 generate
import (
"github.com/siderolabs/gen/optional"
"github.com/siderolabs/go-pointer"
"github.com/siderolabs/talos/pkg/machinery/config"
"github.com/siderolabs/talos/pkg/machinery/config/generate/secrets"
v1alpha1 "github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1"
"github.com/siderolabs/talos/pkg/machinery/role"
)
// Option controls generate options specific to input generation.
type Option func(o *Options) error
// WithEndpointList specifies endpoints to use when accessing Talos cluster.
func WithEndpointList(endpoints []string) Option {
return func(o *Options) error {
o.EndpointList = endpoints
return nil
}
}
// WithLocalAPIServerPort specifies the local API server port for the cluster.
func WithLocalAPIServerPort(port int) Option {
return func(o *Options) error {
o.LocalAPIServerPort = port
return nil
}
}
// WithKubePrismPort specifies the KubePrism port.
//
// If 0, load balancer is disabled.
// If not set, defaults to enabled with Talos 1.6+.
func WithKubePrismPort(port int) Option {
return func(o *Options) error {
o.KubePrismPort = optional.Some(port)
return nil
}
}
// WithInstallDisk specifies install disk to use in Talos cluster.
func WithInstallDisk(disk string) Option {
return func(o *Options) error {
o.InstallDisk = disk
return nil
}
}
// WithAdditionalSubjectAltNames specifies additional SANs.
func WithAdditionalSubjectAltNames(sans []string) Option {
return func(o *Options) error {
o.AdditionalSubjectAltNames = append(o.AdditionalSubjectAltNames, sans...)
return nil
}
}
// WithInstallImage specifies install container image to use in Talos cluster.
func WithInstallImage(imageRef string) Option {
return func(o *Options) error {
o.InstallImage = imageRef
return nil
}
}
// WithInstallExtraKernelArgs specifies extra kernel arguments to pass to the installer.
func WithInstallExtraKernelArgs(args []string) Option {
return func(o *Options) error {
o.InstallExtraKernelArgs = append(o.InstallExtraKernelArgs, args...)
return nil
}
}
// WithNetworkOptions adds network config generation option.
func WithNetworkOptions(opts ...v1alpha1.NetworkConfigOption) Option {
return func(o *Options) error {
o.NetworkConfigOptions = append(o.NetworkConfigOptions, opts...)
return nil
}
}
// WithRegistryMirror configures registry mirror endpoint(s).
func WithRegistryMirror(host string, endpoints ...string) Option {
return func(o *Options) error {
if o.RegistryMirrors == nil {
o.RegistryMirrors = make(map[string]*v1alpha1.RegistryMirrorConfig)
}
o.RegistryMirrors[host] = &v1alpha1.RegistryMirrorConfig{MirrorEndpoints: endpoints}
return nil
}
}
// WithRegistryCACert specifies the certificate of the certificate authority which signed certificate of the registry.
func WithRegistryCACert(host, cacert string) Option {
return func(o *Options) error {
if o.RegistryConfig == nil {
o.RegistryConfig = make(map[string]*v1alpha1.RegistryConfig)
}
if _, ok := o.RegistryConfig[host]; !ok {
o.RegistryConfig[host] = &v1alpha1.RegistryConfig{}
}
if o.RegistryConfig[host].RegistryTLS == nil {
o.RegistryConfig[host].RegistryTLS = &v1alpha1.RegistryTLSConfig{}
}
o.RegistryConfig[host].RegistryTLS.TLSCA = v1alpha1.Base64Bytes(cacert)
return nil
}
}
// WithRegistryInsecureSkipVerify marks registry host to skip TLS verification.
func WithRegistryInsecureSkipVerify(host string) Option {
return func(o *Options) error {
if o.RegistryConfig == nil {
o.RegistryConfig = make(map[string]*v1alpha1.RegistryConfig)
}
if _, ok := o.RegistryConfig[host]; !ok {
o.RegistryConfig[host] = &v1alpha1.RegistryConfig{}
}
if o.RegistryConfig[host].RegistryTLS == nil {
o.RegistryConfig[host].RegistryTLS = &v1alpha1.RegistryTLSConfig{}
}
o.RegistryConfig[host].RegistryTLS.TLSInsecureSkipVerify = pointer.To(true)
return nil
}
}
// WithDNSDomain specifies domain name to use in Talos cluster.
func WithDNSDomain(dnsDomain string) Option {
return func(o *Options) error {
o.DNSDomain = dnsDomain
return nil
}
}
// WithDebug enables verbose logging to console for all services.
func WithDebug(enable bool) Option {
return func(o *Options) error {
o.Debug = enable
return nil
}
}
// WithPersist enables persistence of machine config across reboots.
func WithPersist(enable bool) Option {
return func(o *Options) error {
o.Persist = enable
return nil
}
}
// WithClusterCNIConfig specifies custom cluster CNI config.
func WithClusterCNIConfig(config *v1alpha1.CNIConfig) Option {
return func(o *Options) error {
o.CNIConfig = config
return nil
}
}
// WithUserDisks generates user partitions config.
func WithUserDisks(disks []*v1alpha1.MachineDisk) Option {
return func(o *Options) error {
o.MachineDisks = disks
return nil
}
}
// WithAllowSchedulingOnControlPlanes specifies AllowSchedulingOnControlPlane flag.
func WithAllowSchedulingOnControlPlanes(enabled bool) Option {
return func(o *Options) error {
o.AllowSchedulingOnControlPlanes = enabled
return nil
}
}
// WithVersionContract specifies version contract to use when generating.
func WithVersionContract(versionContract *config.VersionContract) Option {
return func(o *Options) error {
o.VersionContract = versionContract
return nil
}
}
// WithSystemDiskEncryption specifies encryption settings for the system disk partitions.
func WithSystemDiskEncryption(cfg *v1alpha1.SystemDiskEncryptionConfig) Option {
return func(o *Options) error {
o.SystemDiskEncryptionConfig = cfg
return nil
}
}
// WithRoles specifies user roles.
func WithRoles(roles role.Set) Option {
return func(o *Options) error {
o.Roles = roles
return nil
}
}
// WithClusterDiscovery enables cluster discovery feature.
func WithClusterDiscovery(enabled bool) Option {
return func(o *Options) error {
o.DiscoveryEnabled = pointer.To(enabled)
return nil
}
}
// WithSysctls merges list of sysctls with new values.
func WithSysctls(params map[string]string) Option {
return func(o *Options) error {
if o.Sysctls == nil {
o.Sysctls = make(map[string]string)
}
for k, v := range params {
o.Sysctls[k] = v
}
return nil
}
}
// WithSecretsBundle specifies custom secrets bundle.
func WithSecretsBundle(bundle *secrets.Bundle) Option {
return func(o *Options) error {
o.SecretsBundle = bundle
return nil
}
}
// WithHostDNSForwardKubeDNSToHost specifies whether to forward kube-dns to host.
func WithHostDNSForwardKubeDNSToHost(forward bool) Option {
return func(o *Options) error {
o.HostDNSForwardKubeDNSToHost = optional.Some(forward)
return nil
}
}
// Options describes generate parameters.
type Options struct {
VersionContract *config.VersionContract
// Custom secrets bundle.
SecretsBundle *secrets.Bundle
// Base settings.
Debug bool
Persist bool
// Machine settings: install.
InstallDisk string
InstallImage string
InstallExtraKernelArgs []string
// Machine disks.
MachineDisks []*v1alpha1.MachineDisk
SystemDiskEncryptionConfig *v1alpha1.SystemDiskEncryptionConfig
// Machine network settings.
NetworkConfigOptions []v1alpha1.NetworkConfigOption
// Machine sysctls.
Sysctls map[string]string
// Machine registries.
RegistryMirrors map[string]*v1alpha1.RegistryMirrorConfig
RegistryConfig map[string]*v1alpha1.RegistryConfig
// Cluster settings.
DNSDomain string
CNIConfig *v1alpha1.CNIConfig
AllowSchedulingOnControlPlanes bool
LocalAPIServerPort int
AdditionalSubjectAltNames []string
DiscoveryEnabled *bool
KubePrismPort optional.Optional[int]
HostDNSForwardKubeDNSToHost optional.Optional[bool]
// Client options.
Roles role.Set
EndpointList []string
}
// DefaultOptions returns default options.
func DefaultOptions() Options {
return Options{
DNSDomain: "cluster.local",
Persist: true,
Roles: role.MakeSet(role.Admin),
}
}