forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converterfromagentpoolonlyapi.go
282 lines (257 loc) · 10.8 KB
/
converterfromagentpoolonlyapi.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
package api
import (
"strconv"
"github.com/Azure/acs-engine/pkg/api/agentPoolOnlyApi/v20170831"
"github.com/Azure/acs-engine/pkg/api/agentPoolOnlyApi/v20180331"
"github.com/Azure/acs-engine/pkg/helpers"
)
///////////////////////////////////////////////////////////
// The converter exposes functions to convert the top level
// ContainerService resource
//
// All other functions are internal helper functions used
// for converting.
///////////////////////////////////////////////////////////
// ConvertContainerServiceToV20170831AgentPoolOnly converts an unversioned ContainerService to a v20170831 ContainerService
func ConvertContainerServiceToV20170831AgentPoolOnly(api *ContainerService) *v20170831.ManagedCluster {
v20170831HCP := &v20170831.ManagedCluster{}
v20170831HCP.ID = api.ID
v20170831HCP.Location = api.Location
v20170831HCP.Name = api.Name
if api.Plan != nil {
v20170831HCP.Plan = &v20170831.ResourcePurchasePlan{}
convertResourcePurchasePlanToV20170831AgentPoolOnly(api.Plan, v20170831HCP.Plan)
}
v20170831HCP.Tags = map[string]string{}
for k, v := range api.Tags {
v20170831HCP.Tags[k] = v
}
v20170831HCP.Type = api.Type
v20170831HCP.Properties = &v20170831.Properties{}
convertPropertiesToV20170831AgentPoolOnly(api.Properties, v20170831HCP.Properties)
return v20170831HCP
}
// ConvertContainerServiceToV20180331AgentPoolOnly converts an unversioned ContainerService to a v20180331 ContainerService
func ConvertContainerServiceToV20180331AgentPoolOnly(api *ContainerService) *v20180331.ManagedCluster {
v20180331HCP := &v20180331.ManagedCluster{}
v20180331HCP.ID = api.ID
v20180331HCP.Location = api.Location
v20180331HCP.Name = api.Name
if api.Plan != nil {
v20180331HCP.Plan = &v20180331.ResourcePurchasePlan{}
convertResourcePurchasePlanToV20180331AgentPoolOnly(api.Plan, v20180331HCP.Plan)
}
v20180331HCP.Tags = map[string]string{}
for k, v := range api.Tags {
v20180331HCP.Tags[k] = v
}
v20180331HCP.Type = api.Type
v20180331HCP.Properties = &v20180331.Properties{}
convertPropertiesToV20180331AgentPoolOnly(api.Properties, v20180331HCP.Properties)
return v20180331HCP
}
// convertResourcePurchasePlanToV20170831 converts a v20170831 ResourcePurchasePlan to an unversioned ResourcePurchasePlan
func convertResourcePurchasePlanToV20170831AgentPoolOnly(api *ResourcePurchasePlan, v20170831 *v20170831.ResourcePurchasePlan) {
v20170831.Name = api.Name
v20170831.Product = api.Product
v20170831.PromotionCode = api.PromotionCode
v20170831.Publisher = api.Publisher
}
func convertPropertiesToV20170831AgentPoolOnly(api *Properties, p *v20170831.Properties) {
p.ProvisioningState = v20170831.ProvisioningState(api.ProvisioningState)
if api.OrchestratorProfile != nil {
if api.OrchestratorProfile.OrchestratorVersion != "" {
p.KubernetesVersion = api.OrchestratorProfile.OrchestratorVersion
}
}
if api.HostedMasterProfile != nil {
p.DNSPrefix = api.HostedMasterProfile.DNSPrefix
p.FQDN = api.HostedMasterProfile.FQDN
}
p.AgentPoolProfiles = []*v20170831.AgentPoolProfile{}
for _, apiProfile := range api.AgentPoolProfiles {
v20170831Profile := &v20170831.AgentPoolProfile{}
convertAgentPoolProfileToV20170831AgentPoolOnly(apiProfile, v20170831Profile)
p.AgentPoolProfiles = append(p.AgentPoolProfiles, v20170831Profile)
}
if api.LinuxProfile != nil {
p.LinuxProfile = &v20170831.LinuxProfile{}
convertLinuxProfileToV20170831AgentPoolOnly(api.LinuxProfile, p.LinuxProfile)
}
if api.WindowsProfile != nil {
p.WindowsProfile = &v20170831.WindowsProfile{}
convertWindowsProfileToV20170831AgentPoolOnly(api.WindowsProfile, p.WindowsProfile)
}
if api.ServicePrincipalProfile != nil {
p.ServicePrincipalProfile = &v20170831.ServicePrincipalProfile{}
convertServicePrincipalProfileToV20170831AgentPoolOnly(api.ServicePrincipalProfile, p.ServicePrincipalProfile)
}
}
func convertLinuxProfileToV20170831AgentPoolOnly(api *LinuxProfile, obj *v20170831.LinuxProfile) {
obj.AdminUsername = api.AdminUsername
obj.SSH.PublicKeys = []v20170831.PublicKey{}
for _, d := range api.SSH.PublicKeys {
obj.SSH.PublicKeys = append(obj.SSH.PublicKeys, v20170831.PublicKey{
KeyData: d.KeyData,
})
}
}
func convertWindowsProfileToV20170831AgentPoolOnly(api *WindowsProfile, v20170831Profile *v20170831.WindowsProfile) {
v20170831Profile.AdminUsername = api.AdminUsername
v20170831Profile.AdminPassword = api.AdminPassword
}
func convertAgentPoolProfileToV20170831AgentPoolOnly(api *AgentPoolProfile, p *v20170831.AgentPoolProfile) {
p.Name = api.Name
p.Count = api.Count
p.VMSize = api.VMSize
p.OSType = v20170831.OSType(api.OSType)
p.SetSubnet(api.Subnet)
p.OSDiskSizeGB = api.OSDiskSizeGB
p.StorageProfile = api.StorageProfile
p.VnetSubnetID = api.VnetSubnetID
}
func convertServicePrincipalProfileToV20170831AgentPoolOnly(api *ServicePrincipalProfile, v20170831 *v20170831.ServicePrincipalProfile) {
v20170831.ClientID = api.ClientID
v20170831.Secret = api.Secret
// v20170831.KeyvaultSecretRef = api.KeyvaultSecretRef
}
// convertResourcePurchasePlanToV20180331 converts a v20180331 ResourcePurchasePlan to an unversioned ResourcePurchasePlan
func convertResourcePurchasePlanToV20180331AgentPoolOnly(api *ResourcePurchasePlan, v20180331 *v20180331.ResourcePurchasePlan) {
v20180331.Name = api.Name
v20180331.Product = api.Product
v20180331.PromotionCode = api.PromotionCode
v20180331.Publisher = api.Publisher
}
func convertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(kc *KubernetesConfig) *bool {
if kc == nil {
return helpers.PointerToBool(false)
}
// We use KubernetesConfig.EnableRbac to convert to versioned api model
// The assumption here is KubernetesConfig.EnableSecureKubelet is set to be same
if kc != nil && kc.EnableRbac != nil && *kc.EnableRbac {
return helpers.PointerToBool(true)
}
return helpers.PointerToBool(false)
}
func convertPropertiesToV20180331AgentPoolOnly(api *Properties, p *v20180331.Properties) {
p.ProvisioningState = v20180331.ProvisioningState(api.ProvisioningState)
if api.OrchestratorProfile != nil {
p.EnableRBAC = convertKubernetesConfigToEnableRBACV20180331AgentPoolOnly(api.OrchestratorProfile.KubernetesConfig)
p.KubernetesVersion, p.NetworkProfile = convertOrchestratorProfileToV20180331AgentPoolOnly(api.OrchestratorProfile)
}
if api.HostedMasterProfile != nil {
p.DNSPrefix = api.HostedMasterProfile.DNSPrefix
p.FQDN = api.HostedMasterProfile.FQDN
}
p.AgentPoolProfiles = []*v20180331.AgentPoolProfile{}
for _, apiProfile := range api.AgentPoolProfiles {
v20180331Profile := &v20180331.AgentPoolProfile{}
convertAgentPoolProfileToV20180331AgentPoolOnly(apiProfile, v20180331Profile)
p.AgentPoolProfiles = append(p.AgentPoolProfiles, v20180331Profile)
}
if api.LinuxProfile != nil {
p.LinuxProfile = &v20180331.LinuxProfile{}
convertLinuxProfileToV20180331AgentPoolOnly(api.LinuxProfile, p.LinuxProfile)
}
if api.WindowsProfile != nil {
p.WindowsProfile = &v20180331.WindowsProfile{}
convertWindowsProfileToV20180331AgentPoolOnly(api.WindowsProfile, p.WindowsProfile)
}
if api.ServicePrincipalProfile != nil {
p.ServicePrincipalProfile = &v20180331.ServicePrincipalProfile{}
convertServicePrincipalProfileToV20180331AgentPoolOnly(api.ServicePrincipalProfile, p.ServicePrincipalProfile)
}
if api.AddonProfiles != nil {
p.AddonProfiles = make(map[string]v20180331.AddonProfile)
convertAddonsProfileToV20180331AgentPoolOnly(api.AddonProfiles, p.AddonProfiles)
}
if api.AADProfile != nil {
p.AADProfile = &v20180331.AADProfile{}
convertAADProfileToV20180331AgentPoolOnly(api.AADProfile, p.AADProfile)
}
}
func convertOrchestratorProfileToV20180331AgentPoolOnly(orchestratorProfile *OrchestratorProfile) (kubernetesVersion string, networkProfile *v20180331.NetworkProfile) {
if orchestratorProfile.OrchestratorVersion != "" {
kubernetesVersion = orchestratorProfile.OrchestratorVersion
}
if orchestratorProfile.KubernetesConfig != nil {
k := orchestratorProfile.KubernetesConfig
if k.NetworkPlugin != "" {
networkProfile = &v20180331.NetworkProfile{}
networkProfile.NetworkPlugin = v20180331.NetworkPlugin(k.NetworkPlugin)
networkProfile.NetworkPolicy = v20180331.NetworkPolicy(k.NetworkPolicy)
if k.NetworkPlugin == string(v20180331.Kubenet) {
networkProfile.PodCidr = k.ClusterSubnet
}
networkProfile.ServiceCidr = k.ServiceCIDR
networkProfile.DNSServiceIP = k.DNSServiceIP
networkProfile.DockerBridgeCidr = k.DockerBridgeSubnet
} else if k.NetworkPolicy != "" {
networkProfile = &v20180331.NetworkProfile{}
// ACS-E uses "none" in the old un-versioned model to represent kubenet.
if k.NetworkPolicy == "none" {
networkProfile.NetworkPlugin = v20180331.Kubenet
networkProfile.PodCidr = k.ClusterSubnet
} else {
networkProfile.NetworkPlugin = v20180331.NetworkPlugin(k.NetworkPolicy)
}
networkProfile.ServiceCidr = k.ServiceCIDR
networkProfile.DNSServiceIP = k.DNSServiceIP
networkProfile.DockerBridgeCidr = k.DockerBridgeSubnet
}
}
return kubernetesVersion, networkProfile
}
func convertLinuxProfileToV20180331AgentPoolOnly(api *LinuxProfile, obj *v20180331.LinuxProfile) {
obj.AdminUsername = api.AdminUsername
obj.SSH.PublicKeys = []v20180331.PublicKey{}
for _, d := range api.SSH.PublicKeys {
obj.SSH.PublicKeys = append(obj.SSH.PublicKeys, v20180331.PublicKey{
KeyData: d.KeyData,
})
}
}
func convertWindowsProfileToV20180331AgentPoolOnly(api *WindowsProfile, v20180331Profile *v20180331.WindowsProfile) {
v20180331Profile.AdminUsername = api.AdminUsername
v20180331Profile.AdminPassword = api.AdminPassword
}
func convertAgentPoolProfileToV20180331AgentPoolOnly(api *AgentPoolProfile, p *v20180331.AgentPoolProfile) {
p.Name = api.Name
p.Count = api.Count
p.VMSize = api.VMSize
p.OSType = v20180331.OSType(api.OSType)
p.SetSubnet(api.Subnet)
p.OSDiskSizeGB = api.OSDiskSizeGB
p.StorageProfile = api.StorageProfile
p.VnetSubnetID = api.VnetSubnetID
if api.KubernetesConfig != nil && api.KubernetesConfig.KubeletConfig != nil {
if maxPods, ok := api.KubernetesConfig.KubeletConfig["--max-pods"]; ok {
agentPoolMaxPods, _ := strconv.Atoi(maxPods)
p.MaxPods = &agentPoolMaxPods
}
}
}
func convertServicePrincipalProfileToV20180331AgentPoolOnly(api *ServicePrincipalProfile, v20180331 *v20180331.ServicePrincipalProfile) {
v20180331.ClientID = api.ClientID
v20180331.Secret = api.Secret
// v20180331.KeyvaultSecretRef = api.KeyvaultSecretRef
}
func convertAddonsProfileToV20180331AgentPoolOnly(api map[string]AddonProfile, p map[string]v20180331.AddonProfile) {
if api == nil {
return
}
for k, v := range api {
p[k] = v20180331.AddonProfile{
Enabled: v.Enabled,
Config: v.Config,
}
}
}
func convertAADProfileToV20180331AgentPoolOnly(api *AADProfile, v20180331 *v20180331.AADProfile) {
v20180331.ClientAppID = api.ClientAppID
v20180331.ServerAppID = api.ServerAppID
v20180331.TenantID = api.TenantID
if api.Authenticator == Webhook {
v20180331.ServerAppSecret = api.ServerAppSecret
}
}