This repository has been archived by the owner on Jun 12, 2023. It is now read-only.
/
types.go
404 lines (332 loc) 路 14.8 KB
/
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
/*
Copyright The Pharmer 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 azure
import (
"time"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// AzureResourceReference is a reference to a specific Azure resource by ID
type AzureResourceReference struct {
// ID of resource
// +optional
ID *string `json:"id,omitempty"`
// TODO: Investigate if we should reference resources in other ways
}
// TODO: Investigate resource filters
// AzureMachineProviderConditionType is a valid value for AzureMachineProviderCondition.Type
type AzureMachineProviderConditionType string
// Valid conditions for an Azure machine instance
const (
// MachineCreated indicates whether the machine has been created or not. If not,
// it should include a reason and message for the failure.
MachineCreated AzureMachineProviderConditionType = "MachineCreated"
)
// AzureMachineProviderCondition is a condition in a AzureMachineProviderStatus
type AzureMachineProviderCondition struct {
// Type is the type of the condition.
Type AzureMachineProviderConditionType `json:"type"`
// Status is the status of the condition.
Status corev1.ConditionStatus `json:"status"`
// LastProbeTime is the last time we probed the condition.
// +optional
LastProbeTime metav1.Time `json:"lastProbeTime"`
// LastTransitionTime is the last time the condition transitioned from one status to another.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
// Reason is a unique, one-word, CamelCase reason for the condition's last transition.
// +optional
Reason string `json:"reason"`
// Message is a human-readable message indicating details about last transition.
// +optional
Message string `json:"message"`
}
type MachineRole string
const (
// TODO: Change references to "controlplane", instead of "Master" and lowercase both roles.
Master MachineRole = "Master"
Node MachineRole = "Node"
)
// Network encapsulates Azure networking resources.
type Network struct {
// Vnet defines the cluster vnet.
Vnet Vnet `json:"vnet,omitempty"`
// SecurityGroups is a map from the role/kind of the security group to its unique name, if any.
SecurityGroups map[SecurityGroupRole]*SecurityGroup `json:"securityGroups,omitempty"`
// Subnets includes all the subnets defined inside the Vnet.
Subnets Subnets `json:"subnets,omitempty"`
// APIServerLB is the Kubernetes API server load balancer.
APIServerLB LoadBalancer `json:"apiServerLb,omitempty"`
// APIServerIP is the Kubernetes API server public IP address.
APIServerIP PublicIP `json:"apiServerIp,omitempty"`
}
// Tags defines resource tags.
type Tags map[string]*string
// Vnet defines an Azure Virtual Network.
type Vnet struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CidrBlock string `json:"cidrBlock"`
Tags *Tags `json:"tags"`
}
// Subnets is a slice of Subnet.
type Subnets []*Subnet
// TODO
// ToMap returns a map from id to subnet.
func (s Subnets) ToMap() map[string]*Subnet {
res := make(map[string]*Subnet)
for _, x := range s {
res[x.ID] = x
}
return res
}
// Subnet defines an Azure subnet attached to a Vnet.
type Subnet struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
VnetID string `json:"vnetId"`
CidrBlock string `json:"cidrBlock"`
SecurityGroup SecurityGroup `json:"securityGroup"`
}
// SecurityGroupRole defines the unique role of a security group.
type SecurityGroupRole string
var (
// SecurityGroupBastion defines an SSH bastion role
SecurityGroupBastion = SecurityGroupRole("bastion")
// SecurityGroupNode defines a Kubernetes workload node role
SecurityGroupNode = SecurityGroupRole("node")
// SecurityGroupControlPlane defines a Kubernetes control plane node role
SecurityGroupControlPlane = SecurityGroupRole("controlplane")
)
// SecurityGroup defines an Azure security group.
type SecurityGroup struct {
ID string `json:"id"`
Name string `json:"name"`
IngressRules IngressRules `json:"ingressRule"`
Tags *Tags `json:"tags"`
}
/*
// TODO
// String returns a string representation of the security group.
func (s *SecurityGroup) String() string {
return fmt.Sprintf("id=%s/name=%s", s.ID, s.Name)
}
*/
// SecurityGroupProtocol defines the protocol type for a security group rule.
type SecurityGroupProtocol string
var (
// SecurityGroupProtocolAll is a wildcard for all IP protocols
SecurityGroupProtocolAll = SecurityGroupProtocol("*")
// SecurityGroupProtocolTCP represents the TCP protocol in ingress rules
SecurityGroupProtocolTCP = SecurityGroupProtocol("Tcp")
// SecurityGroupProtocolUDP represents the UDP protocol in ingress rules
SecurityGroupProtocolUDP = SecurityGroupProtocol("Udp")
)
// TODO
// IngressRule defines an Azure ingress rule for security groups.
type IngressRule struct {
Description string `json:"description"`
Protocol SecurityGroupProtocol `json:"protocol"`
// SourcePorts - The source port or range. Integer or range between 0 and 65535. Asterix '*' can also be used to match all ports.
SourcePorts *string `json:"sourcePorts,omitempty"`
// DestinationPorts - The destination port or range. Integer or range between 0 and 65535. Asterix '*' can also be used to match all ports.
DestinationPorts *string `json:"destinationPorts,omitempty"`
// Source - The CIDR or source IP range. Asterix '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. If this is an ingress rule, specifies where network traffic originates from.
Source *string `json:"source,omitempty"`
// Destination - The destination address prefix. CIDR or destination IP range. Asterix '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used.
Destination *string `json:"destination,omitempty"`
}
// TODO
// String returns a string representation of the ingress rule.
/*
func (i *IngressRule) String() string {
return fmt.Sprintf("protocol=%s/range=[%d-%d]/description=%s", i.Protocol, i.FromPort, i.ToPort, i.Description)
}
*/
// TODO
// IngressRules is a slice of Azure ingress rules for security groups.
type IngressRules []*IngressRule
// TODO
// Difference returns the difference between this slice and the other slice.
/*
func (i IngressRules) Difference(o IngressRules) (out IngressRules) {
for _, x := range i {
found := false
for _, y := range o {
sort.Strings(x.CidrBlocks)
sort.Strings(y.CidrBlocks)
sort.Strings(x.SourceSecurityGroupIDs)
sort.Strings(y.SourceSecurityGroupIDs)
if reflect.DeepEqual(x, y) {
found = true
break
}
}
if !found {
out = append(out, x)
}
}
return
}
*/
// PublicIP defines an Azure public IP address.
// TODO: Remove once load balancer is implemented.
type PublicIP struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
IPAddress string `json:"ipAddress,omitempty"`
DNSName string `json:"dnsName,omitempty"`
}
// TODO
// LoadBalancer defines an Azure load balancer.
type LoadBalancer struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
SKU SKU `json:"sku,omitempty"`
FrontendIPConfig FrontendIPConfig `json:"frontendIpConfig,omitempty"`
BackendPool BackendPool `json:"backendPool,omitempty"`
Tags Tags `json:"tags,omitempty"`
/*
// FrontendIPConfigurations - Object representing the frontend IPs to be used for the load balancer
FrontendIPConfigurations *[]FrontendIPConfiguration `json:"frontendIPConfigurations,omitempty"`
// BackendAddressPools - Collection of backend address pools used by a load balancer
BackendAddressPools *[]BackendAddressPool `json:"backendAddressPools,omitempty"`
// LoadBalancingRules - Object collection representing the load balancing rules Gets the provisioning
LoadBalancingRules *[]LoadBalancingRule `json:"loadBalancingRules,omitempty"`
// Probes - Collection of probe objects used in the load balancer
Probes *[]Probe `json:"probes,omitempty"`
// InboundNatRules - Collection of inbound NAT Rules used by a load balancer. Defining inbound NAT rules on your load balancer is mutually exclusive with defining an inbound NAT pool. Inbound NAT pools are referenced from virtual machine scale sets. NICs that are associated with individual virtual machines cannot reference an Inbound NAT pool. They have to reference individual inbound NAT rules.
InboundNatRules *[]InboundNatRule `json:"inboundNatRules,omitempty"`
// InboundNatPools - Defines an external port range for inbound NAT to a single backend port on NICs associated with a load balancer. Inbound NAT rules are created automatically for each NIC associated with the Load Balancer using an external port from this range. Defining an Inbound NAT pool on your Load Balancer is mutually exclusive with defining inbound Nat rules. Inbound NAT pools are referenced from virtual machine scale sets. NICs that are associated with individual virtual machines cannot reference an inbound NAT pool. They have to reference individual inbound NAT rules.
InboundNatPools *[]InboundNatPool `json:"inboundNatPools,omitempty"`
// OutboundRules - The outbound rules.
OutboundRules *[]OutboundRule `json:"outboundRules,omitempty"`
// ResourceGUID - The resource GUID property of the load balancer resource.
ResourceGUID *string `json:"resourceGuid,omitempty"`
// ProvisioningState - Gets the provisioning state of the PublicIP resource. Possible values are: 'Updating', 'Deleting', and 'Failed'.
ProvisioningState *string `json:"provisioningState,omitempty"`
*/
}
// LoadBalancerSKU enumerates the values for load balancer sku name.
type SKU string
var (
SKUBasic = SKU("Basic")
SKUStandard = SKU("Standard")
)
type FrontendIPConfig struct {
/*
// FrontendIPConfigurationPropertiesFormat - Properties of the load balancer probe.
*FrontendIPConfigurationPropertiesFormat `json:"properties,omitempty"`
// Name - The name of the resource that is unique within a resource group. This name can be used to access the resource.
Name *string `json:"name,omitempty"`
// Etag - A unique read-only string that changes whenever the resource is updated.
Etag *string `json:"etag,omitempty"`
// Zones - A list of availability zones denoting the IP allocated for the resource needs to come from.
Zones *[]string `json:"zones,omitempty"`
// ID - Resource ID.
ID *string `json:"id,omitempty"`
*/
}
type BackendPool struct {
Name string `json:"name,omitempty"`
ID string `json:"id,omitempty"`
}
// TODO
// LoadBalancerProtocol defines listener protocols for a load balancer.
type LoadBalancerProtocol string
// TODO
var (
// LoadBalancerProtocolTCP defines the LB API string representing the TCP protocol
LoadBalancerProtocolTCP = LoadBalancerProtocol("TCP")
// LoadBalancerProtocolSSL defines the LB API string representing the TLS protocol
LoadBalancerProtocolSSL = LoadBalancerProtocol("SSL")
// LoadBalancerProtocolHTTP defines the LB API string representing the HTTP protocol at L7
LoadBalancerProtocolHTTP = LoadBalancerProtocol("HTTP")
// LoadBalancerProtocolHTTPS defines the LB API string representing the HTTP protocol at L7
LoadBalancerProtocolHTTPS = LoadBalancerProtocol("HTTPS")
)
// TODO
// LoadBalancerListener defines an Azure load balancer listener.
type LoadBalancerListener struct {
Protocol LoadBalancerProtocol `json:"protocol"`
Port int64 `json:"port"`
InstanceProtocol LoadBalancerProtocol `json:"instanceProtocol"`
InstancePort int64 `json:"instancePort"`
}
// TODO
// LoadBalancerHealthCheck defines an Azure load balancer health check.
type LoadBalancerHealthCheck struct {
Target string `json:"target"`
Interval time.Duration `json:"interval"`
Timeout time.Duration `json:"timeout"`
HealthyThreshold int64 `json:"healthyThreshold"`
UnhealthyThreshold int64 `json:"unhealthyThreshold"`
}
// VMState describes the state of an Azure virtual machine.
type VMState string
var (
// VMStateCreating ...
VMStateCreating = VMState("Creating")
// VMStateDeleting ...
VMStateDeleting = VMState("Deleting")
// VMStateFailed ...
VMStateFailed = VMState("Failed")
// VMStateMigrating ...
VMStateMigrating = VMState("Migrating")
// VMStateSucceeded ...
VMStateSucceeded = VMState("Succeeded")
// VMStateUpdating ...
VMStateUpdating = VMState("Updating")
)
// VM describes an Azure virtual machine.
type VM struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
// Hardware profile
VMSize string `json:"vmSize,omitempty"`
// Storage profile
Image Image `json:"image,omitempty"`
OSDisk OSDisk `json:"osDisk,omitempty"`
StartupScript string `json:"startupScript,omitempty"`
// State - The provisioning state, which only appears in the response.
State VMState `json:"vmState,omitempty"`
Identity VMIdentity `json:"identity,omitempty"`
Tags Tags `json:"tags,omitempty"`
// HardwareProfile - Specifies the hardware settings for the virtual machine.
//HardwareProfile *HardwareProfile `json:"hardwareProfile,omitempty"`
// StorageProfile - Specifies the storage settings for the virtual machine disks.
//StorageProfile *StorageProfile `json:"storageProfile,omitempty"`
// AdditionalCapabilities - Specifies additional capabilities enabled or disabled on the virtual machine.
//AdditionalCapabilities *AdditionalCapabilities `json:"additionalCapabilities,omitempty"`
// OsProfile - Specifies the operating system settings for the virtual machine.
//OsProfile *OSProfile `json:"osProfile,omitempty"`
// NetworkProfile - Specifies the network interfaces of the virtual machine.
//NetworkProfile *NetworkProfile `json:"networkProfile,omitempty"`
//AvailabilitySet *SubResource `json:"availabilitySet,omitempty"`
}
type Image struct {
Publisher string `json:"publisher"`
Offer string `json:"offer"`
SKU string `json:"sku"`
Version string `json:"version"`
}
// VMIdentity defines the identity of the virtual machine, if configured.
type VMIdentity string
type OSDisk struct {
OSType string `json:"osType"`
ManagedDisk ManagedDisk `json:"managedDisk"`
DiskSizeGB int32 `json:"diskSizeGB"`
}
type ManagedDisk struct {
StorageAccountType string `json:"storageAccountType"`
}