-
Notifications
You must be signed in to change notification settings - Fork 416
/
azuremachine_types.go
298 lines (246 loc) · 13.2 KB
/
azuremachine_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
/*
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 (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
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 ReconcileAzureMachine to clean up Azure resources associated with AzureMachine before
// removing it from the apiserver.
MachineFinalizer = "azuremachine.infrastructure.cluster.x-k8s.io"
)
// AzureMachineSpec defines the desired state of AzureMachine.
type AzureMachineSpec struct {
// ProviderID is the unique identifier as specified by the cloud provider.
// +optional
ProviderID *string `json:"providerID,omitempty"`
VMSize string `json:"vmSize"`
// FailureDomain is the failure domain unique identifier this Machine should be attached to,
// as defined in Cluster API. This relates to an Azure Availability Zone
// +optional
FailureDomain *string `json:"failureDomain,omitempty"`
// Image is used to provide details of an image to use during VM creation.
// If image details are omitted the image will default the Azure Marketplace "capi" offer,
// which is based on Ubuntu.
// +kubebuilder:validation:nullable
// +optional
Image *Image `json:"image,omitempty"`
// Identity is the type of identity used for the virtual machine.
// The type 'SystemAssigned' is an implicitly created identity.
// The generated identity will be assigned a Subscription contributor role.
// The type 'UserAssigned' is a standalone Azure resource provided by the user
// and assigned to the VM
// +kubebuilder:default=None
// +optional
Identity VMIdentity `json:"identity,omitempty"`
// UserAssignedIdentities is a list of standalone Azure identities provided by the user
// The lifecycle of a user-assigned identity is managed separately from the lifecycle of
// the AzureMachine.
// See https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/how-to-manage-ua-identity-cli
// +optional
UserAssignedIdentities []UserAssignedIdentity `json:"userAssignedIdentities,omitempty"`
// SystemAssignedIdentityRole defines the role and scope to assign to the system-assigned identity.
// +optional
SystemAssignedIdentityRole *SystemAssignedIdentityRole `json:"systemAssignedIdentityRole,omitempty"`
// Deprecated: RoleAssignmentName should be set in the systemAssignedIdentityRole field.
// +optional
RoleAssignmentName string `json:"roleAssignmentName,omitempty"`
// OSDisk specifies the parameters for the operating system disk of the machine
OSDisk OSDisk `json:"osDisk"`
// DataDisk specifies the parameters that are used to add one or more data disks to the machine
// +optional
DataDisks []DataDisk `json:"dataDisks,omitempty"`
SSHPublicKey string `json:"sshPublicKey"`
// AdditionalTags is an optional set of tags to add to an instance, in addition to the ones added by default by the
// Azure provider. If both the AzureCluster and the AzureMachine specify the same tag name with different values, the
// AzureMachine's value takes precedence.
// +optional
AdditionalTags Tags `json:"additionalTags,omitempty"`
// AdditionalCapabilities specifies additional capabilities enabled or disabled on the virtual machine.
// +optional
AdditionalCapabilities *AdditionalCapabilities `json:"additionalCapabilities,omitempty"`
// AllocatePublicIP allows the ability to create dynamic public ips for machines where this value is true.
// +optional
AllocatePublicIP bool `json:"allocatePublicIP,omitempty"`
// EnableIPForwarding enables IP Forwarding in Azure which is required for some CNI's to send traffic from a pods on one machine
// to another. This is required for IpV6 with Calico in combination with User Defined Routes (set by the Azure Cloud Controller
// manager). Default is false for disabled.
// +optional
EnableIPForwarding bool `json:"enableIPForwarding,omitempty"`
// Deprecated: AcceleratedNetworking should be set in the networkInterfaces field.
// +kubebuilder:validation:nullable
// +optional
AcceleratedNetworking *bool `json:"acceleratedNetworking,omitempty"`
// Diagnostics specifies the diagnostics settings for a virtual machine.
// If not specified then Boot diagnostics (Managed) will be enabled.
// +optional
Diagnostics *Diagnostics `json:"diagnostics,omitempty"`
// SpotVMOptions allows the ability to specify the Machine should use a Spot VM
// +optional
SpotVMOptions *SpotVMOptions `json:"spotVMOptions,omitempty"`
// SecurityProfile specifies the Security profile settings for a virtual machine.
// +optional
SecurityProfile *SecurityProfile `json:"securityProfile,omitempty"`
// Deprecated: SubnetName should be set in the networkInterfaces field.
// +optional
SubnetName string `json:"subnetName,omitempty"`
// DNSServers adds a list of DNS Server IP addresses to the VM NICs.
// +optional
DNSServers []string `json:"dnsServers,omitempty"`
// VMExtensions specifies a list of extensions to be added to the virtual machine.
// +optional
VMExtensions []VMExtension `json:"vmExtensions,omitempty"`
// NetworkInterfaces specifies a list of network interface configurations.
// If left unspecified, the VM will get a single network interface with a
// single IPConfig in the subnet specified in the cluster's node subnet field.
// The primary interface will be the first networkInterface specified (index 0) in the list.
// +optional
NetworkInterfaces []NetworkInterface `json:"networkInterfaces,omitempty"`
}
// SpotVMOptions defines the options relevant to running the Machine on Spot VMs.
type SpotVMOptions struct {
// MaxPrice defines the maximum price the user is willing to pay for Spot VM instances
// +optional
MaxPrice *resource.Quantity `json:"maxPrice,omitempty"`
// EvictionPolicy defines the behavior of the virtual machine when it is evicted. It can be either Delete or Deallocate.
// +optional
EvictionPolicy *SpotEvictionPolicy `json:"evictionPolicy,omitempty"`
}
// SystemAssignedIdentityRole defines the role and scope to assign to the system assigned identity.
type SystemAssignedIdentityRole struct {
// Name is the name of the role assignment to create for a system assigned identity. It can be any valid UUID.
// If not specified, a random UUID will be generated.
// +optional
Name string `json:"name,omitempty"`
// DefinitionID is the ID of the role definition to create for a system assigned identity. It can be an Azure built-in role or a custom role.
// Refer to built-in roles: https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles
// +optional
DefinitionID string `json:"definitionID,omitempty"`
// Scope is the scope that the role assignment or definition applies to. The scope can be any REST resource instance.
// If not specified, the scope will be the subscription.
// +optional
Scope string `json:"scope,omitempty"`
}
// AzureMachineStatus defines the observed state of AzureMachine.
type AzureMachineStatus struct {
// Ready is true when the provider resource is ready.
// +optional
Ready bool `json:"ready"`
// Addresses contains the Azure instance associated addresses.
// +optional
Addresses []corev1.NodeAddress `json:"addresses,omitempty"`
// VMState is the provisioning state of the Azure virtual machine.
// +optional
VMState *ProvisioningState `json:"vmState,omitempty"`
// ErrorReason 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"`
// ErrorMessage 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 AzureMachine.
// +optional
Conditions clusterv1.Conditions `json:"conditions,omitempty"`
// LongRunningOperationStates saves the states for Azure long-running operations so they can be continued on the
// next reconciliation loop.
// +optional
LongRunningOperationStates Futures `json:"longRunningOperationStates,omitempty"`
}
// AdditionalCapabilities enables or disables a capability on the virtual machine.
type AdditionalCapabilities struct {
// UltraSSDEnabled enables or disables Azure UltraSSD capability for the virtual machine.
// Defaults to true if Ultra SSD data disks are specified,
// otherwise it doesn't set the capability on the VM.
// +optional
UltraSSDEnabled *bool `json:"ultraSSDEnabled,omitempty"`
}
// +kubebuilder:object:root=true
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="Reason",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].reason"
// +kubebuilder:printcolumn:name="Message",type="string",priority=1,JSONPath=".status.conditions[?(@.type=='Ready')].message"
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.vmState",description="Azure VM provisioning state"
// +kubebuilder:printcolumn:name="Cluster",type="string",priority=1,JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this AzureMachine belongs"
// +kubebuilder:printcolumn:name="Machine",type="string",priority=1,JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object to which this AzureMachine belongs"
// +kubebuilder:printcolumn:name="VM ID",type="string",priority=1,JSONPath=".spec.providerID",description="Azure VM ID"
// +kubebuilder:printcolumn:name="VM Size",type="string",priority=1,JSONPath=".spec.vmSize",description="Azure VM Size"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of this AzureMachine"
// +kubebuilder:resource:path=azuremachines,scope=Namespaced,categories=cluster-api
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// AzureMachine is the Schema for the azuremachines API.
type AzureMachine struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec AzureMachineSpec `json:"spec,omitempty"`
Status AzureMachineStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// AzureMachineList contains a list of AzureMachine.
type AzureMachineList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AzureMachine `json:"items"`
}
// GetConditions returns the list of conditions for an AzureMachine API object.
func (m *AzureMachine) GetConditions() clusterv1.Conditions {
return m.Status.Conditions
}
// SetConditions will set the given conditions on an AzureMachine object.
func (m *AzureMachine) SetConditions(conditions clusterv1.Conditions) {
m.Status.Conditions = conditions
}
// GetFutures returns the list of long running operation states for an AzureMachine API object.
func (m *AzureMachine) GetFutures() Futures {
return m.Status.LongRunningOperationStates
}
// SetFutures will set the given long running operation states on an AzureMachine object.
func (m *AzureMachine) SetFutures(futures Futures) {
m.Status.LongRunningOperationStates = futures
}
func init() {
SchemeBuilder.Register(&AzureMachine{}, &AzureMachineList{})
}