forked from Azure/acs-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.go
2691 lines (2485 loc) · 108 KB
/
engine.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"
"compress/gzip"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"hash/fnv"
"io/ioutil"
"log"
"math/rand"
"net"
"net/http"
"regexp"
"runtime/debug"
"sort"
"strconv"
"strings"
"text/template"
//log "github.com/sirupsen/logrus"
"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/i18n"
"github.com/Masterminds/semver"
"github.com/ghodss/yaml"
)
const (
kubernetesMasterCustomDataYaml = "k8s/kubernetesmastercustomdata.yml"
kubernetesCustomScript = "k8s/kubernetescustomscript.sh"
kubernetesProvisionSourceScript = "k8s/kubernetesprovisionsource.sh"
kubernetesMountetcd = "k8s/kubernetes_mountetcd.sh"
kubernetesMasterGenerateProxyCertsScript = "k8s/kubernetesmastergenerateproxycertscript.sh"
kubernetesAgentCustomDataYaml = "k8s/kubernetesagentcustomdata.yml"
kubernetesJumpboxCustomDataYaml = "k8s/kubernetesjumpboxcustomdata.yml"
kubeConfigJSON = "k8s/kubeconfig.json"
kubernetesWindowsAgentCustomDataPS1 = "k8s/kuberneteswindowssetup.ps1"
)
const (
dcosCustomData188 = "dcos/dcoscustomdata188.t"
dcosCustomData190 = "dcos/dcoscustomdata190.t"
dcosCustomData198 = "dcos/dcoscustomdata198.t"
dcosCustomData110 = "dcos/dcoscustomdata110.t"
dcosCustomData111 = "dcos/dcoscustomdata111.t"
dcosProvision = "dcos/dcosprovision.sh"
dcosWindowsProvision = "dcos/dcosWindowsProvision.ps1"
)
const (
swarmProvision = "swarm/configure-swarm-cluster.sh"
swarmWindowsProvision = "swarm/Install-ContainerHost-And-Join-Swarm.ps1"
swarmModeProvision = "swarm/configure-swarmmode-cluster.sh"
swarmModeWindowsProvision = "swarm/Join-SwarmMode-cluster.ps1"
)
const (
agentOutputs = "agentoutputs.t"
agentParams = "agentparams.t"
classicParams = "classicparams.t"
dcosAgentResourcesVMAS = "dcos/dcosagentresourcesvmas.t"
dcosWindowsAgentResourcesVMAS = "dcos/dcosWindowsAgentResourcesVmas.t"
dcosAgentResourcesVMSS = "dcos/dcosagentresourcesvmss.t"
dcosWindowsAgentResourcesVMSS = "dcos/dcosWindowsAgentResourcesVmss.t"
dcosAgentVars = "dcos/dcosagentvars.t"
dcosBaseFile = "dcos/dcosbase.t"
dcosParams = "dcos/dcosparams.t"
dcosMasterResources = "dcos/dcosmasterresources.t"
dcosMasterVars = "dcos/dcosmastervars.t"
iaasOutputs = "iaasoutputs.t"
kubernetesBaseFile = "k8s/kubernetesbase.t"
kubernetesAgentResourcesVMAS = "k8s/kubernetesagentresourcesvmas.t"
kubernetesAgentVars = "k8s/kubernetesagentvars.t"
kubernetesMasterResources = "k8s/kubernetesmasterresources.t"
kubernetesMasterVars = "k8s/kubernetesmastervars.t"
kubernetesParams = "k8s/kubernetesparams.t"
kubernetesWinAgentVars = "k8s/kuberneteswinagentresourcesvmas.t"
masterOutputs = "masteroutputs.t"
masterParams = "masterparams.t"
swarmBaseFile = "swarm/swarmbase.t"
swarmParams = "swarm/swarmparams.t"
swarmAgentResourcesVMAS = "swarm/swarmagentresourcesvmas.t"
swarmAgentResourcesVMSS = "swarm/swarmagentresourcesvmss.t"
swarmAgentResourcesClassic = "swarm/swarmagentresourcesclassic.t"
swarmAgentVars = "swarm/swarmagentvars.t"
swarmMasterResources = "swarm/swarmmasterresources.t"
swarmMasterVars = "swarm/swarmmastervars.t"
swarmWinAgentResourcesVMAS = "swarm/swarmwinagentresourcesvmas.t"
swarmWinAgentResourcesVMSS = "swarm/swarmwinagentresourcesvmss.t"
windowsParams = "windowsparams.t"
)
const (
azurePublicCloud = "AzurePublicCloud"
azureChinaCloud = "AzureChinaCloud"
azureGermanCloud = "AzureGermanCloud"
azureUSGovernmentCloud = "AzureUSGovernmentCloud"
)
var commonTemplateFiles = []string{agentOutputs, agentParams, classicParams, masterOutputs, iaasOutputs, masterParams, windowsParams}
var dcosTemplateFiles = []string{dcosBaseFile, dcosAgentResourcesVMAS, dcosAgentResourcesVMSS, dcosAgentVars, dcosMasterResources, dcosMasterVars, dcosParams, dcosWindowsAgentResourcesVMAS, dcosWindowsAgentResourcesVMSS}
var kubernetesTemplateFiles = []string{kubernetesBaseFile, kubernetesAgentResourcesVMAS, kubernetesAgentVars, kubernetesMasterResources, kubernetesMasterVars, kubernetesParams, kubernetesWinAgentVars}
var swarmTemplateFiles = []string{swarmBaseFile, swarmParams, swarmAgentResourcesVMAS, swarmAgentVars, swarmAgentResourcesVMSS, swarmAgentResourcesClassic, swarmBaseFile, swarmMasterResources, swarmMasterVars, swarmWinAgentResourcesVMAS, swarmWinAgentResourcesVMSS}
var swarmModeTemplateFiles = []string{swarmBaseFile, swarmParams, swarmAgentResourcesVMAS, swarmAgentVars, swarmAgentResourcesVMSS, swarmAgentResourcesClassic, swarmBaseFile, swarmMasterResources, swarmMasterVars, swarmWinAgentResourcesVMAS, swarmWinAgentResourcesVMSS}
/**
The following parameters could be either a plain text, or referenced to a secret in a keyvault:
- apiServerCertificate
- apiServerPrivateKey
- caCertificate
- clientCertificate
- clientPrivateKey
- kubeConfigCertificate
- kubeConfigPrivateKey
- servicePrincipalClientSecret
- etcdClientCertificate
- etcdClientPrivateKey
- etcdServerCertificate
- etcdServerPrivateKey
- etcdPeerCertificates
- etcdPeerPrivateKeys
To refer to a keyvault secret, the value of the parameter in the api model file should be formatted as:
"<PARAMETER>": "/subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.KeyVault/vaults/<KV_NAME>/secrets/<NAME>[/<VERSION>]"
where:
<SUB_ID> is the subscription ID of the keyvault
<RG_NAME> is the resource group of the keyvault
<KV_NAME> is the name of the keyvault
<NAME> is the name of the secret.
<VERSION> (optional) is the version of the secret (default: the latest version)
This will generate a reference block in the parameters file:
"reference": {
"keyVault": {
"id": "/subscriptions/<SUB_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.KeyVault/vaults/<KV_NAME>"
},
"secretName": "<NAME>"
"secretVersion": "<VERSION>"
}
**/
// KeyVaultID represents a KeyVault instance on Azure
type KeyVaultID struct {
ID string `json:"id"`
}
// KeyVaultRef represents a reference to KeyVault instance on Azure
type KeyVaultRef struct {
KeyVault KeyVaultID `json:"keyVault"`
SecretName string `json:"secretName"`
SecretVersion string `json:"secretVersion,omitempty"`
}
type paramsMap map[string]interface{}
var keyvaultSecretPathRe *regexp.Regexp
func init() {
keyvaultSecretPathRe = regexp.MustCompile(`^(/subscriptions/\S+/resourceGroups/\S+/providers/Microsoft.KeyVault/vaults/\S+)/secrets/([^/\s]+)(/(\S+))?$`)
}
func (t *TemplateGenerator) verifyFiles() error {
allFiles := commonTemplateFiles
allFiles = append(allFiles, dcosTemplateFiles...)
allFiles = append(allFiles, kubernetesTemplateFiles...)
allFiles = append(allFiles, swarmTemplateFiles...)
for _, file := range allFiles {
if _, err := Asset(file); err != nil {
return t.Translator.Errorf("template file %s does not exist", file)
}
}
return nil
}
// TemplateGenerator represents the object that performs the template generation.
type TemplateGenerator struct {
ClassicMode bool
Translator *i18n.Translator
}
// InitializeTemplateGenerator creates a new template generator object
func InitializeTemplateGenerator(ctx Context, classicMode bool) (*TemplateGenerator, error) {
t := &TemplateGenerator{
ClassicMode: classicMode,
Translator: ctx.Translator,
}
if err := t.verifyFiles(); err != nil {
return nil, err
}
return t, nil
}
// GenerateTemplate generates the template from the API Model
func (t *TemplateGenerator) GenerateTemplate(containerService *api.ContainerService, generatorCode string, isUpgrade bool) (templateRaw string, parametersRaw string, certsGenerated bool, err error) {
// named return values are used in order to set err in case of a panic
templateRaw = ""
parametersRaw = ""
err = nil
var templ *template.Template
properties := containerService.Properties
// save the current orchestrator version and restore it after deploying.
// this allows us to deploy agents on the most recent patch without updating the orchestator version in the object
orchVersion := properties.OrchestratorProfile.OrchestratorVersion
defer func() {
properties.OrchestratorProfile.OrchestratorVersion = orchVersion
}()
if certsGenerated, err = SetPropertiesDefaults(containerService, isUpgrade); err != nil {
return templateRaw, parametersRaw, certsGenerated, err
}
templ = template.New("acs template").Funcs(t.getTemplateFuncMap(containerService))
files, baseFile, e := t.prepareTemplateFiles(properties)
if e != nil {
return "", "", false, e
}
for _, file := range files {
bytes, e := Asset(file)
if e != nil {
err = t.Translator.Errorf("Error reading file %s, Error: %s", file, e.Error())
return templateRaw, parametersRaw, certsGenerated, err
}
if _, err = templ.New(file).Parse(string(bytes)); err != nil {
return templateRaw, parametersRaw, certsGenerated, err
}
}
// template generation may have panics in the called functions. This catches those panics
// and ensures the panic is returned as an error
defer func() {
if r := recover(); r != nil {
s := debug.Stack()
err = fmt.Errorf("%v - %s", r, s)
// invalidate the template and the parameters
templateRaw = ""
parametersRaw = ""
}
}()
if !ValidateDistro(containerService) {
return templateRaw, parametersRaw, certsGenerated, fmt.Errorf("Invalid distro")
}
var b bytes.Buffer
if err = templ.ExecuteTemplate(&b, baseFile, properties); err != nil {
return templateRaw, parametersRaw, certsGenerated, err
}
templateRaw = b.String()
var parametersMap paramsMap
if parametersMap, err = getParameters(containerService, t.ClassicMode, generatorCode); err != nil {
return templateRaw, parametersRaw, certsGenerated, err
}
var parameterBytes []byte
if parameterBytes, err = helpers.JSONMarshal(parametersMap, false); err != nil {
return templateRaw, parametersRaw, certsGenerated, err
}
parametersRaw = string(parameterBytes)
return templateRaw, parametersRaw, certsGenerated, err
}
// GenerateClusterID creates a unique 8 string cluster ID
func GenerateClusterID(properties *api.Properties) string {
uniqueNameSuffixSize := 8
// the name suffix uniquely identifies the cluster and is generated off a hash
// from the master dns name
h := fnv.New64a()
if properties.MasterProfile != nil {
h.Write([]byte(properties.MasterProfile.DNSPrefix))
} else if properties.HostedMasterProfile != nil {
h.Write([]byte(properties.HostedMasterProfile.DNSPrefix))
} else {
h.Write([]byte(properties.AgentPoolProfiles[0].Name))
}
rand.Seed(int64(h.Sum64()))
return fmt.Sprintf("%08d", rand.Uint32())[:uniqueNameSuffixSize]
}
// GenerateKubeConfig returns a JSON string representing the KubeConfig
func GenerateKubeConfig(properties *api.Properties, location string) (string, error) {
b, err := Asset(kubeConfigJSON)
if err != nil {
return "", fmt.Errorf("error reading kube config template file %s: %s", kubeConfigJSON, err.Error())
}
kubeconfig := string(b)
// variable replacement
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"variables('caCertificate')\"}}", base64.StdEncoding.EncodeToString([]byte(properties.CertificateProfile.CaCertificate)), -1)
if properties.OrchestratorProfile.KubernetesConfig.PrivateCluster != nil && helpers.IsTrueBoolPointer(properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.Enabled) {
if properties.MasterProfile.Count > 1 {
// more than 1 master, use the internal lb IP
firstMasterIP := net.ParseIP(properties.MasterProfile.FirstConsecutiveStaticIP).To4()
if firstMasterIP == nil {
return "", fmt.Errorf("MasterProfile.FirstConsecutiveStaticIP '%s' is an invalid IP address", properties.MasterProfile.FirstConsecutiveStaticIP)
}
lbIP := net.IP{firstMasterIP[0], firstMasterIP[1], firstMasterIP[2], firstMasterIP[3] + byte(DefaultInternalLbStaticIPOffset)}
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).dnsSettings.fqdn\"}}", lbIP.String(), -1)
} else {
// Master count is 1, use the master IP
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).dnsSettings.fqdn\"}}", properties.MasterProfile.FirstConsecutiveStaticIP, -1)
}
} else {
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVerbatim \"reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).dnsSettings.fqdn\"}}", FormatAzureProdFQDN(properties.MasterProfile.DNSPrefix, location), -1)
}
kubeconfig = strings.Replace(kubeconfig, "{{WrapAsVariable \"resourceGroup\"}}", properties.MasterProfile.DNSPrefix, -1)
var authInfo string
if properties.AADProfile == nil {
authInfo = fmt.Sprintf("{\"client-certificate-data\":\"%v\",\"client-key-data\":\"%v\"}",
base64.StdEncoding.EncodeToString([]byte(properties.CertificateProfile.KubeConfigCertificate)),
base64.StdEncoding.EncodeToString([]byte(properties.CertificateProfile.KubeConfigPrivateKey)))
} else {
tenantID := properties.AADProfile.TenantID
if len(tenantID) == 0 {
tenantID = "common"
}
authInfo = fmt.Sprintf("{\"auth-provider\":{\"name\":\"azure\",\"config\":{\"environment\":\"%v\",\"tenant-id\":\"%v\",\"apiserver-id\":\"%v\",\"client-id\":\"%v\"}}}",
GetCloudTargetEnv(location),
tenantID,
properties.AADProfile.ServerAppID,
properties.AADProfile.ClientAppID)
}
kubeconfig = strings.Replace(kubeconfig, "{{authInfo}}", authInfo, -1)
return kubeconfig, nil
}
func (t *TemplateGenerator) prepareTemplateFiles(properties *api.Properties) ([]string, string, error) {
var files []string
var baseFile string
switch properties.OrchestratorProfile.OrchestratorType {
case api.DCOS:
files = append(commonTemplateFiles, dcosTemplateFiles...)
baseFile = dcosBaseFile
case api.Swarm:
files = append(commonTemplateFiles, swarmTemplateFiles...)
baseFile = swarmBaseFile
case api.Kubernetes:
files = append(commonTemplateFiles, kubernetesTemplateFiles...)
baseFile = kubernetesBaseFile
case api.SwarmMode:
files = append(commonTemplateFiles, swarmModeTemplateFiles...)
baseFile = swarmBaseFile
default:
return nil, "", t.Translator.Errorf("orchestrator '%s' is unsupported", properties.OrchestratorProfile.OrchestratorType)
}
return files, baseFile, nil
}
// FormatAzureProdFQDNs constructs all possible Azure prod fqdn
func FormatAzureProdFQDNs(fqdnPrefix string) []string {
var fqdns []string
for _, location := range AzureLocations {
fqdns = append(fqdns, FormatAzureProdFQDN(fqdnPrefix, location))
}
return fqdns
}
// FormatAzureProdFQDN constructs an Azure prod fqdn
func FormatAzureProdFQDN(fqdnPrefix string, location string) string {
var FQDNFormat string
switch GetCloudTargetEnv(location) {
case azureChinaCloud:
FQDNFormat = AzureChinaCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix
case azureGermanCloud:
FQDNFormat = AzureGermanCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix
case azureUSGovernmentCloud:
FQDNFormat = AzureUSGovernmentCloud.EndpointConfig.ResourceManagerVMDNSSuffix
default:
FQDNFormat = AzureCloudSpec.EndpointConfig.ResourceManagerVMDNSSuffix
}
return fmt.Sprintf("%s.%s."+FQDNFormat, fqdnPrefix, location)
}
//GetCloudSpecConfig returns the kubenernetes container images url configurations based on the deploy target environment
//for example: if the target is the public azure, then the default container image url should be k8s-gcrio.azureedge.net/...
//if the target is azure china, then the default container image should be mirror.azure.cn:5000/google_container/...
func GetCloudSpecConfig(location string) AzureEnvironmentSpecConfig {
switch GetCloudTargetEnv(location) {
case azureChinaCloud:
return AzureChinaCloudSpec
case azureGermanCloud:
return AzureGermanCloudSpec
case azureUSGovernmentCloud:
return AzureUSGovernmentCloud
default:
return AzureCloudSpec
}
}
// ValidateDistro checks if the requested orchestrator type is supported on the requested Linux distro.
func ValidateDistro(cs *api.ContainerService) bool {
// Check Master distro
if cs.Properties.MasterProfile != nil && cs.Properties.MasterProfile.Distro == api.RHEL && cs.Properties.OrchestratorProfile.OrchestratorType != api.SwarmMode {
log.Fatalf("Orchestrator type %s not suported on RHEL Master", cs.Properties.OrchestratorProfile.OrchestratorType)
return false
}
// Check Agent distros
for _, agentProfile := range cs.Properties.AgentPoolProfiles {
if agentProfile.Distro == api.RHEL && cs.Properties.OrchestratorProfile.OrchestratorType != api.SwarmMode {
log.Fatalf("Orchestrator type %s not suported on RHEL Agent", cs.Properties.OrchestratorProfile.OrchestratorType)
return false
}
}
return true
}
// GetCloudTargetEnv determines and returns whether the region is a sovereign cloud which
// have their own data compliance regulations (China/Germany/USGov) or standard
// Azure public cloud
func GetCloudTargetEnv(location string) string {
loc := strings.ToLower(strings.Join(strings.Fields(location), ""))
switch {
case loc == "chinaeast" || loc == "chinanorth":
return azureChinaCloud
case loc == "germanynortheast" || loc == "germanycentral":
return azureGermanCloud
case strings.HasPrefix(loc, "usgov") || strings.HasPrefix(loc, "usdod"):
return azureUSGovernmentCloud
default:
return azurePublicCloud
}
}
func getParameters(cs *api.ContainerService, isClassicMode bool, generatorCode string) (paramsMap, error) {
properties := cs.Properties
location := cs.Location
parametersMap := paramsMap{}
cloudSpecConfig := GetCloudSpecConfig(location)
// Master Parameters
addValue(parametersMap, "location", location)
// Identify Master distro
masterDistro := getMasterDistro(properties.MasterProfile)
if properties.MasterProfile != nil && properties.MasterProfile.ImageRef != nil {
addValue(parametersMap, "osImageName", properties.MasterProfile.ImageRef.Name)
addValue(parametersMap, "osImageResourceGroup", properties.MasterProfile.ImageRef.ResourceGroup)
}
addValue(parametersMap, "osImageOffer", cloudSpecConfig.OSImageConfig[masterDistro].ImageOffer)
addValue(parametersMap, "osImageSKU", cloudSpecConfig.OSImageConfig[masterDistro].ImageSku)
addValue(parametersMap, "osImagePublisher", cloudSpecConfig.OSImageConfig[masterDistro].ImagePublisher)
addValue(parametersMap, "osImageVersion", cloudSpecConfig.OSImageConfig[masterDistro].ImageVersion)
addValue(parametersMap, "fqdnEndpointSuffix", cloudSpecConfig.EndpointConfig.ResourceManagerVMDNSSuffix)
addValue(parametersMap, "targetEnvironment", GetCloudTargetEnv(location))
addValue(parametersMap, "linuxAdminUsername", properties.LinuxProfile.AdminUsername)
// masterEndpointDNSNamePrefix is the basis for storage account creation across dcos, swarm, and k8s
if properties.MasterProfile != nil {
// MasterProfile exists, uses master DNS prefix
addValue(parametersMap, "masterEndpointDNSNamePrefix", properties.MasterProfile.DNSPrefix)
} else if properties.HostedMasterProfile != nil {
// Agents only, use cluster DNS prefix
addValue(parametersMap, "masterEndpointDNSNamePrefix", properties.HostedMasterProfile.DNSPrefix)
}
if properties.MasterProfile != nil {
if properties.MasterProfile.IsCustomVNET() {
addValue(parametersMap, "masterVnetSubnetID", properties.MasterProfile.VnetSubnetID)
if properties.OrchestratorProfile.IsKubernetes() {
addValue(parametersMap, "vnetCidr", properties.MasterProfile.VnetCidr)
}
} else {
addValue(parametersMap, "masterSubnet", properties.MasterProfile.Subnet)
}
addValue(parametersMap, "firstConsecutiveStaticIP", properties.MasterProfile.FirstConsecutiveStaticIP)
addValue(parametersMap, "masterVMSize", properties.MasterProfile.VMSize)
if isClassicMode {
addValue(parametersMap, "masterCount", properties.MasterProfile.Count)
}
}
if properties.HostedMasterProfile != nil {
addValue(parametersMap, "masterSubnet", properties.HostedMasterProfile.Subnet)
}
addValue(parametersMap, "sshRSAPublicKey", properties.LinuxProfile.SSH.PublicKeys[0].KeyData)
for i, s := range properties.LinuxProfile.Secrets {
addValue(parametersMap, fmt.Sprintf("linuxKeyVaultID%d", i), s.SourceVault.ID)
for j, c := range s.VaultCertificates {
addValue(parametersMap, fmt.Sprintf("linuxKeyVaultID%dCertificateURL%d", i, j), c.CertificateURL)
}
}
//Swarm and SwarmMode Parameters
if properties.OrchestratorProfile.OrchestratorType == api.Swarm || properties.OrchestratorProfile.OrchestratorType == api.SwarmMode {
var dockerEngineRepo, dockerComposeDownloadURL string
if cloudSpecConfig.DockerSpecConfig.DockerEngineRepo == "" {
dockerEngineRepo = DefaultDockerEngineRepo
} else {
dockerEngineRepo = cloudSpecConfig.DockerSpecConfig.DockerEngineRepo
}
if cloudSpecConfig.DockerSpecConfig.DockerComposeDownloadURL == "" {
dockerComposeDownloadURL = DefaultDockerComposeURL
} else {
dockerComposeDownloadURL = cloudSpecConfig.DockerSpecConfig.DockerComposeDownloadURL
}
addValue(parametersMap, "dockerEngineDownloadRepo", dockerEngineRepo)
addValue(parametersMap, "dockerComposeDownloadURL", dockerComposeDownloadURL)
}
// Kubernetes Parameters
if properties.OrchestratorProfile.OrchestratorType == api.Kubernetes {
k8sVersion := properties.OrchestratorProfile.OrchestratorVersion
kubernetesHyperkubeSpec := properties.OrchestratorProfile.KubernetesConfig.KubernetesImageBase + KubeConfigs[k8sVersion]["hyperkube"]
if properties.OrchestratorProfile.KubernetesConfig.CustomHyperkubeImage != "" {
kubernetesHyperkubeSpec = properties.OrchestratorProfile.KubernetesConfig.CustomHyperkubeImage
}
dockerEngineVersion := KubeConfigs[k8sVersion]["dockerEngineVersion"]
if properties.OrchestratorProfile.KubernetesConfig.DockerEngineVersion != "" {
dockerEngineVersion = properties.OrchestratorProfile.KubernetesConfig.DockerEngineVersion
}
if properties.CertificateProfile != nil {
addSecret(parametersMap, "apiServerCertificate", properties.CertificateProfile.APIServerCertificate, true)
addSecret(parametersMap, "apiServerPrivateKey", properties.CertificateProfile.APIServerPrivateKey, true)
addSecret(parametersMap, "caCertificate", properties.CertificateProfile.CaCertificate, true)
addSecret(parametersMap, "caPrivateKey", properties.CertificateProfile.CaPrivateKey, true)
addSecret(parametersMap, "clientCertificate", properties.CertificateProfile.ClientCertificate, true)
addSecret(parametersMap, "clientPrivateKey", properties.CertificateProfile.ClientPrivateKey, true)
addSecret(parametersMap, "kubeConfigCertificate", properties.CertificateProfile.KubeConfigCertificate, true)
addSecret(parametersMap, "kubeConfigPrivateKey", properties.CertificateProfile.KubeConfigPrivateKey, true)
if properties.MasterProfile != nil {
addSecret(parametersMap, "etcdServerCertificate", properties.CertificateProfile.EtcdServerCertificate, true)
addSecret(parametersMap, "etcdServerPrivateKey", properties.CertificateProfile.EtcdServerPrivateKey, true)
addSecret(parametersMap, "etcdClientCertificate", properties.CertificateProfile.EtcdClientCertificate, true)
addSecret(parametersMap, "etcdClientPrivateKey", properties.CertificateProfile.EtcdClientPrivateKey, true)
for i, pc := range properties.CertificateProfile.EtcdPeerCertificates {
addSecret(parametersMap, "etcdPeerCertificate"+strconv.Itoa(i), pc, true)
}
for i, pk := range properties.CertificateProfile.EtcdPeerPrivateKeys {
addSecret(parametersMap, "etcdPeerPrivateKey"+strconv.Itoa(i), pk, true)
}
}
}
if properties.HostedMasterProfile != nil && properties.HostedMasterProfile.FQDN != "" {
addValue(parametersMap, "kubernetesEndpoint", properties.HostedMasterProfile.FQDN)
}
if helpers.IsTrueBoolPointer(properties.OrchestratorProfile.KubernetesConfig.UseCloudControllerManager) {
kubernetesCcmSpec := properties.OrchestratorProfile.KubernetesConfig.KubernetesImageBase + KubeConfigs[k8sVersion]["ccm"]
if properties.OrchestratorProfile.KubernetesConfig.CustomCcmImage != "" {
kubernetesCcmSpec = properties.OrchestratorProfile.KubernetesConfig.CustomCcmImage
}
addValue(parametersMap, "kubernetesCcmImageSpec", kubernetesCcmSpec)
}
addValue(parametersMap, "dockerEngineDownloadRepo", cloudSpecConfig.DockerSpecConfig.DockerEngineRepo)
addValue(parametersMap, "kubeDNSServiceIP", properties.OrchestratorProfile.KubernetesConfig.DNSServiceIP)
addValue(parametersMap, "kubeServiceCidr", properties.OrchestratorProfile.KubernetesConfig.ServiceCIDR)
addValue(parametersMap, "kubernetesHyperkubeSpec", kubernetesHyperkubeSpec)
addValue(parametersMap, "dockerEngineVersion", dockerEngineVersion)
addValue(parametersMap, "kubernetesAddonManagerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["addonmanager"])
addValue(parametersMap, "kubernetesAddonResizerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["addonresizer"])
addValue(parametersMap, "kubernetesDNSMasqSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["dnsmasq"])
addValue(parametersMap, "kubernetesExecHealthzSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["exechealthz"])
addValue(parametersMap, "kubernetesHeapsterSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["heapster"])
tillerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultTillerAddonName)
c := getAddonContainersIndexByName(tillerAddon.Containers, DefaultTillerAddonName)
if c > -1 {
addValue(parametersMap, "kubernetesTillerCPURequests", tillerAddon.Containers[c].CPURequests)
addValue(parametersMap, "kubernetesTillerCPULimit", tillerAddon.Containers[c].CPULimits)
addValue(parametersMap, "kubernetesTillerMemoryRequests", tillerAddon.Containers[c].MemoryRequests)
addValue(parametersMap, "kubernetesTillerMemoryLimit", tillerAddon.Containers[c].MemoryLimits)
addValue(parametersMap, "kubernetesTillerMaxHistory", tillerAddon.Config["max-history"])
if tillerAddon.Containers[c].Image != "" {
addValue(parametersMap, "kubernetesTillerSpec", tillerAddon.Containers[c].Image)
} else {
addValue(parametersMap, "kubernetesTillerSpec", cloudSpecConfig.KubernetesSpecConfig.TillerImageBase+KubeConfigs[k8sVersion][DefaultTillerAddonName])
}
}
aciConnectorAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultACIConnectorAddonName)
c = getAddonContainersIndexByName(aciConnectorAddon.Containers, DefaultACIConnectorAddonName)
if c > -1 {
addValue(parametersMap, "kubernetesACIConnectorClientId", aciConnectorAddon.Config["clientId"])
addSecret(parametersMap, "kubernetesACIConnectorClientKey", aciConnectorAddon.Config["clientKey"], false)
addValue(parametersMap, "kubernetesACIConnectorTenantId", aciConnectorAddon.Config["tenantId"])
addValue(parametersMap, "kubernetesACIConnectorSubscriptionId", aciConnectorAddon.Config["subscriptionId"])
addValue(parametersMap, "kubernetesACIConnectorResourceGroup", aciConnectorAddon.Config["resourceGroup"])
addValue(parametersMap, "kubernetesACIConnectorNodeName", aciConnectorAddon.Config["nodeName"])
addValue(parametersMap, "kubernetesACIConnectorOS", aciConnectorAddon.Config["os"])
addValue(parametersMap, "kubernetesACIConnectorTaint", aciConnectorAddon.Config["taint"])
addValue(parametersMap, "kubernetesACIConnectorRegion", aciConnectorAddon.Config["region"])
addValue(parametersMap, "kubernetesACIConnectorCPURequests", aciConnectorAddon.Containers[c].CPURequests)
addValue(parametersMap, "kubernetesACIConnectorCPULimit", aciConnectorAddon.Containers[c].CPULimits)
addValue(parametersMap, "kubernetesACIConnectorMemoryRequests", aciConnectorAddon.Containers[c].MemoryRequests)
addValue(parametersMap, "kubernetesACIConnectorMemoryLimit", aciConnectorAddon.Containers[c].MemoryLimits)
if aciConnectorAddon.Containers[c].Image != "" {
addValue(parametersMap, "kubernetesACIConnectorSpec", aciConnectorAddon.Containers[c].Image)
} else {
addValue(parametersMap, "kubernetesACIConnectorSpec", cloudSpecConfig.KubernetesSpecConfig.ACIConnectorImageBase+KubeConfigs[k8sVersion][DefaultACIConnectorAddonName])
}
}
dashboardAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultDashboardAddonName)
c = getAddonContainersIndexByName(dashboardAddon.Containers, DefaultDashboardAddonName)
if c > -1 {
addValue(parametersMap, "kubernetesDashboardCPURequests", dashboardAddon.Containers[c].CPURequests)
addValue(parametersMap, "kubernetesDashboardCPULimit", dashboardAddon.Containers[c].CPULimits)
addValue(parametersMap, "kubernetesDashboardMemoryRequests", dashboardAddon.Containers[c].MemoryRequests)
addValue(parametersMap, "kubernetesDashboardMemoryLimit", dashboardAddon.Containers[c].MemoryLimits)
if dashboardAddon.Containers[c].Image != "" {
addValue(parametersMap, "kubernetesDashboardSpec", dashboardAddon.Containers[c].Image)
} else {
addValue(parametersMap, "kubernetesDashboardSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion][DefaultDashboardAddonName])
}
}
reschedulerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultReschedulerAddonName)
c = getAddonContainersIndexByName(reschedulerAddon.Containers, DefaultReschedulerAddonName)
if c > -1 {
addValue(parametersMap, "kubernetesReschedulerCPURequests", reschedulerAddon.Containers[c].CPURequests)
addValue(parametersMap, "kubernetesReschedulerCPULimit", reschedulerAddon.Containers[c].CPULimits)
addValue(parametersMap, "kubernetesReschedulerMemoryRequests", reschedulerAddon.Containers[c].MemoryRequests)
addValue(parametersMap, "kubernetesReschedulerMemoryLimit", reschedulerAddon.Containers[c].MemoryLimits)
if reschedulerAddon.Containers[c].Image != "" {
addValue(parametersMap, "kubernetesReschedulerSpec", dashboardAddon.Containers[c].Image)
} else {
addValue(parametersMap, "kubernetesReschedulerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion][DefaultReschedulerAddonName])
}
}
metricsServerAddon := getAddonByName(properties.OrchestratorProfile.KubernetesConfig.Addons, DefaultMetricsServerAddonName)
c = getAddonContainersIndexByName(metricsServerAddon.Containers, DefaultMetricsServerAddonName)
if c > -1 {
if metricsServerAddon.Containers[c].Image != "" {
addValue(parametersMap, "kubernetesMetricsServerSpec", metricsServerAddon.Containers[c].Image)
} else {
addValue(parametersMap, "kubernetesMetricsServerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion][DefaultMetricsServerAddonName])
}
}
addValue(parametersMap, "kubernetesKubeDNSSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["dns"])
addValue(parametersMap, "kubernetesPodInfraContainerSpec", cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase+KubeConfigs[k8sVersion]["pause"])
addValue(parametersMap, "cloudProviderBackoff", strconv.FormatBool(properties.OrchestratorProfile.KubernetesConfig.CloudProviderBackoff))
addValue(parametersMap, "cloudProviderBackoffRetries", strconv.Itoa(properties.OrchestratorProfile.KubernetesConfig.CloudProviderBackoffRetries))
addValue(parametersMap, "cloudProviderBackoffExponent", strconv.FormatFloat(properties.OrchestratorProfile.KubernetesConfig.CloudProviderBackoffExponent, 'f', -1, 64))
addValue(parametersMap, "cloudProviderBackoffDuration", strconv.Itoa(properties.OrchestratorProfile.KubernetesConfig.CloudProviderBackoffDuration))
addValue(parametersMap, "cloudProviderBackoffJitter", strconv.FormatFloat(properties.OrchestratorProfile.KubernetesConfig.CloudProviderBackoffJitter, 'f', -1, 64))
addValue(parametersMap, "cloudProviderRatelimit", strconv.FormatBool(properties.OrchestratorProfile.KubernetesConfig.CloudProviderRateLimit))
addValue(parametersMap, "cloudProviderRatelimitQPS", strconv.FormatFloat(properties.OrchestratorProfile.KubernetesConfig.CloudProviderRateLimitQPS, 'f', -1, 64))
addValue(parametersMap, "cloudProviderRatelimitBucket", strconv.Itoa(properties.OrchestratorProfile.KubernetesConfig.CloudProviderRateLimitBucket))
addValue(parametersMap, "kubeClusterCidr", properties.OrchestratorProfile.KubernetesConfig.ClusterSubnet)
addValue(parametersMap, "kubernetesNonMasqueradeCidr", properties.OrchestratorProfile.KubernetesConfig.KubeletConfig["--non-masquerade-cidr"])
addValue(parametersMap, "kubernetesKubeletClusterDomain", properties.OrchestratorProfile.KubernetesConfig.KubeletConfig["--cluster-domain"])
addValue(parametersMap, "generatorCode", generatorCode)
if properties.HostedMasterProfile != nil {
addValue(parametersMap, "orchestratorName", "aks")
} else {
addValue(parametersMap, "orchestratorName", DefaultOrchestratorName)
}
addValue(parametersMap, "dockerBridgeCidr", properties.OrchestratorProfile.KubernetesConfig.DockerBridgeSubnet)
addValue(parametersMap, "networkPolicy", properties.OrchestratorProfile.KubernetesConfig.NetworkPolicy)
addValue(parametersMap, "containerRuntime", properties.OrchestratorProfile.KubernetesConfig.ContainerRuntime)
addValue(parametersMap, "cniPluginsURL", cloudSpecConfig.KubernetesSpecConfig.CNIPluginsDownloadURL)
addValue(parametersMap, "vnetCniLinuxPluginsURL", cloudSpecConfig.KubernetesSpecConfig.VnetCNILinuxPluginsDownloadURL)
addValue(parametersMap, "vnetCniWindowsPluginsURL", cloudSpecConfig.KubernetesSpecConfig.VnetCNIWindowsPluginsDownloadURL)
addValue(parametersMap, "gchighthreshold", properties.OrchestratorProfile.KubernetesConfig.GCHighThreshold)
addValue(parametersMap, "gclowthreshold", properties.OrchestratorProfile.KubernetesConfig.GCLowThreshold)
addValue(parametersMap, "etcdDownloadURLBase", cloudSpecConfig.KubernetesSpecConfig.EtcdDownloadURLBase)
addValue(parametersMap, "etcdVersion", cs.Properties.OrchestratorProfile.KubernetesConfig.EtcdVersion)
addValue(parametersMap, "etcdDiskSizeGB", cs.Properties.OrchestratorProfile.KubernetesConfig.EtcdDiskSizeGB)
if cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateJumpboxProvision() {
addValue(parametersMap, "jumpboxVMName", cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.Name)
addValue(parametersMap, "jumpboxVMSize", cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.VMSize)
addValue(parametersMap, "jumpboxUsername", cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.Username)
addValue(parametersMap, "jumpboxOSDiskSizeGB", cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.OSDiskSizeGB)
addValue(parametersMap, "jumpboxPublicKey", cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.PublicKey)
addValue(parametersMap, "jumpboxStorageProfile", cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.JumpboxProfile.StorageProfile)
}
if properties.OrchestratorProfile.KubernetesConfig == nil ||
!properties.OrchestratorProfile.KubernetesConfig.UseManagedIdentity {
addValue(parametersMap, "servicePrincipalClientId", properties.ServicePrincipalProfile.ClientID)
if properties.ServicePrincipalProfile.KeyvaultSecretRef != nil {
addKeyvaultReference(parametersMap, "servicePrincipalClientSecret",
properties.ServicePrincipalProfile.KeyvaultSecretRef.VaultID,
properties.ServicePrincipalProfile.KeyvaultSecretRef.SecretName,
properties.ServicePrincipalProfile.KeyvaultSecretRef.SecretVersion)
} else {
addValue(parametersMap, "servicePrincipalClientSecret", properties.ServicePrincipalProfile.Secret)
}
}
if properties.AADProfile != nil {
addValue(parametersMap, "aadTenantId", properties.AADProfile.TenantID)
if properties.AADProfile.AdminGroupID != "" {
addValue(parametersMap, "aadAdminGroupId", properties.AADProfile.AdminGroupID)
}
}
}
if strings.HasPrefix(properties.OrchestratorProfile.OrchestratorType, api.DCOS) {
dcosBootstrapURL := cloudSpecConfig.DCOSSpecConfig.DCOS188BootstrapDownloadURL
dcosWindowsBootstrapURL := cloudSpecConfig.DCOSSpecConfig.DCOSWindowsBootstrapDownloadURL
dcosRepositoryURL := cloudSpecConfig.DCOSSpecConfig.DcosRepositoryURL
dcosClusterPackageListID := cloudSpecConfig.DCOSSpecConfig.DcosClusterPackageListID
dcosProviderPackageID := cloudSpecConfig.DCOSSpecConfig.DcosProviderPackageID
switch properties.OrchestratorProfile.OrchestratorType {
case api.DCOS:
switch properties.OrchestratorProfile.OrchestratorVersion {
case api.DCOSVersion1Dot8Dot8:
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS188BootstrapDownloadURL
case api.DCOSVersion1Dot9Dot0:
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS190BootstrapDownloadURL
case api.DCOSVersion1Dot9Dot8:
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS198BootstrapDownloadURL
case api.DCOSVersion1Dot10Dot0:
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS110BootstrapDownloadURL
case api.DCOSVersion1Dot11Dot0:
dcosBootstrapURL = cloudSpecConfig.DCOSSpecConfig.DCOS111BootstrapDownloadURL
}
}
if properties.OrchestratorProfile.DcosConfig != nil {
if properties.OrchestratorProfile.DcosConfig.DcosWindowsBootstrapURL != "" {
dcosWindowsBootstrapURL = properties.OrchestratorProfile.DcosConfig.DcosWindowsBootstrapURL
}
if properties.OrchestratorProfile.DcosConfig.DcosBootstrapURL != "" {
dcosBootstrapURL = properties.OrchestratorProfile.DcosConfig.DcosBootstrapURL
}
if len(properties.OrchestratorProfile.DcosConfig.Registry) > 0 {
addValue(parametersMap, "registry", properties.OrchestratorProfile.DcosConfig.Registry)
addValue(parametersMap, "registryKey", base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", properties.OrchestratorProfile.DcosConfig.RegistryUser, properties.OrchestratorProfile.DcosConfig.RegistryPass))))
}
if properties.OrchestratorProfile.DcosConfig.DcosRepositoryURL != "" {
dcosRepositoryURL = properties.OrchestratorProfile.DcosConfig.DcosRepositoryURL
} else {
dcosRepositoryURL = getDCOSDefaultRepositoryURL(
properties.OrchestratorProfile.OrchestratorType,
properties.OrchestratorProfile.OrchestratorVersion)
}
if properties.OrchestratorProfile.DcosConfig.DcosClusterPackageListID != "" {
dcosClusterPackageListID = properties.OrchestratorProfile.DcosConfig.DcosClusterPackageListID
} else {
dcosClusterPackageListID = getDCOSDefaultClusterPackageListGUID(
properties.OrchestratorProfile.OrchestratorType,
properties.OrchestratorProfile.OrchestratorVersion,
properties.MasterProfile.Count)
}
if properties.OrchestratorProfile.DcosConfig.DcosProviderPackageID != "" {
dcosProviderPackageID = properties.OrchestratorProfile.DcosConfig.DcosProviderPackageID
} else {
dcosProviderPackageID = getDCOSDefaultProviderPackageGUID(
properties.OrchestratorProfile.OrchestratorType,
properties.OrchestratorProfile.OrchestratorVersion,
properties.MasterProfile.Count)
}
}
addValue(parametersMap, "dcosBootstrapURL", dcosBootstrapURL)
addValue(parametersMap, "dcosWindowsBootstrapURL", dcosWindowsBootstrapURL)
addValue(parametersMap, "dcosRepositoryURL", dcosRepositoryURL)
addValue(parametersMap, "dcosClusterPackageListID", dcosClusterPackageListID)
addValue(parametersMap, "dcosProviderPackageID", dcosProviderPackageID)
}
// Agent parameters
for _, agentProfile := range properties.AgentPoolProfiles {
addValue(parametersMap, fmt.Sprintf("%sCount", agentProfile.Name), agentProfile.Count)
addValue(parametersMap, fmt.Sprintf("%sVMSize", agentProfile.Name), agentProfile.VMSize)
if agentProfile.IsCustomVNET() {
addValue(parametersMap, fmt.Sprintf("%sVnetSubnetID", agentProfile.Name), agentProfile.VnetSubnetID)
} else {
addValue(parametersMap, fmt.Sprintf("%sSubnet", agentProfile.Name), agentProfile.Subnet)
}
if len(agentProfile.Ports) > 0 {
addValue(parametersMap, fmt.Sprintf("%sEndpointDNSNamePrefix", agentProfile.Name), agentProfile.DNSPrefix)
}
// Unless distro is defined, default distro is configured by defaults#setAgentNetworkDefaults
// Ignores Windows OS
if !(agentProfile.OSType == api.Windows) {
if agentProfile.ImageRef != nil {
addValue(parametersMap, fmt.Sprintf("%sosImageName", agentProfile.Name), agentProfile.ImageRef.Name)
addValue(parametersMap, fmt.Sprintf("%sosImageResourceGroup", agentProfile.Name), agentProfile.ImageRef.ResourceGroup)
}
addValue(parametersMap, fmt.Sprintf("%sosImageOffer", agentProfile.Name), cloudSpecConfig.OSImageConfig[agentProfile.Distro].ImageOffer)
addValue(parametersMap, fmt.Sprintf("%sosImageSKU", agentProfile.Name), cloudSpecConfig.OSImageConfig[agentProfile.Distro].ImageSku)
addValue(parametersMap, fmt.Sprintf("%sosImagePublisher", agentProfile.Name), cloudSpecConfig.OSImageConfig[agentProfile.Distro].ImagePublisher)
addValue(parametersMap, fmt.Sprintf("%sosImageVersion", agentProfile.Name), cloudSpecConfig.OSImageConfig[agentProfile.Distro].ImageVersion)
}
}
// Windows parameters
if properties.HasWindows() {
addValue(parametersMap, "windowsAdminUsername", properties.WindowsProfile.AdminUsername)
addSecret(parametersMap, "windowsAdminPassword", properties.WindowsProfile.AdminPassword, false)
if properties.WindowsProfile.ImageVersion != "" {
addValue(parametersMap, "agentWindowsVersion", properties.WindowsProfile.ImageVersion)
}
if properties.WindowsProfile.WindowsImageSourceURL != "" {
addValue(parametersMap, "agentWindowsSourceUrl", properties.WindowsProfile.WindowsImageSourceURL)
}
if properties.OrchestratorProfile.OrchestratorType == api.Kubernetes {
k8sVersion := properties.OrchestratorProfile.OrchestratorVersion
addValue(parametersMap, "kubeBinariesSASURL", cloudSpecConfig.KubernetesSpecConfig.KubeBinariesSASURLBase+KubeConfigs[k8sVersion]["windowszip"])
addValue(parametersMap, "windowsPackageSASURLBase", cloudSpecConfig.KubernetesSpecConfig.WindowsPackageSASURLBase)
addValue(parametersMap, "kubeBinariesVersion", k8sVersion)
addValue(parametersMap, "windowsTelemetryGUID", cloudSpecConfig.KubernetesSpecConfig.WindowsTelemetryGUID)
}
for i, s := range properties.WindowsProfile.Secrets {
addValue(parametersMap, fmt.Sprintf("windowsKeyVaultID%d", i), s.SourceVault.ID)
for j, c := range s.VaultCertificates {
addValue(parametersMap, fmt.Sprintf("windowsKeyVaultID%dCertificateURL%d", i, j), c.CertificateURL)
addValue(parametersMap, fmt.Sprintf("windowsKeyVaultID%dCertificateStore%d", i, j), c.CertificateStore)
}
}
}
for _, extension := range properties.ExtensionProfiles {
if extension.ExtensionParametersKeyVaultRef != nil {
addKeyvaultReference(parametersMap, fmt.Sprintf("%sParameters", extension.Name),
extension.ExtensionParametersKeyVaultRef.VaultID,
extension.ExtensionParametersKeyVaultRef.SecretName,
extension.ExtensionParametersKeyVaultRef.SecretVersion)
} else {
addValue(parametersMap, fmt.Sprintf("%sParameters", extension.Name), extension.ExtensionParameters)
}
}
return parametersMap, nil
}
func addValue(m paramsMap, k string, v interface{}) {
m[k] = paramsMap{
"value": v,
}
}
func addKeyvaultReference(m paramsMap, k string, vaultID, secretName, secretVersion string) {
m[k] = paramsMap{
"reference": &KeyVaultRef{
KeyVault: KeyVaultID{
ID: vaultID,
},
SecretName: secretName,
SecretVersion: secretVersion,
},
}
}
func addSecret(m paramsMap, k string, v interface{}, encode bool) {
str, ok := v.(string)
if !ok {
addValue(m, k, v)
return
}
parts := keyvaultSecretPathRe.FindStringSubmatch(str)
if parts == nil || len(parts) != 5 {
if encode {
addValue(m, k, base64.StdEncoding.EncodeToString([]byte(str)))
} else {
addValue(m, k, str)
}
return
}
addKeyvaultReference(m, k, parts[1], parts[2], parts[4])
}
// getStorageAccountType returns the support managed disk storage tier for a give VM size
func getStorageAccountType(sizeName string) (string, error) {
spl := strings.Split(sizeName, "_")
if len(spl) < 2 {
return "", fmt.Errorf("Invalid sizeName: %s", sizeName)
}
capability := spl[1]
if strings.Contains(strings.ToLower(capability), "s") {
return "Premium_LRS", nil
}
return "Standard_LRS", nil
}
// getTemplateFuncMap returns all functions used in template generation
func (t *TemplateGenerator) getTemplateFuncMap(cs *api.ContainerService) template.FuncMap {
return template.FuncMap{
"IsHostedMaster": func() bool {
return cs.Properties.HostedMasterProfile != nil
},
"IsDCOS19": func() bool {
return cs.Properties.OrchestratorProfile.OrchestratorType == api.DCOS &&
(cs.Properties.OrchestratorProfile.OrchestratorVersion == api.DCOSVersion1Dot9Dot0 ||
cs.Properties.OrchestratorProfile.OrchestratorVersion == api.DCOSVersion1Dot9Dot8)
},
"IsDCOS110": func() bool {
return cs.Properties.OrchestratorProfile.OrchestratorType == api.DCOS &&
cs.Properties.OrchestratorProfile.OrchestratorVersion == api.DCOSVersion1Dot10Dot0
},
"IsDCOS111": func() bool {
return cs.Properties.OrchestratorProfile.OrchestratorType == api.DCOS &&
cs.Properties.OrchestratorProfile.OrchestratorVersion == api.DCOSVersion1Dot11Dot0
},
"IsKubernetesVersionGe": func(version string) bool {
orchestratorVersion, _ := semver.NewVersion(cs.Properties.OrchestratorProfile.OrchestratorVersion)
constraint, _ := semver.NewConstraint(">=" + version)
return cs.Properties.OrchestratorProfile.OrchestratorType == api.Kubernetes && constraint.Check(orchestratorVersion)
},
"IsKubernetesVersionLt": func(version string) bool {
orchestratorVersion, _ := semver.NewVersion(cs.Properties.OrchestratorProfile.OrchestratorVersion)
constraint, _ := semver.NewConstraint("<" + version)
return cs.Properties.OrchestratorProfile.OrchestratorType == api.Kubernetes && constraint.Check(orchestratorVersion)
},
"IsKubernetesVersionTilde": func(version string) bool {
// examples include
// ~2.3 is equivalent to >= 2.3, < 2.4
// ~1.2.x is equivalent to >= 1.2.0, < 1.3.0
orchestratorVersion, _ := semver.NewVersion(cs.Properties.OrchestratorProfile.OrchestratorVersion)
constraint, _ := semver.NewConstraint("~" + version)
return cs.Properties.OrchestratorProfile.OrchestratorType == api.Kubernetes && constraint.Check(orchestratorVersion)
},
"GetMasterKubernetesLabels": func(rg string) string {
var buf bytes.Buffer
buf.WriteString("kubernetes.io/role=master")
buf.WriteString(fmt.Sprintf(",kubernetes.azure.com/cluster=%s", rg))
return buf.String()
},
"GetAgentKubernetesLabels": func(profile *api.AgentPoolProfile, rg string) string {
var buf bytes.Buffer
buf.WriteString(fmt.Sprintf("kubernetes.io/role=agent,agentpool=%s", profile.Name))
if profile.StorageProfile == api.ManagedDisks {
storagetier, _ := getStorageAccountType(profile.VMSize)
buf.WriteString(fmt.Sprintf(",storageprofile=managed,storagetier=%s", storagetier))
}
buf.WriteString(fmt.Sprintf(",kubernetes.azure.com/cluster=%s", rg))
for k, v := range profile.CustomNodeLabels {
buf.WriteString(fmt.Sprintf(",%s=%s", k, v))
}
return buf.String()
},
"GetKubeletConfigKeyVals": func(kc *api.KubernetesConfig) string {
kubeletConfig := cs.Properties.OrchestratorProfile.KubernetesConfig.KubeletConfig
if kc.KubeletConfig != nil {
kubeletConfig = kc.KubeletConfig
}
// Order by key for consistency
keys := []string{}
for key := range kubeletConfig {
keys = append(keys, key)
}
sort.Strings(keys)
var buf bytes.Buffer
for _, key := range keys {
buf.WriteString(fmt.Sprintf("%s=%s ", key, kubeletConfig[key]))
}
return buf.String()
},
"GetK8sRuntimeConfigKeyVals": func(config map[string]string) string {
// Order by key for consistency
keys := []string{}
for key := range config {
keys = append(keys, key)
}
sort.Strings(keys)
var buf bytes.Buffer
for _, key := range keys {
buf.WriteString(fmt.Sprintf("\\\"%s=%s\\\", ", key, config[key]))
}
return strings.TrimSuffix(buf.String(), ", ")
},
"HasPrivateRegistry": func() bool {
if cs.Properties.OrchestratorProfile.DcosConfig != nil {
return len(cs.Properties.OrchestratorProfile.DcosConfig.Registry) > 0
}
return false
},
"RequiresFakeAgentOutput": func() bool {
return cs.Properties.OrchestratorProfile.OrchestratorType == api.Kubernetes
},
"IsSwarmMode": func() bool {
return cs.Properties.OrchestratorProfile.IsSwarmMode()
},
"IsKubernetes": func() bool {
return cs.Properties.OrchestratorProfile.IsKubernetes()
},
"IsPublic": func(ports []int) bool {
return len(ports) > 0
},
"IsAzureCNI": func() bool {
return cs.Properties.OrchestratorProfile.IsAzureCNI()
},
"IsPrivateCluster": func() bool {
if !cs.Properties.OrchestratorProfile.IsKubernetes() {
return false
}
return helpers.IsTrueBoolPointer(cs.Properties.OrchestratorProfile.KubernetesConfig.PrivateCluster.Enabled)