forked from Azure/aks-engine
/
types.go
293 lines (251 loc) · 10.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package v20180331
import "encoding/json"
// The validate tag is used for validation
// Reference to gopkg.in/go-playground/validator.v9
// ResourcePurchasePlan defines resource plan as required by ARM
// for billing purposes.
type ResourcePurchasePlan struct {
Name string `json:"name,omitempty"`
Product string `json:"product,omitempty"`
PromotionCode string `json:"promotionCode,omitempty"`
Publisher string `json:"publisher,omitempty"`
}
// ManagedCluster complies with the ARM model of
// resource definition in a JSON template.
type ManagedCluster struct {
ID string `json:"id,omitempty"`
Location string `json:"location,omitempty" validate:"required"`
Name string `json:"name,omitempty"`
Plan *ResourcePurchasePlan `json:"plan,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
Type string `json:"type,omitempty"`
Properties *Properties `json:"properties"`
}
// Properties represents the AKS cluster definition
type Properties struct {
ProvisioningState ProvisioningState `json:"provisioningState,omitempty"`
KubernetesVersion string `json:"kubernetesVersion"`
DNSPrefix string `json:"dnsPrefix,omitempty"`
FQDN string `json:"fqdn,omitempty"`
AgentPoolProfiles []*AgentPoolProfile `json:"agentPoolProfiles,omitempty" validate:"dive,required"`
LinuxProfile *LinuxProfile `json:"linuxProfile,omitempty"`
WindowsProfile *WindowsProfile `json:"windowsProfile,omitempty"`
ServicePrincipalProfile *ServicePrincipalProfile `json:"servicePrincipalProfile,omitempty"`
AccessProfiles map[string]AccessProfile `json:"accessProfiles,omitempty"`
AddonProfiles map[string]AddonProfile `json:"addonProfiles,omitempty"`
NodeResourceGroup string `json:"nodeResourceGroup,omitempty"`
EnableRBAC *bool `json:"enableRBAC,omitempty"`
NetworkProfile *NetworkProfile `json:"networkProfile,omitempty"`
AADProfile *AADProfile `json:"aadProfile,omitempty"`
}
// NetworkProfile represents network related definitions
type NetworkProfile struct {
NetworkPlugin NetworkPlugin `json:"networkPlugin,omitempty"`
NetworkPolicy NetworkPolicy `json:"networkPolicy,omitempty"`
PodCidr string `json:"podCidr,omitempty"`
ServiceCidr string `json:"serviceCidr,omitempty"`
DNSServiceIP string `json:"dnsServiceIP,omitempty"`
DockerBridgeCidr string `json:"dockerBridgeCidr,omitempty"`
}
// NetworkPlugin represnets types of network plugin
type NetworkPlugin string
const (
// Azure represents Azure CNI network plugin
Azure NetworkPlugin = "azure"
// Kubenet represents Kubenet network plugin
Kubenet NetworkPlugin = "kubenet"
)
// NetworkPolicy represnets types of network policy
type NetworkPolicy string
const (
// NetworkPolicyCalico represents Calico network policy
NetworkPolicyCalico NetworkPolicy = "calico"
)
// AddonProfile represents an addon for managed cluster
type AddonProfile struct {
Enabled bool `json:"enabled"`
Config map[string]string `json:"config"`
}
// ManagedClusterAccessProfile represents the access profile definition for managed cluster
// The Id captures the Role Name e.g. clusterAdmin, clusterUser
type ManagedClusterAccessProfile struct {
ID string `json:"id,omitempty"`
Location string `json:"location,omitempty" validate:"required"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Properties *AccessProfile `json:"properties"`
}
// ServicePrincipalProfile contains the client and secret used by the cluster for Azure Resource CRUD
// The 'Secret' parameter could be either a plain text, or referenced to a secret in a keyvault.
// In the latter case, the format of the parameter's value should be
// "/subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.KeyVault/vaults/<KV_NAME>/secrets/<NAME>[/<VERSION>]"
// where:
// <SUB_ID> is the subscription ID of the keyvault
// <RG_NAME> is the resource group of the keyvault
// <KV_NAME> is the name of the keyvault
// <NAME> is the name of the secret.
// <VERSION> (optional) is the version of the secret (default: the latest version)
type ServicePrincipalProfile struct {
ClientID string `json:"clientId,omitempty" validate:"required"`
Secret string `json:"secret,omitempty" conform:"redact"`
}
// LinuxProfile represents the Linux configuration passed to the cluster
type LinuxProfile struct {
AdminUsername string `json:"adminUsername" validate:"required"`
SSH struct {
PublicKeys []PublicKey `json:"publicKeys" validate:"required,len=1"`
} `json:"ssh" validate:"required"`
}
// PublicKey represents an SSH key for LinuxProfile
type PublicKey struct {
KeyData string `json:"keyData"`
}
// WindowsProfile represents the Windows configuration passed to the cluster
type WindowsProfile struct {
AdminUsername string `json:"adminUsername,omitempty" validate:"required"`
AdminPassword string `json:"adminPassword,omitempty" conform:"redact"`
}
// ProvisioningState represents the current state of container service resource.
type ProvisioningState string
const (
// Creating means ContainerService resource is being created.
Creating ProvisioningState = "Creating"
// Updating means an existing ContainerService resource is being updated
Updating ProvisioningState = "Updating"
// Failed means resource is in failed state
Failed ProvisioningState = "Failed"
// Succeeded means resource created succeeded during last create/update
Succeeded ProvisioningState = "Succeeded"
// Deleting means resource is in the process of being deleted
Deleting ProvisioningState = "Deleting"
// Migrating means resource is being migrated from one subscription or
// resource group to another
Migrating ProvisioningState = "Migrating"
// Upgrading means an existing resource is being upgraded
Upgrading ProvisioningState = "Upgrading"
)
// PoolUpgradeProfile contains pool properties:
// - kubernetes version
// - pool name (for agent pool)
// - OS type of the VMs in the pool
// - list of applicable upgrades
type PoolUpgradeProfile struct {
KubernetesVersion string `json:"kubernetesVersion"`
Name string `json:"name,omitempty"`
OSType string `json:"osType,omitempty"`
Upgrades []string `json:"upgrades,omitempty"`
}
// UpgradeProfileProperties contains properties of UpgradeProfile
type UpgradeProfileProperties struct {
ControlPlaneProfile *PoolUpgradeProfile `json:"controlPlaneProfile"`
AgentPoolProfiles []*PoolUpgradeProfile `json:"agentPoolProfiles"`
}
// UpgradeProfile contains controlPlane and agent pools upgrade profiles
type UpgradeProfile struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Properties UpgradeProfileProperties `json:"properties"`
}
// AgentPoolProfile represents configuration of VMs running agent
// daemons that register with the master and offer resources to
// host applications in containers.
type AgentPoolProfile struct {
Name string `json:"name" validate:"required"`
Count int `json:"count" validate:"required,min=1,max=100"`
VMSize string `json:"vmSize" validate:"required"`
OSDiskSizeGB int `json:"osDiskSizeGB,omitempty" validate:"min=0,max=1023"`
StorageProfile string `json:"storageProfile" validate:"eq=ManagedDisks|len=0"`
VnetSubnetID string `json:"vnetSubnetID,omitempty"`
MaxPods *int `json:"maxPods,omitempty"`
// OSType is the operating system type for agents
// Set as nullable to support backward compat because
// this property was added later.
// If the value is null or not set, it defaulted to Linux.
OSType OSType `json:"osType,omitempty"`
// subnet is internal
subnet string
}
// AccessProfile represents role name and kubeconfig
type AccessProfile struct {
KubeConfig string `json:"kubeConfig"`
}
// AADProfile specifies attributes for AAD integration
type AADProfile struct {
// The client AAD application ID.
ClientAppID string `json:"clientAppID,omitempty"`
// The server AAD application ID.
ServerAppID string `json:"serverAppID,omitempty"`
// The server AAD application secret
ServerAppSecret string `json:"serverAppSecret,omitempty" conform:"redact"`
// The AAD tenant ID to use for authentication.
// If not specified, will use the tenant of the deployment subscription.
// Optional
TenantID string `json:"tenantID,omitempty"`
}
// UnmarshalJSON unmarshal json using the default behavior
// And do fields manipulation, such as populating default value
func (a *AgentPoolProfile) UnmarshalJSON(b []byte) error {
// Need to have a alias type to avoid circular unmarshal
type aliasAgentPoolProfile AgentPoolProfile
aa := aliasAgentPoolProfile{}
if e := json.Unmarshal(b, &aa); e != nil {
return e
}
*a = AgentPoolProfile(aa)
if a.Count == 0 {
// if AgentPoolProfile.Count is missing or 0, set it to default 1
a.Count = 1
}
if a.StorageProfile == "" {
// if StorageProfile is missing, set to default ManagedDisks
a.StorageProfile = ManagedDisks
}
if string(a.OSType) == "" {
// OSType is the operating system type for agents
// Set as nullable to support backward compat because
// this property was added later.
// If the value is null or not set, it defaulted to Linux.
a.OSType = Linux
}
// OSDiskSizeGB is an override value. vm sizes have default OS disk sizes.
// If it is not set. The user should get the default for the vm size
return nil
}
// OSType represents OS types of agents
type OSType string
// HasWindows returns true if the cluster contains windows
func (a *Properties) HasWindows() bool {
for _, agentPoolProfile := range a.AgentPoolProfiles {
if agentPoolProfile.OSType == Windows {
return true
}
}
return false
}
// IsCustomVNET returns true if the customer brought their own VNET
func (a *AgentPoolProfile) IsCustomVNET() bool {
return len(a.VnetSubnetID) > 0
}
// IsWindows returns true if the agent pool is windows
func (a *AgentPoolProfile) IsWindows() bool {
return a.OSType == Windows
}
// IsLinux returns true if the agent pool is linux
func (a *AgentPoolProfile) IsLinux() bool {
return a.OSType == Linux
}
// GetSubnet returns the read-only subnet for the agent pool
func (a *AgentPoolProfile) GetSubnet() string {
return a.subnet
}
// SetSubnet sets the read-only subnet for the agent pool
func (a *AgentPoolProfile) SetSubnet(subnet string) {
a.subnet = subnet
}
// IsManagedDisks returns true if the customer specified managed disks
func (a *AgentPoolProfile) IsManagedDisks() bool {
return a.StorageProfile == ManagedDisks
}