forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
converterfromagentpoolonlyapi.go
211 lines (193 loc) · 8.12 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
package api
import "github.com/Azure/acs-engine/pkg/api/agentPoolOnlyApi/v20170831"
import "github.com/Azure/acs-engine/pkg/api/agentPoolOnlyApi/v20180331"
///////////////////////////////////////////////////////////
// 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 convertPropertiesToV20180331AgentPoolOnly(api *Properties, p *v20180331.Properties) {
p.ProvisioningState = v20180331.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 = []*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)
}
}
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
}
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,
}
}
}