This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
defaults.go
302 lines (267 loc) · 8.91 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
package acsengine
import (
"bytes"
"fmt"
"sort"
"strings"
"github.com/Azure/dcos-engine/pkg/api"
"github.com/Azure/dcos-engine/pkg/api/common"
"github.com/blang/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.6"
// CNIPluginVer specifies the version of CNI implementation
// https://github.com/containernetworking/plugins
CNIPluginVer = "v0.7.0"
)
var (
//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.201807030",
}
//DefaultRHELOSImageConfig is the RHEL Linux distribution.
DefaultRHELOSImageConfig = AzureOSImageConfig{
ImageOffer: "RHEL",
ImageSku: "7.3",
ImagePublisher: "RedHat",
ImageVersion: "latest",
}
//DefaultCoreOSImageConfig is the CoreOS Linux distribution.
DefaultCoreOSImageConfig = AzureOSImageConfig{
ImageOffer: "CoreOS",
ImageSku: "Stable",
ImagePublisher: "CoreOS",
ImageVersion: "latest",
}
//AzureCloudSpec is the default configurations for global azure.
AzureCloudSpec = AzureEnvironmentSpecConfig{
//DockerSpecConfig specify the docker engine download repo
DockerSpecConfig: DefaultDockerSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.azure.com",
},
OSImageConfig: map[api.Distro]AzureOSImageConfig{
api.Ubuntu: DefaultUbuntuImageConfig,
api.RHEL: DefaultRHELOSImageConfig,
api.CoreOS: DefaultCoreOSImageConfig,
},
}
//AzureGermanCloudSpec is the German cloud config.
AzureGermanCloudSpec = AzureEnvironmentSpecConfig{
DockerSpecConfig: DefaultDockerSpecConfig,
EndpointConfig: AzureEndpointConfig{
ResourceManagerVMDNSSuffix: "cloudapp.microsoftazure.de",
},
OSImageConfig: map[api.Distro]AzureOSImageConfig{
api.Ubuntu: {
ImageOffer: "UbuntuServer",
ImageSku: "16.04-LTS",
ImagePublisher: "Canonical",
ImageVersion: "latest",
},
api.RHEL: DefaultRHELOSImageConfig,
api.CoreOS: DefaultCoreOSImageConfig,
},
}
//AzureUSGovernmentCloud is the US government config.
AzureUSGovernmentCloud = AzureEnvironmentSpecConfig{
DockerSpecConfig: DefaultDockerSpecConfig,
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",
},
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,
},
}
)
// setPropertiesDefaults for the container Properties, returns true if certs are generated
func setPropertiesDefaults(cs *api.ContainerService, isUpgrade bool) {
properties := cs.Properties
setOrchestratorDefaults(cs)
setMasterNetworkDefaults(properties, isUpgrade)
setAgentNetworkDefaults(properties)
setStorageDefaults(properties)
setExtensionDefaults(properties)
}
// setOrchestratorDefaults for orchestrators
func setOrchestratorDefaults(cs *api.ContainerService) {
a := cs.Properties
if a.OrchestratorProfile == nil {
return
}
o := a.OrchestratorProfile
o.OrchestratorVersion = common.GetValidPatchVersion(
o.OrchestratorType,
o.OrchestratorVersion, a.HasWindows())
switch o.OrchestratorType {
case api.DCOS:
if o.DcosConfig == nil {
o.DcosConfig = &api.DcosConfig{}
}
dcosSemVer, _ := semver.Make(o.OrchestratorVersion)
dcosBootstrapSemVer, _ := semver.Make(common.DCOSVersion1Dot11Dot0)
if !dcosSemVer.LT(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"
}
}
}
}
func setExtensionDefaults(a *api.Properties) {
if a.ExtensionProfiles == nil {
return
}
for _, extension := range a.ExtensionProfiles {
if extension.RootURL == "" {
extension.RootURL = DefaultExtensionsRootURL
}
}
}
// 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.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
}
}
}
}
// 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
}
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 {
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
}
}
}
// setStorageDefaults for agents
func setStorageDefaults(a *api.Properties) {
if a.MasterProfile != nil && len(a.MasterProfile.StorageProfile) == 0 {
a.MasterProfile.StorageProfile = api.ManagedDisks
}
for _, profile := range a.AgentPoolProfiles {
if len(profile.StorageProfile) == 0 {
profile.StorageProfile = api.StorageAccount
}
if len(profile.AvailabilityProfile) == 0 {
profile.AvailabilityProfile = api.VirtualMachineScaleSets
}
if len(profile.ScaleSetEvictionPolicy) == 0 && profile.ScaleSetPriority == api.ScaleSetPriorityLow {
profile.ScaleSetEvictionPolicy = api.ScaleSetEvictionPolicyDelete
}
}
}
func combineValues(inputs ...string) string {
valueMap := make(map[string]string)
for _, input := range inputs {
applyValueStringToMap(valueMap, input)
}
return mapToString(valueMap)
}
func applyValueStringToMap(valueMap map[string]string, input string) {
values := strings.Split(input, ",")
for index := 0; index < len(values); index++ {
// trim spaces (e.g. if the input was "foo=true, bar=true" - we want to drop the space after the comma)
value := strings.Trim(values[index], " ")
valueParts := strings.Split(value, "=")
if len(valueParts) == 2 {
valueMap[valueParts[0]] = valueParts[1]
}
}
}
func mapToString(valueMap map[string]string) string {
// Order by key for consistency
keys := []string{}
for key := range valueMap {
keys = append(keys, key)
}
sort.Strings(keys)
var buf bytes.Buffer
for _, key := range keys {
buf.WriteString(fmt.Sprintf("%s=%s,", key, valueMap[key]))
}
return strings.TrimSuffix(buf.String(), ",")
}