-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathlinodecluster_types.go
More file actions
286 lines (237 loc) · 11 KB
/
linodecluster_types.go
File metadata and controls
286 lines (237 loc) · 11 KB
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
/*
Copyright 2023 Akamai Technologies, Inc.
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 v1alpha2
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
)
const (
// ClusterFinalizer allows ReconcileLinodeCluster to clean up Linode resources associated
// with LinodeCluster before removing it from the apiserver.
ClusterFinalizer = "linodecluster.infrastructure.cluster.x-k8s.io"
ConditionPaused = "Paused"
)
// LinodeClusterSpec defines the desired state of LinodeCluster
type LinodeClusterSpec struct {
// region the LinodeCluster lives in.
// +kubebuilder:validation:MinLength=1
// +required
Region string `json:"region,omitempty"`
// controlPlaneEndpoint represents the endpoint used to communicate with the LinodeCluster control plane
// If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used.
// +optional
ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"`
// network encapsulates all things related to Linode network.
// +optional
Network NetworkSpec `json:"network"`
// vpcRef is a reference to a VPC object. This makes the Linodes use the specified VPC.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
VPCRef *corev1.ObjectReference `json:"vpcRef,omitempty"`
// vpcID is the ID of an existing VPC in Linode.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
VPCID *int `json:"vpcID,omitempty"`
// nodeBalancerFirewallRef is a reference to a NodeBalancer Firewall object. This makes the linode use the specified NodeBalancer Firewall.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
NodeBalancerFirewallRef *corev1.ObjectReference `json:"nodeBalancerFirewallRef,omitempty"`
// objectStore defines a supporting Object Storage bucket for cluster operations. This is currently used for
// bootstrapping (e.g. Cloud-init).
// +optional
ObjectStore *ObjectStore `json:"objectStore,omitempty"`
// credentialsRef is a reference to a Secret that contains the credentials to use for provisioning this cluster. If not
// supplied, then the credentials of the controller will be used.
// +optional
CredentialsRef *corev1.SecretReference `json:"credentialsRef,omitempty"`
}
// LinodeClusterStatus defines the observed state of LinodeCluster
type LinodeClusterStatus struct {
// conditions define the current service state of the LinodeCluster.
// +optional
// +listType=map
// +listMapKey=type
// +patchStrategy=merge
// +patchMergeKey=type
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
// ready denotes that the cluster (infrastructure) is ready.
// +optional
Ready bool `json:"ready"`
// failureReason will be set in the event that there is a terminal problem
// reconciling the LinodeCluster and will contain a succinct value suitable
// for machine interpretation.
// +optional
FailureReason *string `json:"failureReason,omitempty"`
// failureMessage will be set in the event that there is a terminal problem
// reconciling the LinodeCluster and will contain a more verbose string suitable
// for logging and human consumption.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=linodeclusters,scope=Namespaced,categories=cluster-api,shortName=lc
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this LinodeCluster belongs"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Cluster infrastructure is ready for Linode instances"
// +kubebuilder:printcolumn:name="Endpoint",type="string",JSONPath=".spec.ControlPlaneEndpoint",description="API Endpoint",priority=1
// +kubebuilder:storageversion
// LinodeCluster is the Schema for the linodeclusters API
type LinodeCluster struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`
// spec is the desired state of the LinodeCluster.
// +required
Spec LinodeClusterSpec `json:"spec,omitzero,omitempty"`
// status is the observed state of the LinodeCluster.
// +optional
Status LinodeClusterStatus `json:"status,omitempty"`
}
func (lc *LinodeCluster) SetCondition(cond metav1.Condition) {
if cond.LastTransitionTime.IsZero() {
cond.LastTransitionTime = metav1.Now()
}
for i := range lc.Status.Conditions {
if lc.Status.Conditions[i].Type == cond.Type {
lc.Status.Conditions[i] = cond
return
}
}
lc.Status.Conditions = append(lc.Status.Conditions, cond)
}
func (lc *LinodeCluster) GetCondition(condType string) *metav1.Condition {
for i := range lc.Status.Conditions {
if lc.Status.Conditions[i].Type == condType {
return &lc.Status.Conditions[i]
}
}
return nil
}
func (lc *LinodeCluster) IsPaused() bool {
for i := range lc.Status.Conditions {
if lc.Status.Conditions[i].Type == ConditionPaused {
return lc.Status.Conditions[i].Status == metav1.ConditionTrue
}
}
return false
}
// NetworkSpec encapsulates Linode networking resources.
type NetworkSpec struct {
// loadBalancerType is the type of load balancer to use, defaults to NodeBalancer if not otherwise set.
// +kubebuilder:validation:Enum=NodeBalancer;dns;external
// +kubebuilder:default=NodeBalancer
// +optional
LoadBalancerType string `json:"loadBalancerType,omitempty"`
// dnsProvider is the provider who manages the domain.
// Ignored if the LoadBalancerType is set to anything other than dns
// If not set, defaults linode dns
// +kubebuilder:validation:Enum=linode;akamai
// +optional
DNSProvider string `json:"dnsProvider,omitempty"`
// dnsRootDomain is the root domain used to create a DNS entry for the control-plane endpoint.
// Ignored if the LoadBalancerType is set to anything other than dns
// +optional
DNSRootDomain string `json:"dnsRootDomain,omitempty"`
// dnsUniqueIdentifier is the unique identifier for the DNS. This let clusters with the same name have unique
// DNS record
// Ignored if the LoadBalancerType is set to anything other than dns
// If not set, CAPL will create a unique identifier for you
// +optional
DNSUniqueIdentifier string `json:"dnsUniqueIdentifier,omitempty"`
// dnsTTLsec is the TTL for the domain record
// Ignored if the LoadBalancerType is set to anything other than dns
// If not set, defaults to 30
// +optional
DNSTTLSec int `json:"dnsTTLsec,omitempty"`
// dnsSubDomainOverride is used to override CAPL's construction of the controlplane endpoint
// If set, this will override the DNS subdomain from <clustername>-<uniqueid>.<rootdomain> to <overridevalue>.<rootdomain>
// +optional
DNSSubDomainOverride string `json:"dnsSubDomainOverride,omitempty"`
// apiserverLoadBalancerPort used by the api server. It must be valid ports range (1-65535).
// If omitted, default value is 6443.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +optional
ApiserverLoadBalancerPort int `json:"apiserverLoadBalancerPort,omitempty"`
// nodeBalancerID is the id of NodeBalancer.
// +optional
NodeBalancerID *int `json:"nodeBalancerID,omitempty"`
// nodeBalancerFirewallID is the id of NodeBalancer Firewall.
// +optional
NodeBalancerFirewallID *int `json:"nodeBalancerFirewallID,omitempty"`
// apiserverNodeBalancerConfigID is the config ID of api server NodeBalancer config.
// +optional
ApiserverNodeBalancerConfigID *int `json:"apiserverNodeBalancerConfigID,omitempty"`
// additionalPorts contains list of ports to be configured with NodeBalancer.
// +optional
// +listType=map
// +listMapKey=port
AdditionalPorts []LinodeNBPortConfig `json:"additionalPorts,omitempty"`
// subnetName is the name/label of the VPC subnet to be used by the cluster
// +optional
SubnetName string `json:"subnetName,omitempty"`
// useVlan provisions a cluster that uses VLANs instead of VPCs. IPAM is managed internally.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
UseVlan bool `json:"useVlan,omitempty"`
// nodeBalancerBackendIPv4Range is the subnet range we want to provide for creating nodebalancer in VPC.
// example: 10.10.10.0/30
// +optional
NodeBalancerBackendIPv4Range string `json:"nodeBalancerBackendIPv4Range,omitempty"`
// enableVPCBackends toggles VPC-scoped NodeBalancer and VPC backend IP usage.
// If set to false (default), the NodeBalancer will not be created in a VPC and
// backends will use Linode private IPs. If true, the NodeBalancer will be
// created in the configured VPC (when VPCRef or VPCID is set) and backends
// will use VPC IPs.
// +kubebuilder:default=false
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +optional
EnableVPCBackends bool `json:"enableVPCBackends,omitempty"`
}
type LinodeNBPortConfig struct {
// port configured on the NodeBalancer. It must be valid port range (1-65535).
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +required
Port int `json:"port,omitempty"`
// nodeBalancerConfigID is the config ID of port's NodeBalancer config.
// +optional
NodeBalancerConfigID *int `json:"nodeBalancerConfigID,omitempty"`
}
// ObjectStore defines a supporting Object Storage bucket for cluster operations. This is currently used for
// bootstrapping (e.g. Cloud-init).
type ObjectStore struct {
// presignedURLDuration defines the duration for which presigned URLs are valid.
//
// This is used to generate presigned URLs for S3 Bucket objects, which are used by
// control-plane and worker nodes to fetch bootstrap data.
// +optional
PresignedURLDuration *metav1.Duration `json:"presignedURLDuration,omitempty"`
// credentialsRef is a reference to a Secret that contains the credentials to use for accessing the Cluster Object Store.
// +optional
CredentialsRef corev1.SecretReference `json:"credentialsRef,omitempty"`
}
// +kubebuilder:object:root=true
// LinodeClusterList contains a list of LinodeCluster
type LinodeClusterList struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
metav1.ListMeta `json:"metadata,omitempty"`
// items is a list of LinodeCluster.
Items []LinodeCluster `json:"items"`
}
func init() {
SchemeBuilder.Register(&LinodeCluster{}, &LinodeClusterList{})
}