forked from Azure/aks-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
239 lines (204 loc) · 8.79 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package v20170831
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" validate:"required"`
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"`
}
// 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"`
// 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"`
}
// 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
}