-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathcluster_types.go
637 lines (526 loc) · 23.9 KB
/
cluster_types.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1beta1
import (
"fmt"
"net"
"strings"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
capierrors "sigs.k8s.io/cluster-api/errors"
)
const (
// ClusterFinalizer is the finalizer used by the cluster controller to
// cleanup the cluster resources when a Cluster is being deleted.
ClusterFinalizer = "cluster.cluster.x-k8s.io"
// ClusterKind represents the Kind of Cluster.
ClusterKind = "Cluster"
)
// ANCHOR: ClusterSpec
// ClusterSpec defines the desired state of Cluster.
type ClusterSpec struct {
// Paused can be used to prevent controllers from processing the Cluster and all its associated objects.
// +optional
Paused bool `json:"paused,omitempty"`
// Cluster network configuration.
// +optional
ClusterNetwork *ClusterNetwork `json:"clusterNetwork,omitempty"`
// ControlPlaneEndpoint represents the endpoint used to communicate with the control plane.
// +optional
ControlPlaneEndpoint APIEndpoint `json:"controlPlaneEndpoint,omitempty"`
// ControlPlaneRef is an optional reference to a provider-specific resource that holds
// the details for provisioning the Control Plane for a Cluster.
// +optional
ControlPlaneRef *corev1.ObjectReference `json:"controlPlaneRef,omitempty"`
// InfrastructureRef is a reference to a provider-specific resource that holds the details
// for provisioning infrastructure for a cluster in said provider.
// +optional
InfrastructureRef *corev1.ObjectReference `json:"infrastructureRef,omitempty"`
// This encapsulates the topology for the cluster.
// NOTE: It is required to enable the ClusterTopology
// feature gate flag to activate managed topologies support;
// this feature is highly experimental, and parts of it might still be not implemented.
// +optional
Topology *Topology `json:"topology,omitempty"`
}
// Topology encapsulates the information of the managed resources.
type Topology struct {
// The name of the ClusterClass object to create the topology.
Class string `json:"class"`
// The Kubernetes version of the cluster.
Version string `json:"version"`
// RolloutAfter performs a rollout of the entire cluster one component at a time,
// control plane first and then machine deployments.
// +optional
// Deprecated: This field has no function and is going to be removed in the next apiVersion.
RolloutAfter *metav1.Time `json:"rolloutAfter,omitempty"`
// ControlPlane describes the cluster control plane.
// +optional
ControlPlane ControlPlaneTopology `json:"controlPlane,omitempty"`
// Workers encapsulates the different constructs that form the worker nodes
// for the cluster.
// +optional
Workers *WorkersTopology `json:"workers,omitempty"`
// Variables can be used to customize the Cluster through
// patches. They must comply to the corresponding
// VariableClasses defined in the ClusterClass.
// +optional
Variables []ClusterVariable `json:"variables,omitempty"`
}
// ControlPlaneTopology specifies the parameters for the control plane nodes in the cluster.
type ControlPlaneTopology struct {
// Metadata is the metadata applied to the ControlPlane and the Machines of the ControlPlane
// if the ControlPlaneTemplate referenced by the ClusterClass is machine based. If not, it
// is applied only to the ControlPlane.
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
// +optional
Metadata ObjectMeta `json:"metadata,omitempty"`
// Replicas is the number of control plane nodes.
// If the value is nil, the ControlPlane object is created without the number of Replicas
// and it's assumed that the control plane controller does not implement support for this field.
// When specified against a control plane provider that lacks support for this field, this value will be ignored.
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// MachineHealthCheck allows to enable, disable and override
// the MachineHealthCheck configuration in the ClusterClass for this control plane.
// +optional
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
// +optional
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
// +optional
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
// hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely.
// Defaults to 10 seconds.
// +optional
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
}
// WorkersTopology represents the different sets of worker nodes in the cluster.
type WorkersTopology struct {
// MachineDeployments is a list of machine deployments in the cluster.
// +optional
MachineDeployments []MachineDeploymentTopology `json:"machineDeployments,omitempty"`
// MachinePools is a list of machine pools in the cluster.
// +optional
MachinePools []MachinePoolTopology `json:"machinePools,omitempty"`
}
// MachineDeploymentTopology specifies the different parameters for a set of worker nodes in the topology.
// This set of nodes is managed by a MachineDeployment object whose lifecycle is managed by the Cluster controller.
type MachineDeploymentTopology struct {
// Metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment.
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
// +optional
Metadata ObjectMeta `json:"metadata,omitempty"`
// Class is the name of the MachineDeploymentClass used to create the set of worker nodes.
// This should match one of the deployment classes defined in the ClusterClass object
// mentioned in the `Cluster.Spec.Class` field.
Class string `json:"class"`
// Name is the unique identifier for this MachineDeploymentTopology.
// The value is used with other unique identifiers to create a MachineDeployment's Name
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
// the values are hashed together.
Name string `json:"name"`
// FailureDomain is the failure domain the machines will be created in.
// Must match a key in the FailureDomains map stored on the cluster object.
// +optional
FailureDomain *string `json:"failureDomain,omitempty"`
// Replicas is the number of worker nodes belonging to this set.
// If the value is nil, the MachineDeployment is created without the number of Replicas (defaulting to 1)
// and it's assumed that an external entity (like cluster autoscaler) is responsible for the management
// of this value.
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// MachineHealthCheck allows to enable, disable and override
// the MachineHealthCheck configuration in the ClusterClass for this MachineDeployment.
// +optional
MachineHealthCheck *MachineHealthCheckTopology `json:"machineHealthCheck,omitempty"`
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
// +optional
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
// +optional
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the Machine
// hosts after the Machine is marked for deletion. A duration of 0 will retry deletion indefinitely.
// Defaults to 10 seconds.
// +optional
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
// Minimum number of seconds for which a newly created machine should
// be ready.
// Defaults to 0 (machine will be considered available as soon as it
// is ready)
// +optional
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
// The deployment strategy to use to replace existing machines with
// new ones.
// +optional
Strategy *MachineDeploymentStrategy `json:"strategy,omitempty"`
// Variables can be used to customize the MachineDeployment through patches.
// +optional
Variables *MachineDeploymentVariables `json:"variables,omitempty"`
}
// MachineHealthCheckTopology defines a MachineHealthCheck for a group of machines.
type MachineHealthCheckTopology struct {
// Enable controls if a MachineHealthCheck should be created for the target machines.
//
// If false: No MachineHealthCheck will be created.
//
// If not set(default): A MachineHealthCheck will be created if it is defined here or
// in the associated ClusterClass. If no MachineHealthCheck is defined then none will be created.
//
// If true: A MachineHealthCheck is guaranteed to be created. Cluster validation will
// block if `enable` is true and no MachineHealthCheck definition is available.
// +optional
Enable *bool `json:"enable,omitempty"`
// MachineHealthCheckClass defines a MachineHealthCheck for a group of machines.
// If specified (any field is set), it entirely overrides the MachineHealthCheckClass defined in ClusterClass.
MachineHealthCheckClass `json:",inline"`
}
// MachinePoolTopology specifies the different parameters for a pool of worker nodes in the topology.
// This pool of nodes is managed by a MachinePool object whose lifecycle is managed by the Cluster controller.
type MachinePoolTopology struct {
// Metadata is the metadata applied to the MachinePool.
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
// +optional
Metadata ObjectMeta `json:"metadata,omitempty"`
// Class is the name of the MachinePoolClass used to create the pool of worker nodes.
// This should match one of the deployment classes defined in the ClusterClass object
// mentioned in the `Cluster.Spec.Class` field.
Class string `json:"class"`
// Name is the unique identifier for this MachinePoolTopology.
// The value is used with other unique identifiers to create a MachinePool's Name
// (e.g. cluster's name, etc). In case the name is greater than the allowed maximum length,
// the values are hashed together.
Name string `json:"name"`
// FailureDomains is the list of failure domains the machine pool will be created in.
// Must match a key in the FailureDomains map stored on the cluster object.
// +optional
FailureDomains []string `json:"failureDomains,omitempty"`
// NodeDrainTimeout is the total amount of time that the controller will spend on draining a node.
// The default value is 0, meaning that the node can be drained without any time limitations.
// NOTE: NodeDrainTimeout is different from `kubectl drain --timeout`
// +optional
NodeDrainTimeout *metav1.Duration `json:"nodeDrainTimeout,omitempty"`
// NodeVolumeDetachTimeout is the total amount of time that the controller will spend on waiting for all volumes
// to be detached. The default value is 0, meaning that the volumes can be detached without any time limitations.
// +optional
NodeVolumeDetachTimeout *metav1.Duration `json:"nodeVolumeDetachTimeout,omitempty"`
// NodeDeletionTimeout defines how long the controller will attempt to delete the Node that the MachinePool
// hosts after the MachinePool is marked for deletion. A duration of 0 will retry deletion indefinitely.
// Defaults to 10 seconds.
// +optional
NodeDeletionTimeout *metav1.Duration `json:"nodeDeletionTimeout,omitempty"`
// Minimum number of seconds for which a newly created machine pool should
// be ready.
// Defaults to 0 (machine will be considered available as soon as it
// is ready)
// +optional
MinReadySeconds *int32 `json:"minReadySeconds,omitempty"`
// Replicas is the number of nodes belonging to this pool.
// If the value is nil, the MachinePool is created without the number of Replicas (defaulting to 1)
// and it's assumed that an external entity (like cluster autoscaler) is responsible for the management
// of this value.
// +optional
Replicas *int32 `json:"replicas,omitempty"`
// Variables can be used to customize the MachinePool through patches.
// +optional
Variables *MachinePoolVariables `json:"variables,omitempty"`
}
// ClusterVariable can be used to customize the Cluster through patches. Each ClusterVariable is associated with a
// Variable definition in the ClusterClass `status` variables.
type ClusterVariable struct {
// Name of the variable.
Name string `json:"name"`
// DefinitionFrom specifies where the definition of this Variable is from. DefinitionFrom is `inline` when the
// definition is from the ClusterClass `.spec.variables` or the name of a patch defined in the ClusterClass
// `.spec.patches` where the patch is external and provides external variables.
// This field is mandatory if the variable has `DefinitionsConflict: true` in ClusterClass `status.variables[]`
// +optional
DefinitionFrom string `json:"definitionFrom,omitempty"`
// Value of the variable.
// Note: the value will be validated against the schema of the corresponding ClusterClassVariable
// from the ClusterClass.
// Note: We have to use apiextensionsv1.JSON instead of a custom JSON type, because controller-tools has a
// hard-coded schema for apiextensionsv1.JSON which cannot be produced by another type via controller-tools,
// i.e. it is not possible to have no type field.
// Ref: https://github.com/kubernetes-sigs/controller-tools/blob/d0e03a142d0ecdd5491593e941ee1d6b5d91dba6/pkg/crd/known_types.go#L106-L111
Value apiextensionsv1.JSON `json:"value"`
}
// MachineDeploymentVariables can be used to provide variables for a specific MachineDeployment.
type MachineDeploymentVariables struct {
// Overrides can be used to override Cluster level variables.
// +optional
Overrides []ClusterVariable `json:"overrides,omitempty"`
}
// MachinePoolVariables can be used to provide variables for a specific MachinePool.
type MachinePoolVariables struct {
// Overrides can be used to override Cluster level variables.
// +optional
Overrides []ClusterVariable `json:"overrides,omitempty"`
}
// ANCHOR_END: ClusterSpec
// ANCHOR: ClusterNetwork
// ClusterNetwork specifies the different networking
// parameters for a cluster.
type ClusterNetwork struct {
// APIServerPort specifies the port the API Server should bind to.
// Defaults to 6443.
// +optional
APIServerPort *int32 `json:"apiServerPort,omitempty"`
// The network ranges from which service VIPs are allocated.
// +optional
Services *NetworkRanges `json:"services,omitempty"`
// The network ranges from which Pod networks are allocated.
// +optional
Pods *NetworkRanges `json:"pods,omitempty"`
// Domain name for services.
// +optional
ServiceDomain string `json:"serviceDomain,omitempty"`
}
// ANCHOR_END: ClusterNetwork
// ANCHOR: NetworkRanges
// NetworkRanges represents ranges of network addresses.
type NetworkRanges struct {
CIDRBlocks []string `json:"cidrBlocks"`
}
func (n NetworkRanges) String() string {
if len(n.CIDRBlocks) == 0 {
return ""
}
return strings.Join(n.CIDRBlocks, ",")
}
// ANCHOR_END: NetworkRanges
// ANCHOR: ClusterStatus
// ClusterStatus defines the observed state of Cluster.
type ClusterStatus struct {
// FailureDomains is a slice of failure domain objects synced from the infrastructure provider.
// +optional
FailureDomains FailureDomains `json:"failureDomains,omitempty"`
// FailureReason indicates that there is a fatal problem reconciling the
// state, and will be set to a token value suitable for
// programmatic interpretation.
// +optional
FailureReason *capierrors.ClusterStatusError `json:"failureReason,omitempty"`
// FailureMessage indicates that there is a fatal problem reconciling the
// state, and will be set to a descriptive error message.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
// Phase represents the current phase of cluster actuation.
// E.g. Pending, Running, Terminating, Failed etc.
// +optional
Phase string `json:"phase,omitempty"`
// InfrastructureReady is the state of the infrastructure provider.
// +optional
InfrastructureReady bool `json:"infrastructureReady"`
// ControlPlaneReady defines if the control plane is ready.
// +optional
ControlPlaneReady bool `json:"controlPlaneReady"`
// Conditions defines current service state of the cluster.
// +optional
Conditions Conditions `json:"conditions,omitempty"`
// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}
// ANCHOR_END: ClusterStatus
// SetTypedPhase sets the Phase field to the string representation of ClusterPhase.
func (c *ClusterStatus) SetTypedPhase(p ClusterPhase) {
c.Phase = string(p)
}
// GetTypedPhase attempts to parse the Phase field and return
// the typed ClusterPhase representation as described in `machine_phase_types.go`.
func (c *ClusterStatus) GetTypedPhase() ClusterPhase {
switch phase := ClusterPhase(c.Phase); phase {
case
ClusterPhasePending,
ClusterPhaseProvisioning,
ClusterPhaseProvisioned,
ClusterPhaseDeleting,
ClusterPhaseFailed:
return phase
default:
return ClusterPhaseUnknown
}
}
// ANCHOR: APIEndpoint
// APIEndpoint represents a reachable Kubernetes API endpoint.
type APIEndpoint struct {
// The hostname on which the API server is serving.
Host string `json:"host"`
// The port on which the API server is serving.
Port int32 `json:"port"`
}
// IsZero returns true if both host and port are zero values.
func (v APIEndpoint) IsZero() bool {
return v.Host == "" && v.Port == 0
}
// IsValid returns true if both host and port are non-zero values.
func (v APIEndpoint) IsValid() bool {
return v.Host != "" && v.Port != 0
}
// String returns a formatted version HOST:PORT of this APIEndpoint.
func (v APIEndpoint) String() string {
return net.JoinHostPort(v.Host, fmt.Sprintf("%d", v.Port))
}
// ANCHOR_END: APIEndpoint
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=clusters,shortName=cl,scope=Namespaced,categories=cluster-api
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase",description="Cluster status such as Pending/Provisioning/Provisioned/Deleting/Failed"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Cluster"
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.topology.version",description="Kubernetes version associated with this Cluster"
// Cluster is the Schema for the clusters API.
type Cluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSpec `json:"spec,omitempty"`
Status ClusterStatus `json:"status,omitempty"`
}
// GetConditions returns the set of conditions for this object.
func (c *Cluster) GetConditions() Conditions {
return c.Status.Conditions
}
// SetConditions sets the conditions on this object.
func (c *Cluster) SetConditions(conditions Conditions) {
c.Status.Conditions = conditions
}
// GetIPFamily returns a ClusterIPFamily from the configuration provided.
// Note: IPFamily is not a concept in Kubernetes. It was originally introduced in CAPI for CAPD.
// IPFamily may be dropped in a future release. More details at https://github.com/kubernetes-sigs/cluster-api/issues/7521
func (c *Cluster) GetIPFamily() (ClusterIPFamily, error) {
var podCIDRs, serviceCIDRs []string
if c.Spec.ClusterNetwork != nil {
if c.Spec.ClusterNetwork.Pods != nil {
podCIDRs = c.Spec.ClusterNetwork.Pods.CIDRBlocks
}
if c.Spec.ClusterNetwork.Services != nil {
serviceCIDRs = c.Spec.ClusterNetwork.Services.CIDRBlocks
}
}
if len(podCIDRs) == 0 && len(serviceCIDRs) == 0 {
return IPv4IPFamily, nil
}
podsIPFamily, err := ipFamilyForCIDRStrings(podCIDRs)
if err != nil {
return InvalidIPFamily, fmt.Errorf("pods: %s", err)
}
if len(serviceCIDRs) == 0 {
return podsIPFamily, nil
}
servicesIPFamily, err := ipFamilyForCIDRStrings(serviceCIDRs)
if err != nil {
return InvalidIPFamily, fmt.Errorf("services: %s", err)
}
if len(podCIDRs) == 0 {
return servicesIPFamily, nil
}
if podsIPFamily == DualStackIPFamily {
return DualStackIPFamily, nil
} else if podsIPFamily != servicesIPFamily {
return InvalidIPFamily, errors.New("pods and services IP family mismatch")
}
return podsIPFamily, nil
}
func ipFamilyForCIDRStrings(cidrs []string) (ClusterIPFamily, error) {
if len(cidrs) > 2 {
return InvalidIPFamily, errors.New("too many CIDRs specified")
}
var foundIPv4 bool
var foundIPv6 bool
for _, cidr := range cidrs {
ip, _, err := net.ParseCIDR(cidr)
if err != nil {
return InvalidIPFamily, fmt.Errorf("could not parse CIDR: %s", err)
}
if ip.To4() != nil {
foundIPv4 = true
} else {
foundIPv6 = true
}
}
switch {
case foundIPv4 && foundIPv6:
return DualStackIPFamily, nil
case foundIPv4:
return IPv4IPFamily, nil
case foundIPv6:
return IPv6IPFamily, nil
default:
return InvalidIPFamily, nil
}
}
// ClusterIPFamily defines the types of supported IP families.
type ClusterIPFamily int
// Define the ClusterIPFamily constants.
const (
InvalidIPFamily ClusterIPFamily = iota
IPv4IPFamily
IPv6IPFamily
DualStackIPFamily
)
func (f ClusterIPFamily) String() string {
return [...]string{"InvalidIPFamily", "IPv4IPFamily", "IPv6IPFamily", "DualStackIPFamily"}[f]
}
// +kubebuilder:object:root=true
// ClusterList contains a list of Cluster.
type ClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Cluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}
// FailureDomains is a slice of FailureDomains.
type FailureDomains map[string]FailureDomainSpec
// FilterControlPlane returns a FailureDomain slice containing only the domains suitable to be used
// for control plane nodes.
func (in FailureDomains) FilterControlPlane() FailureDomains {
res := make(FailureDomains)
for id, spec := range in {
if spec.ControlPlane {
res[id] = spec
}
}
return res
}
// GetIDs returns a slice containing the ids for failure domains.
func (in FailureDomains) GetIDs() []*string {
ids := make([]*string, 0, len(in))
for id := range in {
ids = append(ids, pointer.String(id))
}
return ids
}
// FailureDomainSpec is the Schema for Cluster API failure domains.
// It allows controllers to understand how many failure domains a cluster can optionally span across.
type FailureDomainSpec struct {
// ControlPlane determines if this failure domain is suitable for use by control plane machines.
// +optional
ControlPlane bool `json:"controlPlane,omitempty"`
// Attributes is a free form map of attributes an infrastructure provider might use or require.
// +optional
Attributes map[string]string `json:"attributes,omitempty"`
}