This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 526
/
convertertoapi.go
788 lines (735 loc) · 31.9 KB
/
convertertoapi.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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package api
import (
"github.com/Azure/aks-engine/pkg/api/common"
"github.com/Azure/aks-engine/pkg/api/vlabs"
"github.com/Azure/aks-engine/pkg/helpers"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/to"
)
///////////////////////////////////////////////////////////
// The converter exposes functions to convert the top level
// ContainerService resource
//
// All other functions are internal helper functions used
// for converting.
///////////////////////////////////////////////////////////
// ConvertVLabsContainerService converts a vlabs ContainerService to an unversioned ContainerService
func ConvertVLabsContainerService(vlabs *vlabs.ContainerService, isUpdate bool) (*ContainerService, error) {
c := &ContainerService{}
c.ID = vlabs.ID
c.Location = helpers.NormalizeAzureRegion(vlabs.Location)
c.Name = vlabs.Name
if vlabs.Plan != nil {
c.Plan = &ResourcePurchasePlan{}
convertVLabsResourcePurchasePlan(vlabs.Plan, c.Plan)
}
c.Tags = map[string]string{}
for k, v := range vlabs.Tags {
c.Tags[k] = v
}
c.Type = vlabs.Type
c.Properties = &Properties{}
if err := convertVLabsProperties(vlabs.Properties, c.Properties, isUpdate); err != nil {
return nil, err
}
return c, nil
}
// convertVLabsResourcePurchasePlan converts a vlabs ResourcePurchasePlan to an unversioned ResourcePurchasePlan
func convertVLabsResourcePurchasePlan(vlabs *vlabs.ResourcePurchasePlan, api *ResourcePurchasePlan) {
api.Name = vlabs.Name
api.Product = vlabs.Product
api.PromotionCode = vlabs.PromotionCode
api.Publisher = vlabs.Publisher
}
func convertVLabsProperties(vlabs *vlabs.Properties, api *Properties, isUpdate bool) error {
api.ProvisioningState = ProvisioningState(vlabs.ProvisioningState)
if vlabs.OrchestratorProfile != nil {
api.OrchestratorProfile = &OrchestratorProfile{}
if err := convertVLabsOrchestratorProfile(vlabs, api.OrchestratorProfile, isUpdate); err != nil {
return err
}
}
if vlabs.MasterProfile != nil {
api.MasterProfile = &MasterProfile{}
convertVLabsMasterProfile(vlabs.MasterProfile, api.MasterProfile)
}
api.AgentPoolProfiles = []*AgentPoolProfile{}
for _, p := range vlabs.AgentPoolProfiles {
apiProfile := &AgentPoolProfile{}
convertVLabsAgentPoolProfile(p, apiProfile)
api.AgentPoolProfiles = append(api.AgentPoolProfiles, apiProfile)
}
if vlabs.LinuxProfile != nil {
api.LinuxProfile = &LinuxProfile{}
convertVLabsLinuxProfile(vlabs.LinuxProfile, api.LinuxProfile)
}
api.ExtensionProfiles = []*ExtensionProfile{}
for _, p := range vlabs.ExtensionProfiles {
apiExtensionProfile := &ExtensionProfile{}
convertVLabsExtensionProfile(p, apiExtensionProfile)
api.ExtensionProfiles = append(api.ExtensionProfiles, apiExtensionProfile)
}
if vlabs.WindowsProfile != nil {
api.WindowsProfile = &WindowsProfile{}
convertVLabsWindowsProfile(vlabs.WindowsProfile, api.WindowsProfile)
}
if vlabs.ServicePrincipalProfile != nil {
api.ServicePrincipalProfile = &ServicePrincipalProfile{}
convertVLabsServicePrincipalProfile(vlabs.ServicePrincipalProfile, api.ServicePrincipalProfile)
}
if vlabs.CertificateProfile != nil {
api.CertificateProfile = &CertificateProfile{}
convertVLabsCertificateProfile(vlabs.CertificateProfile, api.CertificateProfile)
}
if vlabs.AADProfile != nil {
api.AADProfile = &AADProfile{}
convertVLabsAADProfile(vlabs.AADProfile, api.AADProfile)
}
if vlabs.FeatureFlags != nil {
api.FeatureFlags = &FeatureFlags{}
convertVLabsFeatureFlags(vlabs.FeatureFlags, api.FeatureFlags)
}
if vlabs.CustomCloudProfile != nil {
api.CustomCloudProfile = &CustomCloudProfile{}
convertVLabsCustomCloudProfile(vlabs.CustomCloudProfile, api.CustomCloudProfile)
}
if vlabs.TelemetryProfile != nil {
api.TelemetryProfile = &TelemetryProfile{}
convertVLabsTelemetryProfile(vlabs.TelemetryProfile, api.TelemetryProfile)
}
return nil
}
func convertVLabsFeatureFlags(vlabs *vlabs.FeatureFlags, api *FeatureFlags) {
api.EnableCSERunInBackground = vlabs.EnableCSERunInBackground
api.BlockOutboundInternet = vlabs.BlockOutboundInternet
api.EnableIPv6DualStack = vlabs.EnableIPv6DualStack
api.EnableTelemetry = vlabs.EnableTelemetry
api.EnableIPv6Only = vlabs.EnableIPv6Only
api.EnableWinDSR = vlabs.EnableWinDSR
}
func convertVLabsExtensionProfile(vlabs *vlabs.ExtensionProfile, api *ExtensionProfile) {
api.Name = vlabs.Name
api.Version = vlabs.Version
api.ExtensionParameters = vlabs.ExtensionParameters
if vlabs.ExtensionParametersKeyVaultRef != nil {
api.ExtensionParametersKeyVaultRef = &KeyvaultSecretRef{
VaultID: vlabs.ExtensionParametersKeyVaultRef.VaultID,
SecretName: vlabs.ExtensionParametersKeyVaultRef.SecretName,
SecretVersion: vlabs.ExtensionParametersKeyVaultRef.SecretVersion,
}
}
api.RootURL = vlabs.RootURL
api.Script = vlabs.Script
api.URLQuery = vlabs.URLQuery
}
func convertVLabsExtension(vlabs *vlabs.Extension, api *Extension) {
api.Name = vlabs.Name
api.SingleOrAll = vlabs.SingleOrAll
api.Template = vlabs.Template
}
func convertVLabsLinuxProfile(vlabs *vlabs.LinuxProfile, api *LinuxProfile) {
api.AdminUsername = vlabs.AdminUsername
api.SSH.PublicKeys = []PublicKey{}
for _, d := range vlabs.SSH.PublicKeys {
api.SSH.PublicKeys = append(api.SSH.PublicKeys,
PublicKey{KeyData: d.KeyData})
}
api.Secrets = []KeyVaultSecrets{}
for _, s := range vlabs.Secrets {
secret := &KeyVaultSecrets{}
convertVLabsKeyVaultSecrets(&s, secret)
api.Secrets = append(api.Secrets, *secret)
}
api.ScriptRootURL = vlabs.ScriptRootURL
if vlabs.CustomSearchDomain != nil {
api.CustomSearchDomain = &CustomSearchDomain{}
api.CustomSearchDomain.Name = vlabs.CustomSearchDomain.Name
api.CustomSearchDomain.RealmUser = vlabs.CustomSearchDomain.RealmUser
api.CustomSearchDomain.RealmPassword = vlabs.CustomSearchDomain.RealmPassword
}
if vlabs.CustomNodesDNS != nil {
api.CustomNodesDNS = &CustomNodesDNS{}
api.CustomNodesDNS.DNSServer = vlabs.CustomNodesDNS.DNSServer
}
api.RunUnattendedUpgradesOnBootstrap = vlabs.RunUnattendedUpgradesOnBootstrap
api.Eth0MTU = vlabs.Eth0MTU
}
func convertVLabsWindowsProfile(vlabs *vlabs.WindowsProfile, api *WindowsProfile) {
api.AdminUsername = vlabs.AdminUsername
api.AdminPassword = vlabs.AdminPassword
api.CSIProxyURL = vlabs.CSIProxyURL
api.EnableCSIProxy = vlabs.EnableCSIProxy
if vlabs.ImageRef != nil {
api.ImageRef = &ImageReference{}
api.ImageRef.Gallery = vlabs.ImageRef.Gallery
api.ImageRef.Name = vlabs.ImageRef.Name
api.ImageRef.ResourceGroup = vlabs.ImageRef.ResourceGroup
api.ImageRef.SubscriptionID = vlabs.ImageRef.SubscriptionID
api.ImageRef.Version = vlabs.ImageRef.Version
}
api.ImageVersion = vlabs.ImageVersion
api.ProvisioningScriptsPackageURL = vlabs.ProvisioningScriptsPackageURL
api.WindowsPauseImageURL = vlabs.WindowsPauseImageURL
api.WindowsImageSourceURL = vlabs.WindowsImageSourceURL
api.WindowsPublisher = vlabs.WindowsPublisher
api.WindowsOffer = vlabs.WindowsOffer
api.WindowsSku = vlabs.WindowsSku
api.WindowsDockerVersion = vlabs.WindowsDockerVersion
api.Secrets = []KeyVaultSecrets{}
for _, s := range vlabs.Secrets {
secret := &KeyVaultSecrets{}
convertVLabsKeyVaultSecrets(&s, secret)
api.Secrets = append(api.Secrets, *secret)
}
if vlabs.SSHEnabled != nil {
api.SSHEnabled = vlabs.SSHEnabled
}
api.EnableAutomaticUpdates = vlabs.EnableAutomaticUpdates
if vlabs.EnableAHUB != nil && *vlabs.EnableAHUB {
api.EnableAHUB = to.BoolPtr(true)
}
api.AlwaysPullWindowsPauseImage = vlabs.AlwaysPullWindowsPauseImage
if vlabs.WindowsRuntimes != nil {
api.WindowsRuntimes = &WindowsRuntimes{}
api.WindowsRuntimes.Default = vlabs.WindowsRuntimes.Default
api.WindowsRuntimes.HypervRuntimes = []RuntimeHandlers{}
for _, h := range vlabs.WindowsRuntimes.HypervRuntimes {
handler := RuntimeHandlers{}
handler.BuildNumber = h.BuildNumber
api.WindowsRuntimes.HypervRuntimes = append(api.WindowsRuntimes.HypervRuntimes, handler)
}
}
api.WindowsSecureTLSEnabled = vlabs.WindowsSecureTLSEnabled
}
func convertVLabsOrchestratorProfile(vp *vlabs.Properties, api *OrchestratorProfile, isUpdate bool) error {
vlabscs := vp.OrchestratorProfile
// OrchestratorType is a legacy property when non-Kubernetes orchestrators were supported
api.OrchestratorType = Kubernetes
if vlabscs.KubernetesConfig != nil {
api.KubernetesConfig = &KubernetesConfig{}
convertVLabsKubernetesConfig(vlabscs.KubernetesConfig, api.KubernetesConfig)
}
setVlabsKubernetesDefaults(vp, api)
// TODO (hack): this validation should be done as part of the main validation, but deploy does it only after loading the container.
if !isUpdate {
if err := vp.ValidateOrchestratorProfile(isUpdate); err != nil {
return err
}
}
api.OrchestratorVersion = common.RationalizeReleaseAndVersion(
vlabscs.OrchestratorType,
vlabscs.OrchestratorRelease,
vlabscs.OrchestratorVersion,
isUpdate,
vp.HasWindows(),
vp.IsAzureStackCloud())
return nil
}
func convertVLabsKubernetesConfig(vlabs *vlabs.KubernetesConfig, api *KubernetesConfig) {
api.KubernetesImageBase = vlabs.KubernetesImageBase
api.KubernetesImageBaseType = vlabs.KubernetesImageBaseType
api.MCRKubernetesImageBase = vlabs.MCRKubernetesImageBase
api.ClusterSubnet = vlabs.ClusterSubnet
api.DNSServiceIP = vlabs.DNSServiceIP
api.ServiceCIDR = vlabs.ServiceCidr
api.NetworkPlugin = vlabs.NetworkPlugin
api.NetworkMode = vlabs.NetworkMode
api.ContainerRuntime = vlabs.ContainerRuntime
api.MaxPods = vlabs.MaxPods
api.DockerBridgeSubnet = vlabs.DockerBridgeSubnet
api.MobyVersion = vlabs.MobyVersion
api.LinuxMobyURL = vlabs.LinuxMobyURL
api.LinuxRuncURL = vlabs.LinuxRuncURL
api.ContainerdVersion = vlabs.ContainerdVersion
api.LinuxContainerdURL = vlabs.LinuxContainerdURL
api.CloudProviderBackoff = vlabs.CloudProviderBackoff
api.CloudProviderBackoffMode = vlabs.CloudProviderBackoffMode
api.CloudProviderBackoffDuration = vlabs.CloudProviderBackoffDuration
api.CloudProviderBackoffExponent = vlabs.CloudProviderBackoffExponent
api.CloudProviderBackoffJitter = vlabs.CloudProviderBackoffJitter
api.CloudProviderBackoffRetries = vlabs.CloudProviderBackoffRetries
api.CloudProviderRateLimit = vlabs.CloudProviderRateLimit
api.CloudProviderRateLimitBucket = vlabs.CloudProviderRateLimitBucket
api.CloudProviderRateLimitBucketWrite = vlabs.CloudProviderRateLimitBucketWrite
api.CloudProviderRateLimitQPS = vlabs.CloudProviderRateLimitQPS
api.CloudProviderRateLimitQPSWrite = vlabs.CloudProviderRateLimitQPSWrite
api.UseManagedIdentity = vlabs.UseManagedIdentity
api.UserAssignedID = vlabs.UserAssignedID
api.UserAssignedClientID = vlabs.UserAssignedClientID
api.CustomHyperkubeImage = vlabs.CustomHyperkubeImage
api.CustomKubeAPIServerImage = vlabs.CustomKubeAPIServerImage
api.CustomKubeControllerManagerImage = vlabs.CustomKubeControllerManagerImage
api.CustomKubeProxyImage = vlabs.CustomKubeProxyImage
api.CustomKubeSchedulerImage = vlabs.CustomKubeSchedulerImage
api.CustomKubeBinaryURL = vlabs.CustomKubeBinaryURL
api.CustomCcmImage = vlabs.CustomCcmImage
api.UseCloudControllerManager = vlabs.UseCloudControllerManager
api.CustomWindowsPackageURL = vlabs.CustomWindowsPackageURL
api.WindowsNodeBinariesURL = vlabs.WindowsNodeBinariesURL
api.WindowsContainerdURL = vlabs.WindowsContainerdURL
api.WindowsSdnPluginURL = vlabs.WindowsSdnPluginURL
api.UseInstanceMetadata = vlabs.UseInstanceMetadata
api.LoadBalancerSku = vlabs.LoadBalancerSku
api.ExcludeMasterFromStandardLB = vlabs.ExcludeMasterFromStandardLB
api.LoadBalancerOutboundIPs = vlabs.LoadBalancerOutboundIPs
api.EnableRbac = vlabs.EnableRbac
api.EnableSecureKubelet = vlabs.EnableSecureKubelet
api.EnableAggregatedAPIs = vlabs.EnableAggregatedAPIs
api.EnableDataEncryptionAtRest = vlabs.EnableDataEncryptionAtRest
api.EnableEncryptionWithExternalKms = vlabs.EnableEncryptionWithExternalKms
api.EnablePodSecurityPolicy = vlabs.EnablePodSecurityPolicy
api.GCHighThreshold = vlabs.GCHighThreshold
api.GCLowThreshold = vlabs.GCLowThreshold
api.EtcdVersion = vlabs.EtcdVersion
api.EtcdDiskSizeGB = vlabs.EtcdDiskSizeGB
api.EtcdStorageLimitGB = vlabs.EtcdStorageLimitGB
api.EtcdEncryptionKey = vlabs.EtcdEncryptionKey
api.AzureCNIVersion = vlabs.AzureCNIVersion
api.AzureCNIURLLinux = vlabs.AzureCNIURLLinux
api.AzureCNIURLWindows = vlabs.AzureCNIURLWindows
api.KeyVaultSku = vlabs.KeyVaultSku
api.MaximumLoadBalancerRuleCount = vlabs.MaximumLoadBalancerRuleCount
api.ProxyMode = KubeProxyMode(vlabs.ProxyMode)
api.PrivateAzureRegistryServer = vlabs.PrivateAzureRegistryServer
api.OutboundRuleIdleTimeoutInMinutes = vlabs.OutboundRuleIdleTimeoutInMinutes
api.CloudProviderDisableOutboundSNAT = vlabs.CloudProviderDisableOutboundSNAT
api.KubeReservedCgroup = vlabs.KubeReservedCgroup
api.MicrosoftAptRepositoryURL = vlabs.MicrosoftAptRepositoryURL
api.EnableMultipleStandardLoadBalancers = vlabs.EnableMultipleStandardLoadBalancers
api.Tags = vlabs.Tags
convertComponentsToAPI(vlabs, api)
convertAddonsToAPI(vlabs, api)
convertKubeletConfigToAPI(vlabs, api)
convertControllerManagerConfigToAPI(vlabs, api)
convertCloudControllerManagerConfigToAPI(vlabs, api)
convertAPIServerConfigToAPI(vlabs, api)
convertSchedulerConfigToAPI(vlabs, api)
convertPrivateClusterToAPI(vlabs, api)
convertPodSecurityPolicyConfigToAPI(vlabs, api)
convertContainerRuntimeConfigToAPI(vlabs, api)
}
func setVlabsKubernetesDefaults(vp *vlabs.Properties, api *OrchestratorProfile) {
if api.KubernetesConfig == nil {
api.KubernetesConfig = &KubernetesConfig{}
}
if vp.OrchestratorProfile.KubernetesConfig != nil {
// Included here for backwards compatibility with deprecated NetworkPolicy usage patterns
if vp.OrchestratorProfile.KubernetesConfig.NetworkPlugin == "" &&
vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyAzure {
api.KubernetesConfig.NetworkPlugin = vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy
api.KubernetesConfig.NetworkPolicy = "" // no-op but included for emphasis
} else if vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy == NetworkPolicyNone {
api.KubernetesConfig.NetworkPlugin = NetworkPluginKubenet
api.KubernetesConfig.NetworkPolicy = "" // no-op but included for emphasis
} else {
api.KubernetesConfig.NetworkPlugin = vp.OrchestratorProfile.KubernetesConfig.NetworkPlugin
api.KubernetesConfig.NetworkPolicy = vp.OrchestratorProfile.KubernetesConfig.NetworkPolicy
}
}
if api.KubernetesConfig.NetworkPlugin == "" && (api.KubernetesConfig.NetworkPolicy == "" || api.KubernetesConfig.NetworkPolicy == NetworkPolicyCalico) {
if vp.HasWindows() {
api.KubernetesConfig.NetworkPlugin = vlabs.DefaultNetworkPluginWindows
} else {
api.KubernetesConfig.NetworkPlugin = vlabs.DefaultNetworkPlugin
}
}
}
func convertComponentsToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.Components = []KubernetesComponent{}
for i := range v.Components {
a.Components = append(a.Components, KubernetesComponent{
Name: v.Components[i].Name,
Enabled: v.Components[i].Enabled,
Config: map[string]string{},
Data: v.Components[i].Data,
})
for j := range v.Components[i].Containers {
a.Components[i].Containers = append(a.Components[i].Containers, KubernetesContainerSpec{
Name: v.Components[i].Containers[j].Name,
Image: v.Components[i].Containers[j].Image,
CPURequests: v.Components[i].Containers[j].CPURequests,
MemoryRequests: v.Components[i].Containers[j].MemoryRequests,
CPULimits: v.Components[i].Containers[j].CPULimits,
MemoryLimits: v.Components[i].Containers[j].MemoryLimits,
})
}
if v.Components[i].Config != nil {
for key, val := range v.Components[i].Config {
a.Components[i].Config[key] = val
}
}
}
}
func convertAddonsToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.Addons = []KubernetesAddon{}
for i := range v.Addons {
a.Addons = append(a.Addons, KubernetesAddon{
Name: v.Addons[i].Name,
Enabled: v.Addons[i].Enabled,
Mode: v.Addons[i].Mode,
Config: map[string]string{},
Data: v.Addons[i].Data,
})
for j := range v.Addons[i].Containers {
a.Addons[i].Containers = append(a.Addons[i].Containers, KubernetesContainerSpec{
Name: v.Addons[i].Containers[j].Name,
Image: v.Addons[i].Containers[j].Image,
CPURequests: v.Addons[i].Containers[j].CPURequests,
MemoryRequests: v.Addons[i].Containers[j].MemoryRequests,
CPULimits: v.Addons[i].Containers[j].CPULimits,
MemoryLimits: v.Addons[i].Containers[j].MemoryLimits,
})
}
for k := range v.Addons[i].Pools {
a.Addons[i].Pools = append(a.Addons[i].Pools, AddonNodePoolsConfig{
Name: v.Addons[i].Pools[k].Name,
Config: map[string]string{},
})
if v.Addons[i].Pools[k].Config != nil {
for key, val := range v.Addons[i].Pools[k].Config {
a.Addons[i].Pools[k].Config[key] = val
}
}
}
if v.Addons[i].Config != nil {
for key, val := range v.Addons[i].Config {
a.Addons[i].Config[key] = val
}
}
}
}
func convertCustomFilesToAPI(v *vlabs.MasterProfile, a *MasterProfile) {
if v.CustomFiles != nil {
a.CustomFiles = &[]CustomFile{}
for i := range *v.CustomFiles {
*a.CustomFiles = append(*a.CustomFiles, CustomFile{
Dest: (*v.CustomFiles)[i].Dest,
Source: (*v.CustomFiles)[i].Source,
})
}
}
}
func convertContainerRuntimeConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.ContainerRuntimeConfig = map[string]string{}
for key, val := range v.ContainerRuntimeConfig {
a.ContainerRuntimeConfig[key] = val
}
}
func convertKubeletConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.KubeletConfig = map[string]string{}
for key, val := range v.KubeletConfig {
a.KubeletConfig[key] = val
}
}
func convertControllerManagerConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.ControllerManagerConfig = map[string]string{}
for key, val := range v.ControllerManagerConfig {
a.ControllerManagerConfig[key] = val
}
}
func convertCloudControllerManagerConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.CloudControllerManagerConfig = map[string]string{}
for key, val := range v.CloudControllerManagerConfig {
a.CloudControllerManagerConfig[key] = val
}
}
func convertAPIServerConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.APIServerConfig = map[string]string{}
for key, val := range v.APIServerConfig {
a.APIServerConfig[key] = val
}
}
func convertSchedulerConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.SchedulerConfig = map[string]string{}
for key, val := range v.SchedulerConfig {
a.SchedulerConfig[key] = val
}
}
func convertPodSecurityPolicyConfigToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
a.PodSecurityPolicyConfig = map[string]string{}
for key, val := range v.PodSecurityPolicyConfig {
a.PodSecurityPolicyConfig[key] = val
}
}
func convertPrivateClusterToAPI(v *vlabs.KubernetesConfig, a *KubernetesConfig) {
if v.PrivateCluster != nil {
a.PrivateCluster = &PrivateCluster{}
a.PrivateCluster.Enabled = v.PrivateCluster.Enabled
a.PrivateCluster.EnableHostsConfigAgent = v.PrivateCluster.EnableHostsConfigAgent
if v.PrivateCluster.JumpboxProfile != nil {
a.PrivateCluster.JumpboxProfile = &PrivateJumpboxProfile{}
convertPrivateJumpboxProfileToAPI(v.PrivateCluster.JumpboxProfile, a.PrivateCluster.JumpboxProfile)
}
}
}
func convertPrivateJumpboxProfileToAPI(v *vlabs.PrivateJumpboxProfile, a *PrivateJumpboxProfile) {
a.Name = v.Name
a.OSDiskSizeGB = v.OSDiskSizeGB
a.VMSize = v.VMSize
a.PublicKey = v.PublicKey
a.Username = v.Username
a.StorageProfile = v.StorageProfile
}
func convertVLabsMasterProfile(vlabs *vlabs.MasterProfile, api *MasterProfile) {
api.Count = vlabs.Count
api.DNSPrefix = vlabs.DNSPrefix
api.SubjectAltNames = vlabs.SubjectAltNames
api.VMSize = vlabs.VMSize
api.CustomVMTags = vlabs.CustomVMTags
api.OSDiskSizeGB = vlabs.OSDiskSizeGB
api.VnetSubnetID = vlabs.VnetSubnetID
api.AgentVnetSubnetID = vlabs.AgentVnetSubnetID
api.FirstConsecutiveStaticIP = vlabs.FirstConsecutiveStaticIP
api.VnetCidr = vlabs.VnetCidr
api.Subnet = vlabs.GetSubnet()
api.SubnetIPv6 = vlabs.GetSubnetIPv6()
api.IPAddressCount = vlabs.IPAddressCount
api.FQDN = vlabs.FQDN
api.StorageProfile = vlabs.StorageProfile
api.HTTPSourceAddressPrefix = vlabs.HTTPSourceAddressPrefix
api.OAuthEnabled = vlabs.OAuthEnabled
// by default vlabs will use managed disks as it has encryption at rest
if len(api.StorageProfile) == 0 {
api.StorageProfile = ManagedDisks
}
if vlabs.PreProvisionExtension != nil {
apiExtension := &Extension{}
convertVLabsExtension(vlabs.PreProvisionExtension, apiExtension)
api.PreprovisionExtension = apiExtension
}
api.Extensions = []Extension{}
for _, extension := range vlabs.Extensions {
apiExtension := &Extension{}
convertVLabsExtension(&extension, apiExtension)
api.Extensions = append(api.Extensions, *apiExtension)
}
api.Distro = Distro(vlabs.Distro)
if vlabs.KubernetesConfig != nil {
api.KubernetesConfig = &KubernetesConfig{}
convertVLabsKubernetesConfig(vlabs.KubernetesConfig, api.KubernetesConfig)
}
if vlabs.ImageRef != nil {
api.ImageRef = &ImageReference{}
api.ImageRef.Name = vlabs.ImageRef.Name
api.ImageRef.ResourceGroup = vlabs.ImageRef.ResourceGroup
api.ImageRef.SubscriptionID = vlabs.ImageRef.SubscriptionID
api.ImageRef.Gallery = vlabs.ImageRef.Gallery
api.ImageRef.Version = vlabs.ImageRef.Version
}
api.AvailabilityProfile = vlabs.AvailabilityProfile
api.AgentSubnet = vlabs.AgentSubnet
api.AvailabilityZones = vlabs.AvailabilityZones
api.PlatformFaultDomainCount = vlabs.PlatformFaultDomainCount
api.PlatformUpdateDomainCount = vlabs.PlatformUpdateDomainCount
api.SinglePlacementGroup = vlabs.SinglePlacementGroup
api.CosmosEtcd = vlabs.CosmosEtcd
api.UltraSSDEnabled = vlabs.UltraSSDEnabled
api.EncryptionAtHost = vlabs.EncryptionAtHost
api.AuditDEnabled = vlabs.AuditDEnabled
api.ProximityPlacementGroupID = vlabs.ProximityPlacementGroupID
api.OSDiskCachingType = vlabs.OSDiskCachingType
convertCustomFilesToAPI(vlabs, api)
api.SysctlDConfig = map[string]string{}
for key, val := range vlabs.SysctlDConfig {
api.SysctlDConfig[key] = val
}
}
func convertVLabsAgentPoolProfile(vlabs *vlabs.AgentPoolProfile, api *AgentPoolProfile) {
api.Name = vlabs.Name
api.Count = vlabs.Count
api.VMSize = vlabs.VMSize
api.CustomVMTags = vlabs.CustomVMTags
api.OSDiskSizeGB = vlabs.OSDiskSizeGB
api.DNSPrefix = vlabs.DNSPrefix
api.OSType = OSType(vlabs.OSType)
api.Ports = []int{}
api.Ports = append(api.Ports, vlabs.Ports...)
api.AvailabilityProfile = vlabs.AvailabilityProfile
api.ScaleSetPriority = vlabs.ScaleSetPriority
api.ScaleSetEvictionPolicy = vlabs.ScaleSetEvictionPolicy
api.SpotMaxPrice = vlabs.SpotMaxPrice
api.StorageProfile = vlabs.StorageProfile
api.DiskSizesGB = []int{}
api.DiskSizesGB = append(api.DiskSizesGB, vlabs.DiskSizesGB...)
api.VnetSubnetID = vlabs.VnetSubnetID
api.Subnet = vlabs.GetSubnet()
api.IPAddressCount = vlabs.IPAddressCount
api.FQDN = vlabs.FQDN
api.AcceleratedNetworkingEnabled = vlabs.AcceleratedNetworkingEnabled
api.AcceleratedNetworkingEnabledWindows = vlabs.AcceleratedNetworkingEnabledWindows
api.VMSSOverProvisioningEnabled = vlabs.VMSSOverProvisioningEnabled
api.AvailabilityZones = vlabs.AvailabilityZones
api.PlatformFaultDomainCount = vlabs.PlatformFaultDomainCount
api.PlatformUpdateDomainCount = vlabs.PlatformUpdateDomainCount
api.SinglePlacementGroup = vlabs.SinglePlacementGroup
api.EnableVMSSNodePublicIP = vlabs.EnableVMSSNodePublicIP
api.LoadBalancerBackendAddressPoolIDs = vlabs.LoadBalancerBackendAddressPoolIDs
api.AuditDEnabled = vlabs.AuditDEnabled
api.DiskEncryptionSetID = vlabs.DiskEncryptionSetID
api.UltraSSDEnabled = vlabs.UltraSSDEnabled
api.EncryptionAtHost = vlabs.EncryptionAtHost
api.ProximityPlacementGroupID = vlabs.ProximityPlacementGroupID
api.CustomNodeLabels = map[string]string{}
for k, v := range vlabs.CustomNodeLabels {
api.CustomNodeLabels[k] = v
}
if vlabs.PreProvisionExtension != nil {
apiExtension := &Extension{}
convertVLabsExtension(vlabs.PreProvisionExtension, apiExtension)
api.PreprovisionExtension = apiExtension
}
api.Extensions = []Extension{}
for _, extension := range vlabs.Extensions {
apiExtension := &Extension{}
convertVLabsExtension(&extension, apiExtension)
api.Extensions = append(api.Extensions, *apiExtension)
}
api.Distro = Distro(vlabs.Distro)
if vlabs.KubernetesConfig != nil {
api.KubernetesConfig = &KubernetesConfig{}
convertVLabsKubernetesConfig(vlabs.KubernetesConfig, api.KubernetesConfig)
}
if vlabs.ImageRef != nil {
api.ImageRef = &ImageReference{}
api.ImageRef.Name = vlabs.ImageRef.Name
api.ImageRef.ResourceGroup = vlabs.ImageRef.ResourceGroup
api.ImageRef.SubscriptionID = vlabs.ImageRef.SubscriptionID
api.ImageRef.Gallery = vlabs.ImageRef.Gallery
api.ImageRef.Version = vlabs.ImageRef.Version
}
api.Role = AgentPoolProfileRole(vlabs.Role)
api.SysctlDConfig = map[string]string{}
for key, val := range vlabs.SysctlDConfig {
api.SysctlDConfig[key] = val
}
api.OSDiskCachingType = vlabs.OSDiskCachingType
api.DataDiskCachingType = vlabs.DataDiskCachingType
api.VMSSName = vlabs.VMSSName
}
func convertVLabsKeyVaultSecrets(vlabs *vlabs.KeyVaultSecrets, api *KeyVaultSecrets) {
api.SourceVault = &KeyVaultID{ID: vlabs.SourceVault.ID}
api.VaultCertificates = []KeyVaultCertificate{}
for _, c := range vlabs.VaultCertificates {
cert := KeyVaultCertificate{}
cert.CertificateStore = c.CertificateStore
cert.CertificateURL = c.CertificateURL
api.VaultCertificates = append(api.VaultCertificates, cert)
}
}
func convertVLabsServicePrincipalProfile(vlabs *vlabs.ServicePrincipalProfile, api *ServicePrincipalProfile) {
api.ClientID = vlabs.ClientID
api.Secret = vlabs.Secret
api.ObjectID = vlabs.ObjectID
if vlabs.KeyvaultSecretRef != nil {
api.KeyvaultSecretRef = &KeyvaultSecretRef{
VaultID: vlabs.KeyvaultSecretRef.VaultID,
SecretName: vlabs.KeyvaultSecretRef.SecretName,
SecretVersion: vlabs.KeyvaultSecretRef.SecretVersion,
}
}
}
func convertVLabsCertificateProfile(vlabs *vlabs.CertificateProfile, api *CertificateProfile) {
api.CaCertificate = vlabs.CaCertificate
api.CaPrivateKey = vlabs.CaPrivateKey
api.APIServerCertificate = vlabs.APIServerCertificate
api.APIServerPrivateKey = vlabs.APIServerPrivateKey
api.ClientCertificate = vlabs.ClientCertificate
api.ClientPrivateKey = vlabs.ClientPrivateKey
api.KubeConfigCertificate = vlabs.KubeConfigCertificate
api.KubeConfigPrivateKey = vlabs.KubeConfigPrivateKey
api.EtcdServerCertificate = vlabs.EtcdServerCertificate
api.EtcdServerPrivateKey = vlabs.EtcdServerPrivateKey
api.EtcdClientCertificate = vlabs.EtcdClientCertificate
api.EtcdClientPrivateKey = vlabs.EtcdClientPrivateKey
api.EtcdPeerCertificates = vlabs.EtcdPeerCertificates
api.EtcdPeerPrivateKeys = vlabs.EtcdPeerPrivateKeys
}
func convertVLabsAADProfile(vlabs *vlabs.AADProfile, api *AADProfile) {
api.ClientAppID = vlabs.ClientAppID
api.ServerAppID = vlabs.ServerAppID
api.TenantID = vlabs.TenantID
api.AdminGroupID = vlabs.AdminGroupID
api.Authenticator = OIDC
}
func convertVLabsCustomCloudProfile(vlabs *vlabs.CustomCloudProfile, api *CustomCloudProfile) {
if vlabs.Environment != nil {
api.Environment = &azure.Environment{}
api.Environment.Name = vlabs.Environment.Name
api.Environment.ManagementPortalURL = vlabs.Environment.ManagementPortalURL
api.Environment.PublishSettingsURL = vlabs.Environment.PublishSettingsURL
api.Environment.ServiceManagementEndpoint = vlabs.Environment.ServiceManagementEndpoint
api.Environment.ResourceManagerEndpoint = vlabs.Environment.ResourceManagerEndpoint
api.Environment.ActiveDirectoryEndpoint = vlabs.Environment.ActiveDirectoryEndpoint
api.Environment.GalleryEndpoint = vlabs.Environment.GalleryEndpoint
api.Environment.KeyVaultEndpoint = vlabs.Environment.KeyVaultEndpoint
api.Environment.GraphEndpoint = vlabs.Environment.GraphEndpoint
api.Environment.ServiceBusEndpoint = vlabs.Environment.ServiceBusEndpoint
api.Environment.BatchManagementEndpoint = vlabs.Environment.BatchManagementEndpoint
api.Environment.StorageEndpointSuffix = vlabs.Environment.StorageEndpointSuffix
api.Environment.SQLDatabaseDNSSuffix = vlabs.Environment.SQLDatabaseDNSSuffix
api.Environment.TrafficManagerDNSSuffix = vlabs.Environment.TrafficManagerDNSSuffix
api.Environment.KeyVaultDNSSuffix = vlabs.Environment.KeyVaultDNSSuffix
api.Environment.ServiceBusEndpointSuffix = vlabs.Environment.ServiceBusEndpointSuffix
api.Environment.ServiceManagementVMDNSSuffix = vlabs.Environment.ServiceManagementVMDNSSuffix
api.Environment.ResourceManagerVMDNSSuffix = vlabs.Environment.ResourceManagerVMDNSSuffix
api.Environment.ContainerRegistryDNSSuffix = vlabs.Environment.ContainerRegistryDNSSuffix
api.Environment.TokenAudience = vlabs.Environment.TokenAudience
api.Environment.ResourceIdentifiers = azure.ResourceIdentifier{
Graph: vlabs.Environment.ResourceIdentifiers.Graph,
KeyVault: vlabs.Environment.ResourceIdentifiers.KeyVault,
Datalake: vlabs.Environment.ResourceIdentifiers.Datalake,
Batch: vlabs.Environment.ResourceIdentifiers.Batch,
OperationalInsights: vlabs.Environment.ResourceIdentifiers.OperationalInsights,
Storage: vlabs.Environment.ResourceIdentifiers.Storage,
}
}
if vlabs.AzureEnvironmentSpecConfig != nil {
api.AzureEnvironmentSpecConfig = &AzureEnvironmentSpecConfig{}
convertAzureEnvironmentSpecConfig(vlabs.AzureEnvironmentSpecConfig, api.AzureEnvironmentSpecConfig)
}
api.IdentitySystem = vlabs.IdentitySystem
api.AuthenticationMethod = vlabs.AuthenticationMethod
api.DependenciesLocation = DependenciesLocation(vlabs.DependenciesLocation)
api.PortalURL = vlabs.PortalURL
api.CustomCloudRootCertificates = vlabs.CustomCloudRootCertificates
api.CustomCloudSourcesList = vlabs.CustomCloudSourcesList
}
func convertVLabsTelemetryProfile(vlabs *vlabs.TelemetryProfile, api *TelemetryProfile) {
api.ApplicationInsightsKey = vlabs.ApplicationInsightsKey
}
func convertAzureEnvironmentSpecConfig(vlabses *vlabs.AzureEnvironmentSpecConfig, api *AzureEnvironmentSpecConfig) {
api.CloudName = vlabses.CloudName
api.EndpointConfig = AzureEndpointConfig{
ResourceManagerVMDNSSuffix: vlabses.EndpointConfig.ResourceManagerVMDNSSuffix,
}
api.KubernetesSpecConfig = KubernetesSpecConfig{
AzureTelemetryPID: vlabses.KubernetesSpecConfig.AzureTelemetryPID,
KubernetesImageBase: vlabses.KubernetesSpecConfig.KubernetesImageBase,
TillerImageBase: vlabses.KubernetesSpecConfig.TillerImageBase,
NVIDIAImageBase: vlabses.KubernetesSpecConfig.NVIDIAImageBase,
AzureCNIImageBase: vlabses.KubernetesSpecConfig.AzureCNIImageBase,
CalicoImageBase: vlabses.KubernetesSpecConfig.CalicoImageBase,
EtcdDownloadURLBase: vlabses.KubernetesSpecConfig.EtcdDownloadURLBase,
KubeBinariesSASURLBase: vlabses.KubernetesSpecConfig.KubeBinariesSASURLBase,
WindowsTelemetryGUID: vlabses.KubernetesSpecConfig.WindowsTelemetryGUID,
CNIPluginsDownloadURL: vlabses.KubernetesSpecConfig.CNIPluginsDownloadURL,
VnetCNILinuxPluginsDownloadURL: vlabses.KubernetesSpecConfig.VnetCNILinuxPluginsDownloadURL,
VnetCNIWindowsPluginsDownloadURL: vlabses.KubernetesSpecConfig.VnetCNIWindowsPluginsDownloadURL,
ContainerdDownloadURLBase: vlabses.KubernetesSpecConfig.ContainerdDownloadURLBase,
CSIProxyDownloadURL: vlabses.KubernetesSpecConfig.CSIProxyDownloadURL,
WindowsProvisioningScriptsPackageURL: vlabses.KubernetesSpecConfig.WindowsProvisioningScriptsPackageURL,
WindowsPauseImageURL: vlabses.KubernetesSpecConfig.WindowsPauseImageURL,
AlwaysPullWindowsPauseImage: vlabses.KubernetesSpecConfig.AlwaysPullWindowsPauseImage,
}
api.OSImageConfig = map[Distro]AzureOSImageConfig{}
for k, v := range vlabses.OSImageConfig {
api.OSImageConfig[Distro(string(k))] = AzureOSImageConfig{
ImageOffer: v.ImageOffer,
ImageSku: v.ImageSku,
ImagePublisher: v.ImagePublisher,
ImageVersion: v.ImageVersion,
}
}
}