-
Notifications
You must be signed in to change notification settings - Fork 571
/
awsmachine_types.go
422 lines (351 loc) · 18.5 KB
/
awsmachine_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
/*
Copyright 2022 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 v1beta2
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/cluster-api/errors"
)
const (
// MachineFinalizer allows ReconcileAWSMachine to clean up AWS resources associated with AWSMachine before
// removing it from the apiserver.
MachineFinalizer = "awsmachine.infrastructure.cluster.x-k8s.io"
// DefaultIgnitionVersion represents default Ignition version generated for machine userdata.
DefaultIgnitionVersion = "2.3"
)
// SecretBackend defines variants for backend secret storage.
type SecretBackend string
var (
// SecretBackendSSMParameterStore defines AWS Systems Manager Parameter Store as the secret backend.
SecretBackendSSMParameterStore = SecretBackend("ssm-parameter-store")
// SecretBackendSecretsManager defines AWS Secrets Manager as the secret backend.
SecretBackendSecretsManager = SecretBackend("secrets-manager")
)
// IgnitionStorageTypeOption defines the different storage types for Ignition.
type IgnitionStorageTypeOption string
const (
// IgnitionStorageTypeOptionClusterObjectStore means the chosen Ignition storage type is ClusterObjectStore.
IgnitionStorageTypeOptionClusterObjectStore = IgnitionStorageTypeOption("ClusterObjectStore")
// IgnitionStorageTypeOptionUnencryptedUserData means the chosen Ignition storage type is UnencryptedUserData.
IgnitionStorageTypeOptionUnencryptedUserData = IgnitionStorageTypeOption("UnencryptedUserData")
)
// AWSMachineSpec defines the desired state of an Amazon EC2 instance.
type AWSMachineSpec struct {
// ProviderID is the unique identifier as specified by the cloud provider.
ProviderID *string `json:"providerID,omitempty"`
// InstanceID is the EC2 instance ID for this machine.
InstanceID *string `json:"instanceID,omitempty"`
// InstanceMetadataOptions is the metadata options for the EC2 instance.
// +optional
InstanceMetadataOptions *InstanceMetadataOptions `json:"instanceMetadataOptions,omitempty"`
// AMI is the reference to the AMI from which to create the machine instance.
AMI AMIReference `json:"ami,omitempty"`
// ImageLookupFormat is the AMI naming format to look up the image for this
// machine It will be ignored if an explicit AMI is set. Supports
// substitutions for {{.BaseOS}} and {{.K8sVersion}} with the base OS and
// kubernetes version, respectively. The BaseOS will be the value in
// ImageLookupBaseOS or ubuntu (the default), and the kubernetes version as
// defined by the packages produced by kubernetes/release without v as a
// prefix: 1.13.0, 1.12.5-mybuild.1, or 1.17.3. For example, the default
// image format of capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* will end up
// searching for AMIs that match the pattern capa-ami-ubuntu-?1.18.0-* for a
// Machine that is targeting kubernetes v1.18.0 and the ubuntu base OS. See
// also: https://golang.org/pkg/text/template/
// +optional
ImageLookupFormat string `json:"imageLookupFormat,omitempty"`
// ImageLookupOrg is the AWS Organization ID to use for image lookup if AMI is not set.
ImageLookupOrg string `json:"imageLookupOrg,omitempty"`
// ImageLookupBaseOS is the name of the base operating system to use for
// image lookup the AMI is not set.
ImageLookupBaseOS string `json:"imageLookupBaseOS,omitempty"`
// InstanceType is the type of instance to create. Example: m4.xlarge
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength:=2
InstanceType string `json:"instanceType"`
// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
// AWS provider. If both the AWSCluster and the AWSMachine specify the same tag name with different values, the
// AWSMachine's value takes precedence.
// +optional
AdditionalTags Tags `json:"additionalTags,omitempty"`
// IAMInstanceProfile is a name of an IAM instance profile to assign to the instance
// +optional
IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"`
// PublicIP specifies whether the instance should get a public IP.
// Precedence for this setting is as follows:
// 1. This field if set
// 2. Cluster/flavor setting
// 3. Subnet default
// +optional
PublicIP *bool `json:"publicIP,omitempty"`
// ElasticIPPool is the configuration to allocate Public IPv4 address (Elastic IP/EIP) from user-defined pool.
//
// +optional
ElasticIPPool *ElasticIPPool `json:"elasticIpPool,omitempty"`
// AdditionalSecurityGroups is an array of references to security groups that should be applied to the
// instance. These security groups would be set in addition to any security groups defined
// at the cluster level or in the actuator. It is possible to specify either IDs of Filters. Using Filters
// will cause additional requests to AWS API and if tags change the attached security groups might change too.
// +optional
AdditionalSecurityGroups []AWSResourceReference `json:"additionalSecurityGroups,omitempty"`
// Subnet is a reference to the subnet to use for this instance. If not specified,
// the cluster subnet will be used.
// +optional
Subnet *AWSResourceReference `json:"subnet,omitempty"`
// SecurityGroupOverrides is an optional set of security groups to use for the node.
// This is optional - if not provided security groups from the cluster will be used.
// +optional
SecurityGroupOverrides map[SecurityGroupRole]string `json:"securityGroupOverrides,omitempty"`
// SSHKeyName is the name of the ssh key to attach to the instance. Valid values are empty string (do not use SSH keys), a valid SSH key name, or omitted (use the default SSH key name)
// +optional
SSHKeyName *string `json:"sshKeyName,omitempty"`
// RootVolume encapsulates the configuration options for the root volume
// +optional
RootVolume *Volume `json:"rootVolume,omitempty"`
// Configuration options for the non root storage volumes.
// +optional
NonRootVolumes []Volume `json:"nonRootVolumes,omitempty"`
// NetworkInterfaces is a list of ENIs to associate with the instance.
// A maximum of 2 may be specified.
// +optional
// +kubebuilder:validation:MaxItems=2
NetworkInterfaces []string `json:"networkInterfaces,omitempty"`
// UncompressedUserData specify whether the user data is gzip-compressed before it is sent to ec2 instance.
// cloud-init has built-in support for gzip-compressed user data
// user data stored in aws secret manager is always gzip-compressed.
//
// +optional
UncompressedUserData *bool `json:"uncompressedUserData,omitempty"`
// CloudInit defines options related to the bootstrapping systems where
// CloudInit is used.
// +optional
CloudInit CloudInit `json:"cloudInit,omitempty"`
// Ignition defined options related to the bootstrapping systems where Ignition is used.
// +optional
Ignition *Ignition `json:"ignition,omitempty"`
// SpotMarketOptions allows users to configure instances to be run using AWS Spot instances.
// +optional
SpotMarketOptions *SpotMarketOptions `json:"spotMarketOptions,omitempty"`
// PlacementGroupName specifies the name of the placement group in which to launch the instance.
// +optional
PlacementGroupName string `json:"placementGroupName,omitempty"`
// PlacementGroupPartition is the partition number within the placement group in which to launch the instance.
// This value is only valid if the placement group, referred in `PlacementGroupName`, was created with
// strategy set to partition.
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:validation:Maximum:=7
// +optional
PlacementGroupPartition int64 `json:"placementGroupPartition,omitempty"`
// Tenancy indicates if instance should run on shared or single-tenant hardware.
// +optional
// +kubebuilder:validation:Enum:=default;dedicated;host
Tenancy string `json:"tenancy,omitempty"`
// PrivateDNSName is the options for the instance hostname.
// +optional
PrivateDNSName *PrivateDNSName `json:"privateDnsName,omitempty"`
// CapacityReservationID specifies the target Capacity Reservation into which the instance should be launched.
// +optional
CapacityReservationID *string `json:"capacityReservationId,omitempty"`
}
// CloudInit defines options related to the bootstrapping systems where
// CloudInit is used.
type CloudInit struct {
// InsecureSkipSecretsManager, when set to true will not use AWS Secrets Manager
// or AWS Systems Manager Parameter Store to ensure privacy of userdata.
// By default, a cloud-init boothook shell script is prepended to download
// the userdata from Secrets Manager and additionally delete the secret.
InsecureSkipSecretsManager bool `json:"insecureSkipSecretsManager,omitempty"`
// SecretCount is the number of secrets used to form the complete secret
// +optional
SecretCount int32 `json:"secretCount,omitempty"`
// SecretPrefix is the prefix for the secret name. This is stored
// temporarily, and deleted when the machine registers as a node against
// the workload cluster.
// +optional
SecretPrefix string `json:"secretPrefix,omitempty"`
// SecureSecretsBackend, when set to parameter-store will utilize the AWS Systems Manager
// Parameter Storage to distribute secrets. By default or with the value of secrets-manager,
// will use AWS Secrets Manager instead.
// +optional
// +kubebuilder:validation:Enum=secrets-manager;ssm-parameter-store
SecureSecretsBackend SecretBackend `json:"secureSecretsBackend,omitempty"`
}
// Ignition defines options related to the bootstrapping systems where Ignition is used.
// For more information on Ignition configuration, see https://coreos.github.io/butane/specs/
type Ignition struct {
// Version defines which version of Ignition will be used to generate bootstrap data.
//
// +optional
// +kubebuilder:default="2.3"
// +kubebuilder:validation:Enum="2.3";"3.0";"3.1";"3.2";"3.3";"3.4"
Version string `json:"version,omitempty"`
// StorageType defines how to store the boostrap user data for Ignition.
// This can be used to instruct Ignition from where to fetch the user data to bootstrap an instance.
//
// When omitted, the storage option will default to ClusterObjectStore.
//
// When set to "ClusterObjectStore", if the capability is available and a Cluster ObjectStore configuration
// is correctly provided in the Cluster object (under .spec.s3Bucket),
// an object store will be used to store bootstrap user data.
//
// When set to "UnencryptedUserData", EC2 Instance User Data will be used to store the machine bootstrap user data, unencrypted.
// This option is considered less secure than others as user data may contain sensitive informations (keys, certificates, etc.)
// and users with ec2:DescribeInstances permission or users running pods
// that can access the ec2 metadata service have access to this sensitive information.
// So this is only to be used at ones own risk, and only when other more secure options are not viable.
//
// +optional
// +kubebuilder:default="ClusterObjectStore"
// +kubebuilder:validation:Enum:="ClusterObjectStore";"UnencryptedUserData"
StorageType IgnitionStorageTypeOption `json:"storageType,omitempty"`
// Proxy defines proxy settings for Ignition.
// Only valid for Ignition versions 3.1 and above.
// +optional
Proxy *IgnitionProxy `json:"proxy,omitempty"`
// TLS defines TLS settings for Ignition.
// Only valid for Ignition versions 3.1 and above.
// +optional
TLS *IgnitionTLS `json:"tls,omitempty"`
}
// IgnitionCASource defines the source of the certificate authority to use for Ignition.
// +kubebuilder:validation:MaxLength:=65536
type IgnitionCASource string
// IgnitionTLS defines TLS settings for Ignition.
type IgnitionTLS struct {
// CASources defines the list of certificate authorities to use for Ignition.
// The value is the certificate bundle (in PEM format). The bundle can contain multiple concatenated certificates.
// Supported schemes are http, https, tftp, s3, arn, gs, and `data` (RFC 2397) URL scheme.
//
// +optional
// +kubebuilder:validation:MaxItems=64
CASources []IgnitionCASource `json:"certificateAuthorities,omitempty"`
}
// IgnitionNoProxy defines the list of domains to not proxy for Ignition.
// +kubebuilder:validation:MaxLength:=2048
type IgnitionNoProxy string
// IgnitionProxy defines proxy settings for Ignition.
type IgnitionProxy struct {
// HTTPProxy is the HTTP proxy to use for Ignition.
// A single URL that specifies the proxy server to use for HTTP and HTTPS requests,
// unless overridden by the HTTPSProxy or NoProxy options.
// +optional
HTTPProxy *string `json:"httpProxy,omitempty"`
// HTTPSProxy is the HTTPS proxy to use for Ignition.
// A single URL that specifies the proxy server to use for HTTPS requests,
// unless overridden by the NoProxy option.
// +optional
HTTPSProxy *string `json:"httpsProxy,omitempty"`
// NoProxy is the list of domains to not proxy for Ignition.
// Specifies a list of strings to hosts that should be excluded from proxying.
//
// Each value is represented by:
// - An IP address prefix (1.2.3.4)
// - An IP address prefix in CIDR notation (1.2.3.4/8)
// - A domain name
// - A domain name matches that name and all subdomains
// - A domain name with a leading . matches subdomains only
// - A special DNS label (*), indicates that no proxying should be done
//
// An IP address prefix and domain name can also include a literal port number (1.2.3.4:80).
// +optional
// +kubebuilder:validation:MaxItems=64
NoProxy []IgnitionNoProxy `json:"noProxy,omitempty"`
}
// AWSMachineStatus defines the observed state of AWSMachine.
type AWSMachineStatus struct {
// Ready is true when the provider resource is ready.
// +optional
Ready bool `json:"ready"`
// Interruptible reports that this machine is using spot instances and can therefore be interrupted by CAPI when it receives a notice that the spot instance is to be terminated by AWS.
// This will be set to true when SpotMarketOptions is not nil (i.e. this machine is using a spot instance).
// +optional
Interruptible bool `json:"interruptible,omitempty"`
// Addresses contains the AWS instance associated addresses.
Addresses []clusterv1.MachineAddress `json:"addresses,omitempty"`
// InstanceState is the state of the AWS instance for this machine.
// +optional
InstanceState *InstanceState `json:"instanceState,omitempty"`
// FailureReason will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a succinct value suitable
// for machine interpretation.
//
// This field should not be set for transitive errors that a controller
// faces that are expected to be fixed automatically over
// time (like service outages), but instead indicate that something is
// fundamentally wrong with the Machine's spec or the configuration of
// the controller, and that manual intervention is required. Examples
// of terminal errors would be invalid combinations of settings in the
// spec, values that are unsupported by the controller, or the
// responsible controller itself being critically misconfigured.
//
// Any transient errors that occur during the reconciliation of Machines
// can be added as events to the Machine object and/or logged in the
// controller's output.
// +optional
FailureReason *errors.MachineStatusError `json:"failureReason,omitempty"`
// FailureMessage will be set in the event that there is a terminal problem
// reconciling the Machine and will contain a more verbose string suitable
// for logging and human consumption.
//
// This field should not be set for transitive errors that a controller
// faces that are expected to be fixed automatically over
// time (like service outages), but instead indicate that something is
// fundamentally wrong with the Machine's spec or the configuration of
// the controller, and that manual intervention is required. Examples
// of terminal errors would be invalid combinations of settings in the
// spec, values that are unsupported by the controller, or the
// responsible controller itself being critically misconfigured.
//
// Any transient errors that occur during the reconciliation of Machines
// can be added as events to the Machine object and/or logged in the
// controller's output.
// +optional
FailureMessage *string `json:"failureMessage,omitempty"`
// Conditions defines current service state of the AWSMachine.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=awsmachines,scope=Namespaced,categories=cluster-api,shortName=awsm
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AWSMachine belongs"
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.instanceState",description="EC2 instance state"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status"
// +kubebuilder:printcolumn:name="InstanceID",type="string",JSONPath=".spec.providerID",description="EC2 instance ID"
// +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this AWSMachine"
// +k8s:defaulter-gen=true
// AWSMachine is the schema for Amazon EC2 machines.
type AWSMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec AWSMachineSpec `json:"spec,omitempty"`
Status AWSMachineStatus `json:"status,omitempty"`
}
// GetConditions returns the observations of the operational state of the AWSMachine resource.
func (r *AWSMachine) GetConditions() clusterv1.Conditions {
return r.Status.Conditions
}
// SetConditions sets the underlying service state of the AWSMachine to the predescribed clusterv1.Conditions.
func (r *AWSMachine) SetConditions(conditions clusterv1.Conditions) {
r.Status.Conditions = conditions
}
// +kubebuilder:object:root=true
// AWSMachineList contains a list of Amazon EC2 machines.
type AWSMachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AWSMachine `json:"items"`
}
func init() {
SchemeBuilder.Register(&AWSMachine{}, &AWSMachineList{})
}