forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaults.go
1061 lines (965 loc) · 41.6 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
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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package acsengine
import (
"bytes"
"crypto/rand"
"encoding/base64"
"fmt"
"net"
"sort"
"strconv"
"strings"
"github.com/Azure/acs-engine/pkg/api"
"github.com/Azure/acs-engine/pkg/api/common"
"github.com/Azure/acs-engine/pkg/helpers"
"github.com/Azure/acs-engine/pkg/openshift/certgen"
"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.4"
// CNIPluginVer specifies the version of CNI implementation
// https://github.com/containernetworking/plugins
CNIPluginVer = "v0.7.0"
)
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/",
NVIDIAImageBase: "nvidia/",
EtcdDownloadURLBase: "https://acs-mirror.azureedge.net/github-coreos",
KubeBinariesSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
WindowsPackageSASURLBase: "https://acs-mirror.azureedge.net/wink8s/",
WindowsTelemetryGUID: "fb801154-36b9-41bc-89c2-f4d4f05472b0",
CNIPluginsDownloadURL: "https://acs-mirror.azureedge.net/cni/cni-plugins-amd64-" + CNIPluginVer + ".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"),
DCOS198BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable/1.9.8", "f4ae0d20665fc68ee25282d6f78681b2773c6e10"),
DCOS110BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable/1.10.0", "4d92536e7381176206e71ee15b5ffe454439920c"),
DCOS111BootstrapDownloadURL: fmt.Sprintf(AzureEdgeDCOSBootstrapDownloadURL, "stable/1.11.0", "a0654657903fb68dff60f6e522a7f241c1bfbf0f"),
DCOSWindowsBootstrapDownloadURL: "http://dcos-win.westus.cloudapp.azure.com/dcos-windows/stable/",
DcosRepositoryURL: "https://dcosio.azureedge.net/dcos/stable/1.11.0",
DcosClusterPackageListID: "248a66388bba1adbcb14a52fd3b7b424ab06fa76",
}
//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.201805220",
}
//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",
}
//DefaultOpenShift39RHELImageConfig is the OpenShift on RHEL distribution.
DefaultOpenShift39RHELImageConfig = AzureOSImageConfig{
ImageOffer: "acsengine-preview",
ImageSku: "rhel74",
ImagePublisher: "redhat",
ImageVersion: "latest",
}
//DefaultOpenShift39CentOSImageConfig is the OpenShift on CentOS distribution.
DefaultOpenShift39CentOSImageConfig = AzureOSImageConfig{
ImageOffer: "origin-acsengine-preview",
ImageSku: "centos7",
ImagePublisher: "redhat",
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,
// Image config supported for OpenShift
api.OpenShift39RHEL: DefaultOpenShift39RHELImageConfig,
api.OpenShiftCentOS: DefaultOpenShift39CentOSImageConfig,
},
}
//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: {
ImageOffer: "UbuntuServer",
ImageSku: "16.04-LTS",
ImagePublisher: "Canonical",
ImageVersion: "latest",
},
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,
WindowsPackageSASURLBase: DefaultKubernetesSpecConfig.WindowsPackageSASURLBase,
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"),
DCOS198BootstrapDownloadURL: fmt.Sprintf(AzureChinaCloudDCOSBootstrapDownloadURL, "f4ae0d20665fc68ee25282d6f78681b2773c6e10"),
},
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: helpers.PointerToBool(api.DefaultTillerAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultTillerAddonName,
CPURequests: "50m",
MemoryRequests: "150Mi",
CPULimits: "50m",
MemoryLimits: "150Mi",
},
},
Config: map[string]string{
"max-history": strconv.Itoa(DefaultTillerMaxHistory),
},
}
// DefaultACIConnectorAddonsConfig is the default ACI Connector Kubernetes addon Config
DefaultACIConnectorAddonsConfig = api.KubernetesAddon{
Name: DefaultACIConnectorAddonName,
Enabled: helpers.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",
},
},
}
// DefaultClusterAutoscalerAddonsConfig is the default cluster autoscaler addon config
DefaultClusterAutoscalerAddonsConfig = api.KubernetesAddon{
Name: DefaultClusterAutoscalerAddonName,
Enabled: helpers.PointerToBool(api.DefaultClusterAutoscalerAddonEnabled),
Config: map[string]string{
"minNodes": "1",
"maxNodes": "5",
},
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultClusterAutoscalerAddonName,
CPURequests: "100m",
MemoryRequests: "300Mi",
CPULimits: "100m",
MemoryLimits: "300Mi",
},
},
}
// DefaultDashboardAddonsConfig is the default kubernetes-dashboard addon Config
DefaultDashboardAddonsConfig = api.KubernetesAddon{
Name: DefaultDashboardAddonName,
Enabled: helpers.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: helpers.PointerToBool(api.DefaultReschedulerAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultReschedulerAddonName,
CPURequests: "10m",
MemoryRequests: "100Mi",
CPULimits: "10m",
MemoryLimits: "100Mi",
},
},
}
// DefaultMetricsServerAddonsConfig is the default metrics-server Kubernetes addon Config
DefaultMetricsServerAddonsConfig = api.KubernetesAddon{
Name: DefaultMetricsServerAddonName,
Enabled: helpers.PointerToBool(api.DefaultMetricsServerAddonEnabled),
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultMetricsServerAddonName,
},
},
}
// DefaultNVIDIADevicePluginAddonsConfig is the default NVIDIA Device Plugin Kubernetes addon Config
DefaultNVIDIADevicePluginAddonsConfig = api.KubernetesAddon{
Name: DefaultNVIDIADevicePluginAddonName,
Containers: []api.KubernetesContainerSpec{
{
Name: DefaultNVIDIADevicePluginAddonName,
},
},
}
)
// setPropertiesDefaults for the container Properties, returns true if certs are generated
func setPropertiesDefaults(cs *api.ContainerService, isUpgrade bool) (bool, error) {
properties := cs.Properties
setOrchestratorDefaults(cs)
setMasterNetworkDefaults(properties, isUpgrade)
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, a.HasWindows())
switch o.OrchestratorType {
case api.Kubernetes:
k8sVersion := o.OrchestratorVersion
if o.KubernetesConfig == nil {
o.KubernetesConfig = &api.KubernetesConfig{}
}
// For backwards compatibility with original, overloaded "NetworkPolicy" config vector
// we translate deprecated NetworkPolicy usage to the NetworkConfig equivalent
// and set a default network policy enforcement configuration
switch o.KubernetesConfig.NetworkPolicy {
case NetworkPluginAzure:
o.KubernetesConfig.NetworkPlugin = NetworkPluginAzure
o.KubernetesConfig.NetworkPolicy = DefaultNetworkPolicy
case NetworkPolicyNone:
o.KubernetesConfig.NetworkPlugin = NetworkPluginKubenet
o.KubernetesConfig.NetworkPolicy = DefaultNetworkPolicy
case NetworkPolicyCalico:
o.KubernetesConfig.NetworkPlugin = NetworkPluginKubenet
case NetworkPolicyCilium:
o.KubernetesConfig.NetworkPlugin = NetworkPolicyCilium
}
// Add default addons specification, if no user-provided spec exists
if o.KubernetesConfig.Addons == nil {
o.KubernetesConfig.Addons = []api.KubernetesAddon{
DefaultTillerAddonsConfig,
DefaultACIConnectorAddonsConfig,
DefaultClusterAutoscalerAddonsConfig,
DefaultDashboardAddonsConfig,
DefaultReschedulerAddonsConfig,
DefaultMetricsServerAddonsConfig,
DefaultNVIDIADevicePluginAddonsConfig,
}
enforceK8sVersionAddonOverrides(o.KubernetesConfig.Addons, o)
} 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)
}
s := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultClusterAutoscalerAddonName)
if s < 0 {
// Provide default acs-engine config for cluster autoscaler
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultClusterAutoscalerAddonsConfig)
}
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)
}
m := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultMetricsServerAddonName)
if m < 0 {
// Provide default acs-engine config for Metrics Server
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultMetricsServerAddonsConfig)
m = getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultMetricsServerAddonName)
o.KubernetesConfig.Addons[m].Enabled = k8sVersionMetricsServerAddonEnabled(o)
}
n := getAddonsIndexByName(o.KubernetesConfig.Addons, DefaultNVIDIADevicePluginAddonName)
if n < 0 {
// Provide default acs-engine config for NVIDIA Device Plugin
o.KubernetesConfig.Addons = append(o.KubernetesConfig.Addons, DefaultNVIDIADevicePluginAddonsConfig)
}
}
if o.KubernetesConfig.KubernetesImageBase == "" {
o.KubernetesConfig.KubernetesImageBase = cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase
}
if o.KubernetesConfig.EtcdVersion == "" {
o.KubernetesConfig.EtcdVersion = DefaultEtcdVersion
}
if a.HasWindows() {
if o.KubernetesConfig.NetworkPlugin == "" {
o.KubernetesConfig.NetworkPlugin = DefaultNetworkPluginWindows
}
} else {
if o.KubernetesConfig.NetworkPlugin == "" {
o.KubernetesConfig.NetworkPlugin = DefaultNetworkPlugin
}
}
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.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 {
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 && 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)
}
s := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultClusterAutoscalerAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[s].IsEnabled(api.DefaultClusterAutoscalerAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[s] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[s], DefaultClusterAutoscalerAddonsConfig)
}
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)
}
m := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultMetricsServerAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[m].IsEnabled(api.DefaultMetricsServerAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[m] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[m], DefaultMetricsServerAddonsConfig)
}
n := getAddonsIndexByName(a.OrchestratorProfile.KubernetesConfig.Addons, DefaultNVIDIADevicePluginAddonName)
if a.OrchestratorProfile.KubernetesConfig.Addons[n].IsEnabled(api.DefaultNVIDIADevicePluginAddonEnabled) {
a.OrchestratorProfile.KubernetesConfig.Addons[n] = assignDefaultAddonVals(a.OrchestratorProfile.KubernetesConfig.Addons[n], DefaultNVIDIADevicePluginAddonsConfig)
}
if o.KubernetesConfig.PrivateCluster == nil {
o.KubernetesConfig.PrivateCluster = &api.PrivateCluster{}
}
if o.KubernetesConfig.PrivateCluster.Enabled == nil {
o.KubernetesConfig.PrivateCluster.Enabled = helpers.PointerToBool(api.DefaultPrivateClusterEnabled)
}
if "" == a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB {
switch {
case a.TotalNodes() > 20:
a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB = DefaultEtcdDiskSizeGT20Nodes
case a.TotalNodes() > 10:
a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB = DefaultEtcdDiskSizeGT10Nodes
case a.TotalNodes() > 3:
a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB = DefaultEtcdDiskSizeGT3Nodes
default:
a.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB = DefaultEtcdDiskSize
}
}
if helpers.IsTrueBoolPointer(o.KubernetesConfig.EnableDataEncryptionAtRest) {
if "" == a.OrchestratorProfile.KubernetesConfig.EtcdEncryptionKey {
a.OrchestratorProfile.KubernetesConfig.EtcdEncryptionKey = generateEtcdEncryptionKey()
}
}
if a.OrchestratorProfile.KubernetesConfig.PrivateJumpboxProvision() && a.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.OSDiskSizeGB == 0 {
a.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.OSDiskSizeGB = DefaultJumpboxDiskSize
}
if a.OrchestratorProfile.KubernetesConfig.PrivateJumpboxProvision() && a.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.Username == "" {
a.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.Username = DefaultJumpboxUsername
}
if a.OrchestratorProfile.KubernetesConfig.PrivateJumpboxProvision() && a.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.StorageProfile == "" {
a.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.StorageProfile = api.ManagedDisks
}
if a.OrchestratorProfile.KubernetesConfig.EnableRbac == nil {
a.OrchestratorProfile.KubernetesConfig.EnableRbac = helpers.PointerToBool(api.DefaultRBACEnabled)
}
if a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet == nil {
a.OrchestratorProfile.KubernetesConfig.EnableSecureKubelet = helpers.PointerToBool(api.DefaultSecureKubeletEnabled)
}
if a.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata == nil {
a.OrchestratorProfile.KubernetesConfig.UseInstanceMetadata = helpers.PointerToBool(api.DefaultUseInstanceMetadata)
}
// Configure kubelet
setKubeletConfig(cs)
// Configure controller-manager
setControllerManagerConfig(cs)
// Configure cloud-controller-manager
setCloudControllerManagerConfig(cs)
// Configure apiserver
setAPIServerConfig(cs)
// Configure scheduler
setSchedulerConfig(cs)
case api.DCOS:
if o.DcosConfig == nil {
o.DcosConfig = &api.DcosConfig{}
}
if o.DcosConfig.DcosWindowsBootstrapURL == "" {
o.DcosConfig.DcosWindowsBootstrapURL = DefaultDCOSSpecConfig.DCOSWindowsBootstrapDownloadURL
}
dcosSemVer, _ := semver.NewVersion(o.OrchestratorVersion)
dcosBootstrapSemVer, _ := semver.NewVersion(common.DCOSVersion1Dot11Dot0)
if !dcosSemVer.LessThan(dcosBootstrapSemVer) {
if o.DcosConfig.BootstrapProfile == nil {
o.DcosConfig.BootstrapProfile = &api.BootstrapProfile{}
}
if len(o.DcosConfig.BootstrapProfile.VMSize) == 0 {
o.DcosConfig.BootstrapProfile.VMSize = "Standard_D2s_v3"
}
}
case api.OpenShift:
if a.MasterProfile.Distro == "" {
a.MasterProfile.Distro = api.RHEL
}
kc := a.OrchestratorProfile.OpenShiftConfig.KubernetesConfig
if kc == nil {
kc = &api.KubernetesConfig{}
}
if kc.ContainerRuntime == "" {
kc.ContainerRuntime = DefaultContainerRuntime
}
if kc.NetworkPlugin == "" {
kc.NetworkPlugin = DefaultNetworkPlugin
}
}
}
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, isUpgrade bool) {
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
// FirstConsecutiveStaticIP is not reset if it is upgrade and some value already exists
if !isUpgrade || len(a.MasterProfile.FirstConsecutiveStaticIP) == 0 {
a.MasterProfile.FirstConsecutiveStaticIP = getFirstConsecutiveStaticIPAddress(a.MasterProfile.Subnet)
}
} else {
a.MasterProfile.Subnet = DefaultKubernetesMasterSubnet
// FirstConsecutiveStaticIP is not reset if it is upgrade and some value already exists
if !isUpgrade || len(a.MasterProfile.FirstConsecutiveStaticIP) == 0 {
a.MasterProfile.FirstConsecutiveStaticIP = DefaultFirstConsecutiveKubernetesStaticIP
}
}
} else if a.OrchestratorProfile.OrchestratorType == api.OpenShift {
a.MasterProfile.Subnet = DefaultOpenShiftMasterSubnet
if !isUpgrade || len(a.MasterProfile.FirstConsecutiveStaticIP) == 0 {
a.MasterProfile.FirstConsecutiveStaticIP = DefaultOpenShiftFirstConsecutiveStaticIP
}
} else if a.OrchestratorProfile.OrchestratorType == api.DCOS {
a.MasterProfile.Subnet = DefaultDCOSMasterSubnet
// FirstConsecutiveStaticIP is not reset if it is upgrade and some value already exists
if !isUpgrade || len(a.MasterProfile.FirstConsecutiveStaticIP) == 0 {
a.MasterProfile.FirstConsecutiveStaticIP = DefaultDCOSFirstConsecutiveStaticIP
}
if a.OrchestratorProfile.DcosConfig != nil && a.OrchestratorProfile.DcosConfig.BootstrapProfile != nil {
if !isUpgrade || len(a.OrchestratorProfile.DcosConfig.BootstrapProfile.StaticIP) == 0 {
a.OrchestratorProfile.DcosConfig.BootstrapProfile.StaticIP = DefaultDCOSBootstrapStaticIP
}
}
} else if a.HasWindows() {
a.MasterProfile.Subnet = DefaultSwarmWindowsMasterSubnet
// FirstConsecutiveStaticIP is not reset if it is upgrade and some value already exists
if !isUpgrade || len(a.MasterProfile.FirstConsecutiveStaticIP) == 0 {
a.MasterProfile.FirstConsecutiveStaticIP = DefaultSwarmWindowsFirstConsecutiveStaticIP
}
} else {
a.MasterProfile.Subnet = DefaultMasterSubnet
// FirstConsecutiveStaticIP is not reset if it is upgrade and some value already exists
if !isUpgrade || len(a.MasterProfile.FirstConsecutiveStaticIP) == 0 {
a.MasterProfile.FirstConsecutiveStaticIP = DefaultFirstConsecutiveStaticIP
}
}
}
// Set the default number of IP addresses allocated for masters.
if a.MasterProfile.IPAddressCount == 0 {
// Allocate one IP address for the node.
a.MasterProfile.IPAddressCount = 1
// Allocate IP addresses for pods if VNET integration is enabled.
if a.OrchestratorProfile.IsAzureCNI() {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
masterMaxPods, _ := strconv.Atoi(a.MasterProfile.KubernetesConfig.KubeletConfig["--max-pods"])
a.MasterProfile.IPAddressCount += masterMaxPods
}
}
}
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 ||
a.OrchestratorProfile.OrchestratorType == api.OpenShift {
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() {
agentPoolMaxPods, _ := strconv.Atoi(profile.KubernetesConfig.KubeletConfig["--max-pods"])
profile.IPAddressCount += agentPoolMaxPods
}
}
}
}
// setStorageDefaults for agents
func setStorageDefaults(a *api.Properties) {
if a.MasterProfile != nil && len(a.MasterProfile.StorageProfile) == 0 {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
a.MasterProfile.StorageProfile = api.ManagedDisks
} else {
a.MasterProfile.StorageProfile = api.StorageAccount
}
}
for _, profile := range a.AgentPoolProfiles {
if len(profile.StorageProfile) == 0 {
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes {
profile.StorageProfile = api.ManagedDisks
} else {
profile.StorageProfile = api.StorageAccount
}
}
if len(profile.AvailabilityProfile) == 0 {
profile.AvailabilityProfile = api.VirtualMachineScaleSets
if a.OrchestratorProfile.OrchestratorType == api.Kubernetes && !common.IsKubernetesVersionGe(a.OrchestratorProfile.OrchestratorVersion, "1.10.0") {
profile.AvailabilityProfile = api.AvailabilitySet
}
}
if len(profile.ScaleSetEvictionPolicy) == 0 && profile.ScaleSetPriority == api.ScaleSetPriorityLow {
profile.ScaleSetEvictionPolicy = api.ScaleSetEvictionPolicyDelete
}
}
}
func setDefaultCerts(a *api.Properties) (bool, error) {
if a.MasterProfile != nil && a.OrchestratorProfile.OrchestratorType == api.OpenShift {
return certgen.OpenShiftSetDefaultCerts(a, DefaultOpenshiftOrchestratorName, GenerateClusterID(a))
}
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 := append(formatAzureProdFQDNs(a.MasterProfile.DNSPrefix), a.MasterProfile.SubjectAltNames...)
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 {
_, subnet, err := net.ParseCIDR(subnetStr)
if err != nil {
return DefaultFirstConsecutiveKubernetesStaticIP
}
// Find the first and last octet of the host bits.
ones, bits := subnet.Mask.Size()
firstOctet := ones / 8
lastOctet := bits/8 - 1
// Set the remaining host bits in the first octet.
subnet.IP[firstOctet] |= (1 << byte((8 - (ones % 8)))) - 1
// Fill the intermediate octets with 1s and last octet with offset. This is done so to match
// the existing behavior of allocating static IP addresses from the last /24 of the subnet.
for i := firstOctet + 1; i < lastOctet; i++ {
subnet.IP[i] = 255
}
subnet.IP[lastOctet] = DefaultKubernetesFirstConsecutiveStaticIPOffset
return subnet.IP.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 {
if addon.Enabled == nil {
addon.Enabled = defaults.Enabled
}
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)
}
if v, ok := addon.Config[key]; !ok || v == "" {
addon.Config[key] = val
}
}
return addon
}
// combine user-provided --feature-gates vals with defaults