This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 560
/
defaults.go
759 lines (683 loc) · 28 KB
/
defaults.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
package acsengine
import (
"encoding/binary"
"fmt"
"net"
"github.com/Azure/acs-engine/pkg/api"
"github.com/Azure/acs-engine/pkg/api/common"
"github.com/Masterminds/semver"
)
const (
// AzureCniPluginVer specifies version of Azure CNI plugin, which has been mirrored from
// https://github.com/Azure/azure-container-networking/releases/download/${AZURE_PLUGIN_VER}/azure-vnet-cni-linux-amd64-${AZURE_PLUGIN_VER}.tgz
// to https://acs-mirror.azureedge.net/cni/
AzureCniPluginVer = "v1.0.1"
)
var (
//DefaultKubernetesSpecConfig is the default Docker image source of Kubernetes
DefaultKubernetesSpecConfig = KubernetesSpecConfig{
KubernetesImageBase: "k8s-gcrio.azureedge.net/",
TillerImageBase: "gcrio.azureedge.net/kubernetes-helm/",
ACIConnectorImageBase: "microsoft/",
EtcdDownloadURLBase: "https://acs-mirror.azureedge.net/github-coreos",
KubeBinariesSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
WindowsTelemetryGUID: "fb801154-36b9-41bc-89c2-f4d4f05472b0",
CNIPluginsDownloadURL: "https://acs-mirror.azureedge.net/cni/cni-plugins-amd64-latest.tgz",
VnetCNILinuxPluginsDownloadURL: "https://acs-mirror.azureedge.net/cni/azure-vnet-cni-linux-amd64-" + AzureCniPluginVer + ".tgz",
VnetCNIWindowsPluginsDownloadURL: "https://acs-mirror.azureedge.net/cni/azure-vnet-cni-windows-amd64-" + AzureCniPluginVer + ".zip",
}
//DefaultDCOSSpecConfig is the default DC/OS binary download URL.
DefaultDCOSSpecConfig = DCOSSpecConfig{
DCOS188BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "5df43052907c021eeb5de145419a3da1898c58a5"),
DCOS190BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "58fd0833ce81b6244fc73bf65b5deb43217b0bd7"),
DCOS110BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable", "e38ab2aa282077c8eb7bf103c6fff7b0f08db1a4"),
DCOSWindowsBootstrapDownloadURL: "http://dcos-win.westus.cloudapp.azure.com/dcos-windows/stable/",
}
//DefaultDockerSpecConfig is the default Docker engine repo.
DefaultDockerSpecConfig = DockerSpecConfig{
DockerEngineRepo: "https://aptdocker.azureedge.net/repo",
DockerComposeDownloadURL: "https://github.com/docker/compose/releases/download",
}
//DefaultUbuntuImageConfig is the default Linux distribution.
DefaultUbuntuImageConfig = AzureOSImageConfig{
ImageOffer: "UbuntuServer",
ImageSku: "16.04-LTS",
ImagePublisher: "Canonical",
ImageVersion: "16.04.201801050",
}
//DefaultRHELOSImageConfig is the RHEL Linux distribution.
DefaultRHELOSImageConfig = AzureOSImageConfig{
ImageOffer: "RHEL",
ImageSku: "7.3",
ImagePublisher: "RedHat",
ImageVersion: "latest",
}
//DefaultCoreOSImageConfig is the CoreOS Linux distribution.
DefaultCoreOSImageConfig = AzureOSImageConfig{
ImageOffer: "CoreOS",
ImageSku: "Stable",
ImagePublisher: "CoreOS",
ImageVersion: "latest",
}
//AzureCloudSpec is the default configurations for global azure.
AzureCloudSpec = AzureEnvironmentSpecConfig{
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: DefaultDockerSpecConfig,
//KubernetesSpecConfig is the default kubernetes container image url.
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
DCOSSpecConfig: DefaultDCOSSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
},
OSImageConfig: map[api.Distro]AzureOSImageConfig{
api.Ubuntu: DefaultUbuntuImageConfig,
api.RHEL: DefaultRHELOSImageConfig,
api.CoreOS: DefaultCoreOSImageConfig,
},
}
//AzureGermanCloudSpec is the German cloud config.
AzureGermanCloudSpec = AzureEnvironmentSpecConfig{
DockerSpecConfig: DefaultDockerSpecConfig,
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
DCOSSpecConfig: DefaultDCOSSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
},
OSImageConfig: map[api.Distro]AzureOSImageConfig{
api.Ubuntu: {
ImageOffer: "UbuntuServer",
ImageSku: "16.04-LTS",
ImagePublisher: "Canonical",
ImageVersion: "16.04.201801050",
},
api.RHEL: DefaultRHELOSImageConfig,
api.CoreOS: DefaultCoreOSImageConfig,
},
}
//AzureUSGovernmentCloud is the US government config.
AzureUSGovernmentCloud = AzureEnvironmentSpecConfig{
DockerSpecConfig: DefaultDockerSpecConfig,
KubernetesSpecConfig: DefaultKubernetesSpecConfig,
DCOSSpecConfig: DefaultDCOSSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.usgovcloudapi.net",
},
OSImageConfig: map[api.Distro]AzureOSImageConfig{
api.Ubuntu: DefaultUbuntuImageConfig,
api.RHEL: DefaultRHELOSImageConfig,
api.CoreOS: DefaultCoreOSImageConfig,
},
}
//AzureChinaCloudSpec is the configurations for Azure China (Mooncake)
AzureChinaCloudSpec = AzureEnvironmentSpecConfig{
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: DockerSpecConfig{
DockerEngineRepo: "https://mirror.azure.cn/docker-engine/apt/repo/",
DockerComposeDownloadURL: "https://mirror.azure.cn/docker-toolbox/linux/compose",
},
//KubernetesSpecConfig - Due to Chinese firewall issue, the default containers from google is blocked, use the Chinese local mirror instead
KubernetesSpecConfig: KubernetesSpecConfig{
KubernetesImageBase: "crproxy.trafficmanager.net:6000/google_containers/",
TillerImageBase: "crproxy.trafficmanager.net:6000/kubernetes-helm/",
ACIConnectorImageBase: DefaultKubernetesSpecConfig.ACIConnectorImageBase,
EtcdDownloadURLBase: DefaultKubernetesSpecConfig.EtcdDownloadURLBase,
KubeBinariesSASURLBase: DefaultKubernetesSpecConfig.KubeBinariesSASURLBase,
WindowsTelemetryGUID: DefaultKubernetesSpecConfig.WindowsTelemetryGUID,
CNIPluginsDownloadURL: DefaultKubernetesSpecConfig.CNIPluginsDownloadURL,
VnetCNILinuxPluginsDownloadURL: DefaultKubernetesSpecConfig.VnetCNILinuxPluginsDownloadURL,
VnetCNIWindowsPluginsDownloadURL: DefaultKubernetesSpecConfig.VnetCNIWindowsPluginsDownloadURL,
},
DCOSSpecConfig: DCOSSpecConfig{
DCOS188BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "5df43052907c021eeb5de145419a3da1898c58a5"),
DCOSWindowsBootstrapDownloadURL: "https://dcosdevstorage.blob.core.windows.net/dcos-windows",
DCOS190BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "58fd0833ce81b6244fc73bf65b5deb43217b0bd7"),
},
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.chinacloudapi.cn",
},
OSImageConfig: map[api.Distro]AzureOSImageConfig{
api.Ubuntu: {
ImageOffer: "UbuntuServer",
ImageSku: "16.04-LTS",
ImagePublisher: "Canonical",
ImageVersion: "latest",
},
api.RHEL: DefaultRHELOSImageConfig,
api.CoreOS: DefaultCoreOSImageConfig,
},
}
// DefaultTillerAddonsConfig is the default tiller Kubernetes addon Config
DefaultTillerAddonsConfig = api.KubernetesAddon{
Name: DefaultTillerAddonName,
Enabled: pointerToBool(api.DefaultTillerAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultTillerAddonName,
CPURequests: "50m",
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
},
},
}
// DefaultACIConnectorAddonsConfig is the default ACI Connector Kubernetes addon Config
DefaultACIConnectorAddonsConfig = api.KubernetesAddon{
Name: DefaultACIConnectorAddonName,
Enabled: pointerToBool(api.DefaultACIConnectorAddonEnabled),
Config: map[string]string{
"region": "westus",
"nodeName": "aci-connector",
"os": "Linux",
"taint": "azure.com/aci",
},
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultACIConnectorAddonName,
CPURequests: "50m",
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
},
},
}
// DefaultDashboardAddonsConfig is the default kubernetes-dashboard addon Config
DefaultDashboardAddonsConfig = api.KubernetesAddon{
Name: DefaultDashboardAddonName,
Enabled: pointerToBool(api.DefaultDashboardAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultDashboardAddonName,
CPURequests: "300m",
MemoryRequests: "150Mi",
CPULimits: "300m",
MemoryLimits: "150Mi",
},
},
}
// DefaultReschedulerAddonsConfig is the default rescheduler Kubernetes addon Config
DefaultReschedulerAddonsConfig = api.KubernetesAddon{
Name: DefaultReschedulerAddonName,
Enabled: pointerToBool(api.DefaultReschedulerAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultReschedulerAddonName,
CPURequests: "10m",
MemoryRequests: "100Mi",
CPULimits: "10m",
MemoryLimits: "100Mi",
},
},
}
)
// SetPropertiesDefaults for the container Properties, returns true if certs are generated
func SetPropertiesDefaults(cs *api.ContainerService) (bool, error) {
properties := cs.Properties
setOrchestratorDefaults(cs)
setMasterNetworkDefaults(properties)
setHostedMasterNetworkDefaults(properties)
setAgentNetworkDefaults(properties)
setStorageDefaults(properties)
setExtensionDefaults(properties)
certsGenerated, e := setDefaultCerts(properties)
if e != nil {
return false, e
}
return certsGenerated, nil
}
// setOrchestratorDefaults for orchestrators
func setOrchestratorDefaults(cs *api.ContainerService) {
location := cs.Location
a := cs.Properties
cloudSpecConfig := GetCloudSpecConfig(location)
if a.OrchestratorProfile == nil {
return
}
o := a.OrchestratorProfile
o.OrchestratorVersion = common.GetValidPatchVersion(
o.OrchestratorType,
o.OrchestratorVersion)
if o.OrchestratorType == api.Kubernetes {
k8sVersion := o.OrchestratorVersion
if o.KubernetesConfig == nil {
o.KubernetesConfig = &api.KubernetesConfig{}
}
// Add default addons specification, if no user-provided spec exists
if o.KubernetesConfig.Addons == nil {
o.KubernetesConfig.Addons = []api.KubernetesAddon{
DefaultTillerAddonsConfig,
DefaultACIConnectorAddonsConfig,
DefaultDashboardAddonsConfig,
DefaultReschedulerAddonsConfig,
}
} else {
// For each addon, provide default configuration if user didn't provide its own config
t := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultTillerAddonName)
if t < 0 {
// Provide default acs-engine config for Tiller
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultTillerAddonsConfig)
}
a := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultACIConnectorAddonName)
if a < 0 {
// Provide default acs-engine config for ACI Connector
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultACIConnectorAddonsConfig)
}
d := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultDashboardAddonName)
if d < 0 {
// Provide default acs-engine config for Dashboard
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultDashboardAddonsConfig)
}
r := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultReschedulerAddonName)
if r < 0 {
// Provide default acs-engine config for Rescheduler
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultReschedulerAddonsConfig)
}
}
if o.KubernetesConfig.KubernetesImageBase == "" {
o.KubernetesConfig.KubernetesImageBase = cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase
}
if o.KubernetesConfig.EtcdVersion == "" {
o.KubernetesConfig.EtcdVersion = DefaultEtcdVersion
}
if a.HasWindows() {
o.KubernetesConfig.NetworkPolicy = DefaultNetworkPolicyWindows
} else {
if o.KubernetesConfig.NetworkPolicy == "" {
o.KubernetesConfig.NetworkPolicy = DefaultNetworkPolicy
}
}
if o.KubernetesConfig.ContainerRuntime == "" {
o.KubernetesConfig.ContainerRuntime = DefaultContainerRuntime
}
if o.KubernetesConfig.ClusterSubnet == "" {
if o.IsAzureCNI() {
// When VNET integration is enabled, all masters, agents and pods share the same large subnet.
o.KubernetesConfig.ClusterSubnet = DefaultKubernetesSubnet
} else {
o.KubernetesConfig.ClusterSubnet = DefaultKubernetesClusterSubnet
}
}
if o.KubernetesConfig.MaxPods == 0 {
if o.IsAzureCNI() {
o.KubernetesConfig.MaxPods = DefaultKubernetesMaxPodsVNETIntegrated
} else {
o.KubernetesConfig.MaxPods = DefaultKubernetesMaxPods
}
}
if o.KubernetesConfig.GCHighThreshold == 0 {
o.KubernetesConfig.GCHighThreshold = DefaultKubernetesGCHighThreshold
}
if o.KubernetesConfig.GCLowThreshold == 0 {
o.KubernetesConfig.GCLowThreshold = DefaultKubernetesGCLowThreshold
}
if o.KubernetesConfig.DNSServiceIP == "" {
o.KubernetesConfig.DNSServiceIP = DefaultKubernetesDNSServiceIP
}
if o.KubernetesConfig.DockerBridgeSubnet == "" {
o.KubernetesConfig.DockerBridgeSubnet = DefaultDockerBridgeSubnet
}
if o.KubernetesConfig.ServiceCIDR == "" {
o.KubernetesConfig.ServiceCIDR = DefaultKubernetesServiceCIDR
}
// Enforce sane cloudprovider backoff defaults, if CloudProviderBackoff is true in KubernetesConfig
if o.KubernetesConfig.CloudProviderBackoff == true {
if o.KubernetesConfig.CloudProviderBackoffDuration == 0 {
o.KubernetesConfig.CloudProviderBackoffDuration = DefaultKubernetesCloudProviderBackoffDuration
}
if o.KubernetesConfig.CloudProviderBackoffExponent == 0 {
o.KubernetesConfig.CloudProviderBackoffExponent = DefaultKubernetesCloudProviderBackoffExponent
}
if o.KubernetesConfig.CloudProviderBackoffJitter == 0 {
o.KubernetesConfig.CloudProviderBackoffJitter = DefaultKubernetesCloudProviderBackoffJitter
}
if o.KubernetesConfig.CloudProviderBackoffRetries == 0 {
o.KubernetesConfig.CloudProviderBackoffRetries = DefaultKubernetesCloudProviderBackoffRetries
}
}
k8sSemVer, _ := semver.NewVersion(k8sVersion)
constraint, _ := semver.NewConstraint(">= 1.6.6")
// Enforce sane cloudprovider rate limit defaults, if CloudProviderRateLimit is true in KubernetesConfig
// For k8s version greater or equal to 1.6.6, we will set the default CloudProviderRate* settings
if o.KubernetesConfig.CloudProviderRateLimit == true && constraint.Check(k8sSemVer) {
if o.KubernetesConfig.CloudProviderRateLimitQPS == 0 {
o.KubernetesConfig.CloudProviderRateLimitQPS = DefaultKubernetesCloudProviderRateLimitQPS
}
if o.KubernetesConfig.CloudProviderRateLimitBucket == 0 {
o.KubernetesConfig.CloudProviderRateLimitBucket = DefaultKubernetesCloudProviderRateLimitBucket
}
}
// For each addon, produce a synthesized config between user-provided and acs-engine defaults
t := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultTillerAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[t].IsEnabled(api.DefaultTillerAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[t] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[t], DefaultTillerAddonsConfig)
}
c := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultACIConnectorAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[c].IsEnabled(api.DefaultACIConnectorAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[c] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[c], DefaultACIConnectorAddonsConfig)
}
d := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultDashboardAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[d].IsEnabled(api.DefaultDashboardAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[d] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[d], DefaultDashboardAddonsConfig)
}
r := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultReschedulerAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[r].IsEnabled(api.DefaultReschedulerAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[r] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[r], DefaultReschedulerAddonsConfig)
}
if "" == a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB {
a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB = DefaultEtcdDiskSize
}
if a.OrchestratorProfile.KubernetesConfig.EnableRbac == nil {
a.OrchestratorProfile.KubernetesConfig.EnableRbac = pointerToBool(api.DefaultRBACEnabled)
}
if a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet == nil {
a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = pointerToBool(api.DefaultSecureKubeletEnabled)
}
// Configure kubelet
setKubeletConfig(cs)
// Configure controller-manager
setControllerManagerConfig(cs)
// Configure cloud-controller-manager
setCloudControllerManagerConfig(cs)
// Configure apiserver
setAPIServerConfig(cs)
} else if o.OrchestratorType == api.DCOS {
if o.DcosConfig == nil {
o.DcosConfig = &api.DcosConfig{}
}
if o.DcosConfig.DcosWindowsBootstrapURL == "" {
o.DcosConfig.DcosWindowsBootstrapURL = DefaultDCOSSpecConfig.DCOSWindowsBootstrapDownloadURL
}
}
}
func setExtensionDefaults(a *api.Properties) {
if a.ExtensionProfiles == nil {
return
}
for _, extension := range a.ExtensionProfiles {
if extension.RootURL == "" {
extension.RootURL = DefaultExtensionsRootURL
}
}
}
// SetHostedMasterNetworkDefaults for hosted masters
func setHostedMasterNetworkDefaults(a *api.Properties) {
if a.HostedMasterProfile == nil {
return
}
a.HostedMasterProfile.Subnet = DefaultKubernetesMasterSubnet
}
// SetMasterNetworkDefaults for masters
func setMasterNetworkDefaults(a *api.Properties) {
if a.MasterProfile == nil {
return
}
// Set default Distro to Ubuntu
if a.MasterProfile.Distro == "" {
a.MasterProfile.Distro = api.Ubuntu
}
if !a.MasterProfile.IsCustomVNET() {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
if a.OrchestratorProfile.IsAzureCNI() {
// When VNET integration is enabled, all masters, agents and pods share the same large subnet.
a.MasterProfile.Subnet = a.OrchestratorProfile.KubernetesConfig.ClusterSubnet
a.MasterProfile.FirstConsecutiveStaticIP = getFirstConsecutiveStaticIPAddress(a.MasterProfile.Subnet)
} else {
a.MasterProfile.Subnet = DefaultKubernetesMasterSubnet
a.MasterProfile.FirstConsecutiveStaticIP = DefaultFirstConsecutiveKubernetesStaticIP
}
} else if a.HasWindows() {
a.MasterProfile.Subnet = DefaultSwarmWindowsMasterSubnet
a.MasterProfile.FirstConsecutiveStaticIP = DefaultSwarmWindowsFirstConsecutiveStaticIP
} else {
a.MasterProfile.Subnet = DefaultMasterSubnet
a.MasterProfile.FirstConsecutiveStaticIP = DefaultFirstConsecutiveStaticIP
}
}
// Set the default number of IP addresses allocated for masters.
if a.MasterProfile.IPAddressCount == 0 {
// Allocate IP addresses for pods if VNET integration is enabled.
if a.OrchestratorProfile.IsAzureCNI() {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
a.MasterProfile.IPAddressCount += a.OrchestratorProfile.KubernetesConfig.MaxPods
}
}
}
if a.MasterProfile.HTTPSourceAddressPrefix == "" {
a.MasterProfile.HTTPSourceAddressPrefix = "*"
}
}
// SetAgentNetworkDefaults for agents
func setAgentNetworkDefaults(a *api.Properties) {
// configure the subnets if not in custom VNET
if a.MasterProfile != nil && !a.MasterProfile.IsCustomVNET() {
subnetCounter := 0
for _, profile := range a.AgentPoolProfiles {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
profile.Subnet = a.MasterProfile.Subnet
} else {
profile.Subnet = fmt.Sprintf(DefaultAgentSubnetTemplate, subnetCounter)
}
subnetCounter++
}
}
for _, profile := range a.AgentPoolProfiles {
// set default OSType to Linux
if profile.OSType == "" {
profile.OSType = api.Linux
}
// set default Distro to Ubuntu
if profile.Distro == "" {
profile.Distro = api.Ubuntu
}
// Set the default number of IP addresses allocated for agents.
if profile.IPAddressCount == 0 {
// Allocate one IP address for the node.
profile.IPAddressCount = 1
// Allocate IP addresses for pods if VNET integration is enabled.
if a.OrchestratorProfile.IsAzureCNI() {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
profile.IPAddressCount += a.OrchestratorProfile.KubernetesConfig.MaxPods
}
}
}
}
}
// setStorageDefaults for agents
func setStorageDefaults(a *api.Properties) {
if a.MasterProfile != nil && len(a.MasterProfile.StorageProfile) == 0 {
a.MasterProfile.StorageProfile = api.StorageAccount
}
for _, profile := range a.AgentPoolProfiles {
if len(profile.StorageProfile) == 0 {
profile.StorageProfile = api.StorageAccount
}
if len(profile.AvailabilityProfile) == 0 {
profile.AvailabilityProfile = api.VirtualMachineScaleSets
}
}
}
func setDefaultCerts(a *api.Properties) (bool, error) {
if a.MasterProfile == nil || a.OrchestratorProfile.OrchestratorType != api.Kubernetes {
return false, nil
}
provided := certsAlreadyPresent(a.CertificateProfile, a.MasterProfile.Count)
if areAllTrue(provided) {
return false, nil
}
masterExtraFQDNs := FormatAzureProdFQDNs(a.MasterProfile.DNSPrefix)
firstMasterIP := net.ParseIP(a.MasterProfile.FirstConsecutiveStaticIP).To4()
if firstMasterIP == nil {
return false, fmt.Errorf("MasterProfile.FirstConsecutiveStaticIP '%s' is an invalid IP address", a.MasterProfile.FirstConsecutiveStaticIP)
}
ips := []net.IP{firstMasterIP}
// Add the Internal Loadbalancer IP which is always at at a known offset from the firstMasterIP
ips = append(ips, net.IP{firstMasterIP[0], firstMasterIP[1], firstMasterIP[2], firstMasterIP[3] + byte(DefaultInternalLbStaticIPOffset)})
// Include the Internal load balancer as well
for i := 1; i < a.MasterProfile.Count; i++ {
ip := net.IP{firstMasterIP[0], firstMasterIP[1], firstMasterIP[2], firstMasterIP[3] + byte(i)}
ips = append(ips, ip)
}
if a.CertificateProfile == nil {
a.CertificateProfile = &api.CertificateProfile{}
}
// use the specified Certificate Authority pair, or generate a new pair
var caPair *PkiKeyCertPair
if provided["ca"] {
caPair = &PkiKeyCertPair{CertificatePem: a.CertificateProfile.CaCertificate, PrivateKeyPem: a.CertificateProfile.CaPrivateKey}
} else {
caCertificate, caPrivateKey, err := createCertificate("ca", nil, nil, false, false, nil, nil, nil)
if err != nil {
return false, err
}
caPair = &PkiKeyCertPair{CertificatePem: string(certificateToPem(caCertificate.Raw)), PrivateKeyPem: string(privateKeyToPem(caPrivateKey))}
a.CertificateProfile.CaCertificate = caPair.CertificatePem
a.CertificateProfile.CaPrivateKey = caPair.PrivateKeyPem
}
cidrFirstIP, err := common.CidrStringFirstIP(a.OrchestratorProfile.KubernetesConfig.ServiceCIDR)
if err != nil {
return false, err
}
ips = append(ips, cidrFirstIP)
apiServerPair, clientPair, kubeConfigPair, etcdServerPair, etcdClientPair, etcdPeerPairs, err := CreatePki(masterExtraFQDNs, ips, DefaultKubernetesClusterDomain, caPair, a.MasterProfile.Count)
if err != nil {
return false, err
}
// If no Certificate Authority pair or no cert/key pair was provided, use generated cert/key pairs signed by provided Certificate Authority pair
if !provided["apiserver"] || !provided["ca"] {
a.CertificateProfile.APIServerCertificate = apiServerPair.CertificatePem
a.CertificateProfile.APIServerPrivateKey = apiServerPair.PrivateKeyPem
}
if !provided["client"] || !provided["ca"] {
a.CertificateProfile.ClientCertificate = clientPair.CertificatePem
a.CertificateProfile.ClientPrivateKey = clientPair.PrivateKeyPem
}
if !provided["kubeconfig"] || !provided["ca"] {
a.CertificateProfile.KubeConfigCertificate = kubeConfigPair.CertificatePem
a.CertificateProfile.KubeConfigPrivateKey = kubeConfigPair.PrivateKeyPem
}
if !provided["etcd"] || !provided["ca"] {
a.CertificateProfile.EtcdServerCertificate = etcdServerPair.CertificatePem
a.CertificateProfile.EtcdServerPrivateKey = etcdServerPair.PrivateKeyPem
a.CertificateProfile.EtcdClientCertificate = etcdClientPair.CertificatePem
a.CertificateProfile.EtcdClientPrivateKey = etcdClientPair.PrivateKeyPem
a.CertificateProfile.EtcdPeerCertificates = make([]string, a.MasterProfile.Count)
a.CertificateProfile.EtcdPeerPrivateKeys = make([]string, a.MasterProfile.Count)
for i, v := range etcdPeerPairs {
a.CertificateProfile.EtcdPeerCertificates[i] = v.CertificatePem
a.CertificateProfile.EtcdPeerPrivateKeys[i] = v.PrivateKeyPem
}
}
return true, nil
}
func areAllTrue(m map[string]bool) bool {
for _, v := range m {
if !v {
return false
}
}
return true
}
// certsAlreadyPresent already present returns a map where each key is a type of cert and each value is true if that cert/key pair is user-provided
func certsAlreadyPresent(c *api.CertificateProfile, m int) map[string]bool {
g := map[string]bool{
"ca": false,
"apiserver": false,
"kubeconfig": false,
"client": false,
"etcd": false,
}
if c != nil {
etcdPeer := true
if len(c.EtcdPeerCertificates) != m || len(c.EtcdPeerPrivateKeys) != m {
etcdPeer = false
} else {
for i, p := range c.EtcdPeerCertificates {
if !(len(p) > 0) || !(len(c.EtcdPeerPrivateKeys[i]) > 0) {
etcdPeer = false
}
}
}
g["ca"] = len(c.CaCertificate) > 0 && len(c.CaPrivateKey) > 0
g["apiserver"] = len(c.APIServerCertificate) > 0 && len(c.APIServerPrivateKey) > 0
g["kubeconfig"] = len(c.KubeConfigCertificate) > 0 && len(c.KubeConfigPrivateKey) > 0
g["client"] = len(c.ClientCertificate) > 0 && len(c.ClientPrivateKey) > 0
g["etcd"] = etcdPeer && len(c.EtcdClientCertificate) > 0 && len(c.EtcdClientPrivateKey) > 0 && len(c.EtcdServerCertificate) > 0 && len(c.EtcdServerPrivateKey) > 0
}
return g
}
// getFirstConsecutiveStaticIPAddress returns the first static IP address of the given subnet.
func getFirstConsecutiveStaticIPAddress(subnetStr string) string {
ip, _, err := net.ParseCIDR(subnetStr)
if err != nil {
return DefaultFirstConsecutiveKubernetesStaticIP
}
ipv4 := ip.To4()
if ipv4 == nil {
return DefaultFirstConsecutiveKubernetesStaticIP
}
ipint := binary.BigEndian.Uint32(ipv4)
// First 4 IPs will be reserved in Azure and cannot use.
ipint += 4
startIP := make(net.IP, 4)
binary.BigEndian.PutUint32(startIP, ipint)
return startIP.String()
}
func getAddonsIndexByName(addons []api.KubernetesAddon, name string) int {
for i := range addons {
if addons[i].Name == name {
return i
}
}
return -1
}
func getAddonContainersIndexByName(containers []api.KubernetesContainerSpec, name string) int {
for i := range containers {
if containers[i].Name == name {
return i
}
}
return -1
}
// assignDefaultAddonVals will assign default values to addon from defaults, for each property in addon that has a zero value
func assignDefaultAddonVals(addon, defaults api.KubernetesAddon) api.KubernetesAddon {
for i := range defaults.Containers {
c := getAddonContainersIndexByName(addon.Containers, defaults.Containers[i].Name)
if c < 0 {
addon.Containers = append(addon.Containers, defaults.Containers[i])
} else {
if addon.Containers[c].Image == "" {
addon.Containers[c].Image = defaults.Containers[i].Image
}
if addon.Containers[c].CPURequests == "" {
addon.Containers[c].CPURequests = defaults.Containers[i].CPURequests
}
if addon.Containers[c].MemoryRequests == "" {
addon.Containers[c].MemoryRequests = defaults.Containers[i].MemoryRequests
}
if addon.Containers[c].CPULimits == "" {
addon.Containers[c].CPULimits = defaults.Containers[i].CPULimits
}
if addon.Containers[c].MemoryLimits == "" {
addon.Containers[c].MemoryLimits = defaults.Containers[i].MemoryLimits
}
}
}
for key, val := range defaults.Config {
if addon.Config == nil {
addon.Config = make(map[string]string, 0)
}
if v, ok := addon.Config[key]; !ok || v == "" {
addon.Config[key] = val
}
}
return addon
}
// pointerToBool returns a pointer to a bool
func pointerToBool(b bool) *bool {
p := b
return &p
}
func isKubernetesVersionGe(actualVersion, version string) bool {
orchestratorVersion, _ := semver.NewVersion(actualVersion)
constraint, _ := semver.NewConstraint(">=" + version)
return constraint.Check(orchestratorVersion)
}