-
Notifications
You must be signed in to change notification settings - Fork 431
/
types.go
438 lines (357 loc) · 13.7 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
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
/*
Copyright 2020 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 azure
import (
"reflect"
"github.com/google/go-cmp/cmp"
infrav1 "sigs.k8s.io/cluster-api-provider-azure/api/v1alpha4"
)
// PublicIPSpec defines the specification for a Public IP.
type PublicIPSpec struct {
Name string
DNSName string
IsIPv6 bool
}
// NICSpec defines the specification for a Network Interface.
type NICSpec struct {
Name string
MachineName string
SubnetName string
VNetName string
VNetResourceGroup string
StaticIPAddress string
PublicLBName string
PublicLBAddressPoolName string
PublicLBNATRuleName string
InternalLBName string
InternalLBAddressPoolName string
PublicIPName string
VMSize string
AcceleratedNetworking *bool
IPv6Enabled bool
EnableIPForwarding bool
}
// DiskSpec defines the specification for a Disk.
type DiskSpec struct {
Name string
}
// LBSpec defines the specification for a Load Balancer.
type LBSpec struct {
Name string
Role string
Type infrav1.LBType
SKU infrav1.SKU
SubnetName string
BackendPoolName string
FrontendIPConfigs []infrav1.FrontendIP
APIServerPort int32
IdleTimeoutInMinutes *int32
}
// RouteTableRole defines the unique role of a route table.
type RouteTableRole string
// RouteTableSpec defines the specification for a Route Table.
type RouteTableSpec struct {
Name string
Subnet infrav1.SubnetSpec
}
// NatGatewaySpec defines the specification for a Nat Gateway.
type NatGatewaySpec struct {
NatGatewayIP infrav1.PublicIPSpec
Name string
Subnet infrav1.SubnetSpec
}
// InboundNatSpec defines the specification for an inbound NAT rule.
type InboundNatSpec struct {
Name string
LoadBalancerName string
}
// SubnetSpec defines the specification for a Subnet.
type SubnetSpec struct {
Name string
CIDRs []string
VNetName string
RouteTableName string
SecurityGroupName string
Role infrav1.SubnetRole
NatGatewayName string
}
// VNetSpec defines the specification for a Virtual Network.
type VNetSpec struct {
ResourceGroup string
Name string
CIDRs []string
}
// RoleAssignmentSpec defines the specification for a Role Assignment.
type RoleAssignmentSpec struct {
MachineName string
Name string
ResourceType string
}
// ResourceType defines the type azure resource being reconciled.
// Eg. Virtual Machine, Virtual Machine Scale Sets.
type ResourceType string
const (
// VirtualMachine ...
VirtualMachine = "VirtualMachine"
// VirtualMachineScaleSet ...
VirtualMachineScaleSet = "VirtualMachineScaleSet"
)
// NSGSpec defines the specification for a Security Group.
type NSGSpec struct {
Name string
SecurityRules infrav1.SecurityRules
}
// VMSpec defines the specification for a Virtual Machine.
type VMSpec struct {
Name string
Role string
NICNames []string
SSHKeyData string
Size string
Zone string
Identity infrav1.VMIdentity
OSDisk infrav1.OSDisk
DataDisks []infrav1.DataDisk
UserAssignedIdentities []infrav1.UserAssignedIdentity
SpotVMOptions *infrav1.SpotVMOptions
SecurityProfile *infrav1.SecurityProfile
}
// BastionSpec defines the specification for the generic bastion feature.
type BastionSpec struct {
AzureBastion *AzureBastionSpec
}
// AzureBastionSpec defines the specification for azure bastion feature.
type AzureBastionSpec struct { // nolint
Name string
SubnetSpec infrav1.SubnetSpec
PublicIPName string
VNetName string
}
// ScaleSetSpec defines the specification for a Scale Set.
type ScaleSetSpec struct {
Name string
Size string
Capacity int64
SSHKeyData string
OSDisk infrav1.OSDisk
DataDisks []infrav1.DataDisk
SubnetName string
VNetName string
VNetResourceGroup string
PublicLBName string
PublicLBAddressPoolName string
AcceleratedNetworking *bool
TerminateNotificationTimeout *int
Identity infrav1.VMIdentity
UserAssignedIdentities []infrav1.UserAssignedIdentity
SecurityProfile *infrav1.SecurityProfile
SpotVMOptions *infrav1.SpotVMOptions
FailureDomains []string
}
// TagsSpec defines the specification for a set of tags.
type TagsSpec struct {
Scope string
Tags infrav1.Tags
Annotation string
}
// PrivateDNSSpec defines the specification for a private DNS zone.
type PrivateDNSSpec struct {
ZoneName string
VNetName string
VNetResourceGroup string
LinkName string
Records []infrav1.AddressRecord
}
// AvailabilitySetSpec defines the specification for an availability set.
type AvailabilitySetSpec struct {
Name string
}
// VMExtensionSpec defines the specification for a VM extension.
type VMExtensionSpec struct {
Name string
VMName string
Publisher string
Version string
ProtectedSettings map[string]string
}
// VMSSExtensionSpec defines the specification for a VMSS extension.
type VMSSExtensionSpec struct {
Name string
ScaleSetName string
Publisher string
Version string
ProtectedSettings map[string]string
}
type (
// VMSSVM defines a VM in a virtual machine scale set.
VMSSVM struct {
ID string `json:"id,omitempty"`
InstanceID string `json:"instanceID,omitempty"`
Image infrav1.Image `json:"image,omitempty"`
Name string `json:"name,omitempty"`
AvailabilityZone string `json:"availabilityZone,omitempty"`
State infrav1.ProvisioningState `json:"vmState,omitempty"`
}
// VMSS defines a virtual machine scale set.
VMSS struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Sku string `json:"sku,omitempty"`
Capacity int64 `json:"capacity,omitempty"`
Zones []string `json:"zones,omitempty"`
Image infrav1.Image `json:"image,omitempty"`
State infrav1.ProvisioningState `json:"vmState,omitempty"`
Identity infrav1.VMIdentity `json:"identity,omitempty"`
Tags infrav1.Tags `json:"tags,omitempty"`
Instances []VMSSVM `json:"instances,omitempty"`
}
)
// HasModelChanges returns true if the spec fields which will mutate the Azure VMSS model are different.
func (vmss VMSS) HasModelChanges(other VMSS) bool {
equal := cmp.Equal(vmss.Image, other.Image) &&
cmp.Equal(vmss.Identity, other.Identity) &&
cmp.Equal(vmss.Zones, other.Zones) &&
cmp.Equal(vmss.Tags, other.Tags) &&
cmp.Equal(vmss.Sku, other.Sku)
return !equal
}
// InstancesByProviderID returns VMSSVMs by ID.
func (vmss VMSS) InstancesByProviderID() map[string]VMSSVM {
instancesByProviderID := make(map[string]VMSSVM, len(vmss.Instances))
for _, instance := range vmss.Instances {
instancesByProviderID[instance.ProviderID()] = instance
}
return instancesByProviderID
}
// ProviderID returns the K8s provider ID for the VMSS instance.
func (vm VMSSVM) ProviderID() string {
return ProviderIDPrefix + vm.ID
}
// HasLatestModelAppliedToAll returns true if all VMSS instance have the latest model applied.
func (vmss VMSS) HasLatestModelAppliedToAll() bool {
for _, instance := range vmss.Instances {
if !vmss.HasLatestModelApplied(instance) {
return false
}
}
return true
}
// HasEnoughLatestModelOrNotMixedModel returns true if VMSS instance have the latest model applied to all or equal to the capacity.
func (vmss VMSS) HasEnoughLatestModelOrNotMixedModel() bool {
if vmss.HasLatestModelAppliedToAll() {
return true
}
counter := int64(0)
for _, instance := range vmss.Instances {
if vmss.HasLatestModelApplied(instance) {
counter++
}
}
return counter == vmss.Capacity
}
// HasLatestModelApplied returns true if the VMSS instance matches the VMSS image reference.
func (vmss VMSS) HasLatestModelApplied(vm VMSSVM) bool {
// if the images match, then the VM is of the same model
return reflect.DeepEqual(vm.Image, vmss.Image)
}
// ManagedClusterSpec contains properties to create a managed cluster.
type ManagedClusterSpec struct {
// Name is the name of this AKS Cluster.
Name string
// ResourceGroupName is the name of the Azure resource group for this AKS Cluster.
ResourceGroupName string
// NodeResourceGroupName is the name of the Azure resource group containing IaaS VMs.
NodeResourceGroupName string
// VnetSubnetID is the Azure Resource ID for the subnet which should contain nodes.
VnetSubnetID string
// Location is a string matching one of the canonical Azure region names. Examples: "westus2", "eastus".
Location string
// Tags is a set of tags to add to this cluster.
Tags map[string]string
// Version defines the desired Kubernetes version.
Version string
// LoadBalancerSKU for the managed cluster. Possible values include: 'Standard', 'Basic'. Defaults to Standard.
LoadBalancerSKU string
// NetworkPlugin used for building Kubernetes network. Possible values include: 'azure', 'kubenet'. Defaults to azure.
NetworkPlugin string
// NetworkPolicy used for building Kubernetes network. Possible values include: 'calico', 'azure'. Defaults to azure.
NetworkPolicy string
// SSHPublicKey is a string literal containing an ssh public key. Will autogenerate and discard if not provided.
SSHPublicKey string
// AgentPools is the list of agent pool specifications in this cluster.
AgentPools []AgentPoolSpec
// PodCIDR is the CIDR block for IP addresses distributed to pods
PodCIDR string
// ServiceCIDR is the CIDR block for IP addresses distributed to services
ServiceCIDR string
// DNSServiceIP is an IP address assigned to the Kubernetes DNS service
DNSServiceIP *string
// AADProfile is Azure Active Directory configuration to integrate with AKS, for aad authentication.
AADProfile *AADProfile
// SKU is the SKU of the AKS to be provisioned.
SKU *SKU
// LoadBalancerProfile is the profile of the cluster load balancer.
LoadBalancerProfile *LoadBalancerProfile
}
// AADProfile is Azure Active Directory configuration to integrate with AKS, for aad authentication.
type AADProfile struct {
// Managed - Whether to enable managed AAD.
Managed bool
// EnableAzureRBAC - Whether to enable Azure RBAC for Kubernetes authorization.
EnableAzureRBAC bool
// AdminGroupObjectIDs - AAD group object IDs that will have admin role of the cluster.
AdminGroupObjectIDs []string
}
// SKU - AKS SKU.
type SKU struct {
// Tier - Tier of a managed cluster SKU.
Tier string
}
// LoadBalancerProfile - Profile of the cluster load balancer.
type LoadBalancerProfile struct {
// Load balancer profile must specify at most one of ManagedOutboundIPs, OutboundIPPrefixes and OutboundIPs.
// By default the AKS cluster automatically creates a public IP in the AKS-managed infrastructure resource group and assigns it to the load balancer outbound pool.
// Alternatively, you can assign your own custom public IP or public IP prefix at cluster creation time.
// See https://docs.microsoft.com/en-us/azure/aks/load-balancer-standard#provide-your-own-outbound-public-ips-or-prefixes
// ManagedOutboundIPs - Desired managed outbound IPs for the cluster load balancer.
ManagedOutboundIPs *int32
// OutboundIPPrefixes - Desired outbound IP Prefix resources for the cluster load balancer.
OutboundIPPrefixes []string
// OutboundIPs - Desired outbound IP resources for the cluster load balancer.
OutboundIPs []string
// AllocatedOutboundPorts - Desired number of allocated SNAT ports per VM. Allowed values must be in the range of 0 to 64000 (inclusive). The default value is 0 which results in Azure dynamically allocating ports.
AllocatedOutboundPorts *int32
// IdleTimeoutInMinutes - Desired outbound flow idle timeout in minutes. Allowed values must be in the range of 4 to 120 (inclusive). The default value is 30 minutes.
IdleTimeoutInMinutes *int32
}
// AgentPoolSpec contains agent pool specification details.
type AgentPoolSpec struct {
// Name is the name of agent pool.
Name string
// ResourceGroup is the name of the Azure resource group for the AKS Cluster.
ResourceGroup string
// Cluster is the name of the AKS cluster.
Cluster string
// Version defines the desired Kubernetes version.
Version *string
// SKU defines the Azure VM size for the agent pool VMs.
SKU string
// Replicas is the number of desired machines.
Replicas int32
// OSDiskSizeGB is the OS disk size in GB for every machine in this agent pool.
OSDiskSizeGB int32
// VnetSubnetID is the Azure Resource ID for the subnet which should contain nodes.
VnetSubnetID string
// Mode represents mode of an agent pool. Possible values include: 'System', 'User'.
Mode string
}