This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 522
/
params_k8s.go
265 lines (235 loc) · 13.1 KB
/
params_k8s.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package engine
import (
"fmt"
"math/rand"
"strconv"
"strings"
"time"
"github.com/Azure/go-autorest/autorest/to"
"github.com/Azure/aks-engine/pkg/api"
"github.com/Azure/aks-engine/pkg/api/common"
)
func assignKubernetesParameters(properties *api.Properties, parametersMap paramsMap,
cloudSpecConfig api.AzureEnvironmentSpecConfig, generatorCode string) {
addValue(parametersMap, "generatorCode", generatorCode)
orchestratorProfile := properties.OrchestratorProfile
if orchestratorProfile.IsKubernetes() {
k8sVersion := orchestratorProfile.OrchestratorVersion
k8sComponents := api.K8sComponentsByVersionMap[k8sVersion]
kubernetesConfig := orchestratorProfile.KubernetesConfig
kubernetesImageBase := kubernetesConfig.KubernetesImageBase
hyperkubeImageBase := kubernetesConfig.KubernetesImageBase
if properties.IsAzureStackCloud() {
kubernetesImageBase = cloudSpecConfig.KubernetesSpecConfig.KubernetesImageBase
}
if kubernetesConfig != nil {
if to.Bool(kubernetesConfig.UseCloudControllerManager) {
kubernetesCcmSpec := kubernetesImageBase + k8sComponents["ccm"]
if kubernetesConfig.CustomCcmImage != "" {
kubernetesCcmSpec = kubernetesConfig.CustomCcmImage
}
addValue(parametersMap, "kubernetesCcmImageSpec", kubernetesCcmSpec)
}
kubernetesHyperkubeSpec := hyperkubeImageBase + k8sComponents["hyperkube"]
if properties.IsAzureStackCloud() {
kubernetesHyperkubeSpec = kubernetesHyperkubeSpec + AzureStackSuffix
}
if kubernetesConfig.CustomHyperkubeImage != "" {
kubernetesHyperkubeSpec = kubernetesConfig.CustomHyperkubeImage
}
addValue(parametersMap, "kubernetesHyperkubeSpec", kubernetesHyperkubeSpec)
addValue(parametersMap, "kubeDNSServiceIP", kubernetesConfig.DNSServiceIP)
if kubernetesConfig.PrivateAzureRegistryServer != "" {
addValue(parametersMap, "privateAzureRegistryServer", kubernetesConfig.PrivateAzureRegistryServer)
}
addValue(parametersMap, "kubernetesAddonManagerSpec", kubernetesImageBase+k8sComponents["addonmanager"])
if orchestratorProfile.NeedsExecHealthz() {
addValue(parametersMap, "kubernetesExecHealthzSpec", kubernetesImageBase+k8sComponents["exechealthz"])
}
addValue(parametersMap, "kubernetesDNSSidecarSpec", kubernetesImageBase+k8sComponents["k8s-dns-sidecar"])
if kubernetesConfig.IsAADPodIdentityEnabled() {
aadPodIdentityAddon := kubernetesConfig.GetAddonByName(AADPodIdentityAddonName)
aadIndex := aadPodIdentityAddon.GetAddonContainersIndexByName(AADPodIdentityAddonName)
if aadIndex > -1 {
addValue(parametersMap, "kubernetesAADPodIdentityEnabled", to.Bool(aadPodIdentityAddon.Enabled))
}
}
if kubernetesConfig.IsACIConnectorEnabled() {
addValue(parametersMap, "kubernetesACIConnectorEnabled", true)
} else {
addValue(parametersMap, "kubernetesACIConnectorEnabled", false)
}
if kubernetesConfig.IsClusterAutoscalerEnabled() {
clusterAutoscalerAddon := kubernetesConfig.GetAddonByName(ClusterAutoscalerAddonName)
clusterAutoScalerIndex := clusterAutoscalerAddon.GetAddonContainersIndexByName(ClusterAutoscalerAddonName)
if clusterAutoScalerIndex > -1 {
addValue(parametersMap, "kubernetesClusterAutoscalerAzureCloud", cloudSpecConfig.CloudName)
addValue(parametersMap, "kubernetesClusterAutoscalerEnabled", true)
addValue(parametersMap, "kubernetesClusterAutoscalerUseManagedIdentity", strings.ToLower(strconv.FormatBool(kubernetesConfig.UseManagedIdentity)))
}
} else {
addValue(parametersMap, "kubernetesClusterAutoscalerEnabled", false)
}
if kubernetesConfig.LoadBalancerSku == "Standard" && !to.Bool(kubernetesConfig.PrivateCluster.Enabled) {
random := rand.New(rand.NewSource(time.Now().UnixNano()))
elbsvcName := random.Int()
addValue(parametersMap, "kuberneteselbsvcname", fmt.Sprintf("%d", elbsvcName))
}
if common.IsKubernetesVersionGe(k8sVersion, "1.12.0") {
addValue(parametersMap, "kubernetesCoreDNSSpec", kubernetesImageBase+k8sComponents["coredns"])
} else {
addValue(parametersMap, "kubernetesKubeDNSSpec", kubernetesImageBase+k8sComponents["kube-dns"])
addValue(parametersMap, "kubernetesDNSMasqSpec", kubernetesImageBase+k8sComponents["dnsmasq"])
}
addValue(parametersMap, "kubernetesPodInfraContainerSpec", kubernetesImageBase+k8sComponents["pause"])
addValue(parametersMap, "cloudproviderConfig", api.CloudProviderConfig{
CloudProviderBackoff: kubernetesConfig.CloudProviderBackoff,
CloudProviderBackoffRetries: kubernetesConfig.CloudProviderBackoffRetries,
CloudProviderBackoffJitter: strconv.FormatFloat(kubernetesConfig.CloudProviderBackoffJitter, 'f', -1, 64),
CloudProviderBackoffDuration: kubernetesConfig.CloudProviderBackoffDuration,
CloudProviderBackoffExponent: strconv.FormatFloat(kubernetesConfig.CloudProviderBackoffExponent, 'f', -1, 64),
CloudProviderRateLimit: kubernetesConfig.CloudProviderRateLimit,
CloudProviderRateLimitQPS: strconv.FormatFloat(kubernetesConfig.CloudProviderRateLimitQPS, 'f', -1, 64),
CloudProviderRateLimitBucket: kubernetesConfig.CloudProviderRateLimitBucket,
})
addValue(parametersMap, "kubeClusterCidr", kubernetesConfig.ClusterSubnet)
addValue(parametersMap, "kubernetesKubeletClusterDomain", kubernetesConfig.KubeletConfig["--cluster-domain"])
addValue(parametersMap, "dockerBridgeCidr", kubernetesConfig.DockerBridgeSubnet)
addValue(parametersMap, "networkPolicy", kubernetesConfig.NetworkPolicy)
addValue(parametersMap, "networkPlugin", kubernetesConfig.NetworkPlugin)
addValue(parametersMap, "containerRuntime", kubernetesConfig.ContainerRuntime)
addValue(parametersMap, "containerdDownloadURLBase", cloudSpecConfig.KubernetesSpecConfig.ContainerdDownloadURLBase)
addValue(parametersMap, "cniPluginsURL", cloudSpecConfig.KubernetesSpecConfig.CNIPluginsDownloadURL)
addValue(parametersMap, "vnetCniLinuxPluginsURL", kubernetesConfig.GetAzureCNIURLLinux(cloudSpecConfig))
addValue(parametersMap, "vnetCniWindowsPluginsURL", kubernetesConfig.GetAzureCNIURLWindows(cloudSpecConfig))
addValue(parametersMap, "gchighthreshold", kubernetesConfig.GCHighThreshold)
addValue(parametersMap, "gclowthreshold", kubernetesConfig.GCLowThreshold)
addValue(parametersMap, "etcdDownloadURLBase", cloudSpecConfig.KubernetesSpecConfig.EtcdDownloadURLBase)
addValue(parametersMap, "etcdVersion", kubernetesConfig.EtcdVersion)
addValue(parametersMap, "etcdDiskSizeGB", kubernetesConfig.EtcdDiskSizeGB)
addValue(parametersMap, "etcdEncryptionKey", kubernetesConfig.EtcdEncryptionKey)
if kubernetesConfig.PrivateJumpboxProvision() {
addValue(parametersMap, "jumpboxVMName", kubernetesConfig.PrivateCluster.JumpboxProfile.Name)
addValue(parametersMap, "jumpboxVMSize", kubernetesConfig.PrivateCluster.JumpboxProfile.VMSize)
addValue(parametersMap, "jumpboxUsername", kubernetesConfig.PrivateCluster.JumpboxProfile.Username)
addValue(parametersMap, "jumpboxOSDiskSizeGB", kubernetesConfig.PrivateCluster.JumpboxProfile.OSDiskSizeGB)
addValue(parametersMap, "jumpboxPublicKey", kubernetesConfig.PrivateCluster.JumpboxProfile.PublicKey)
addValue(parametersMap, "jumpboxStorageProfile", kubernetesConfig.PrivateCluster.JumpboxProfile.StorageProfile)
}
addValue(parametersMap, "enableAggregatedAPIs", kubernetesConfig.EnableAggregatedAPIs)
if properties.HasWindows() {
// Kubernetes packages as zip file as created by scripts/build-windows-k8s.sh
// will be removed in future release as if gets phased out (https://github.com/Azure/aks-engine/issues/3851)
kubeBinariesSASURL := kubernetesConfig.CustomWindowsPackageURL
if kubeBinariesSASURL == "" {
kubeBinariesSASURL = cloudSpecConfig.KubernetesSpecConfig.KubeBinariesSASURLBase + k8sComponents["windowszip"]
}
addValue(parametersMap, "kubeBinariesSASURL", kubeBinariesSASURL)
// Kubernetes node binaries as packaged by upstream kubernetes
// example at https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG-1.11.md#node-binaries-1
addValue(parametersMap, "windowsKubeBinariesURL", kubernetesConfig.WindowsNodeBinariesURL)
addValue(parametersMap, "kubeServiceCidr", kubernetesConfig.ServiceCIDR)
addValue(parametersMap, "kubeBinariesVersion", k8sVersion)
addValue(parametersMap, "windowsTelemetryGUID", cloudSpecConfig.KubernetesSpecConfig.WindowsTelemetryGUID)
}
}
if kubernetesConfig == nil ||
!kubernetesConfig.UseManagedIdentity {
servicePrincipalProfile := properties.ServicePrincipalProfile
if servicePrincipalProfile != nil {
addValue(parametersMap, "servicePrincipalClientId", servicePrincipalProfile.ClientID)
keyVaultSecretRef := servicePrincipalProfile.KeyvaultSecretRef
if keyVaultSecretRef != nil {
addKeyvaultReference(parametersMap, "servicePrincipalClientSecret",
keyVaultSecretRef.VaultID,
keyVaultSecretRef.SecretName,
keyVaultSecretRef.SecretVersion)
} else {
addValue(parametersMap, "servicePrincipalClientSecret", servicePrincipalProfile.Secret)
}
if kubernetesConfig != nil && to.Bool(kubernetesConfig.EnableEncryptionWithExternalKms) {
if kubernetesConfig.KeyVaultSku != "" {
addValue(parametersMap, "clusterKeyVaultSku", kubernetesConfig.KeyVaultSku)
}
if !kubernetesConfig.UseManagedIdentity && servicePrincipalProfile.ObjectID != "" {
addValue(parametersMap, "servicePrincipalObjectId", servicePrincipalProfile.ObjectID)
}
}
}
}
addValue(parametersMap, "orchestratorName", properties.K8sOrchestratorName())
/**
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>"
}
**/
certificateProfile := properties.CertificateProfile
if certificateProfile != nil {
addSecret(parametersMap, "apiServerCertificate", certificateProfile.APIServerCertificate, true)
addSecret(parametersMap, "apiServerPrivateKey", certificateProfile.APIServerPrivateKey, true)
addSecret(parametersMap, "caCertificate", certificateProfile.CaCertificate, true)
addSecret(parametersMap, "caPrivateKey", certificateProfile.CaPrivateKey, true)
addSecret(parametersMap, "clientCertificate", certificateProfile.ClientCertificate, true)
addSecret(parametersMap, "clientPrivateKey", certificateProfile.ClientPrivateKey, true)
addSecret(parametersMap, "kubeConfigCertificate", certificateProfile.KubeConfigCertificate, true)
addSecret(parametersMap, "kubeConfigPrivateKey", certificateProfile.KubeConfigPrivateKey, true)
if properties.MasterProfile != nil {
addSecret(parametersMap, "etcdServerCertificate", certificateProfile.EtcdServerCertificate, true)
addSecret(parametersMap, "etcdServerPrivateKey", certificateProfile.EtcdServerPrivateKey, true)
addSecret(parametersMap, "etcdClientCertificate", certificateProfile.EtcdClientCertificate, true)
addSecret(parametersMap, "etcdClientPrivateKey", certificateProfile.EtcdClientPrivateKey, true)
for i, pc := range certificateProfile.EtcdPeerCertificates {
addSecret(parametersMap, "etcdPeerCertificate"+strconv.Itoa(i), pc, true)
}
for i, pk := range certificateProfile.EtcdPeerPrivateKeys {
addSecret(parametersMap, "etcdPeerPrivateKey"+strconv.Itoa(i), pk, true)
}
}
}
if properties.HostedMasterProfile != nil && properties.HostedMasterProfile.FQDN != "" {
addValue(parametersMap, "kubernetesEndpoint", properties.HostedMasterProfile.FQDN)
}
if properties.OrchestratorProfile.KubernetesConfig.MobyVersion != "" {
addValue(parametersMap, "mobyVersion", properties.OrchestratorProfile.KubernetesConfig.MobyVersion)
}
if properties.OrchestratorProfile.KubernetesConfig.ContainerdVersion != "" {
addValue(parametersMap, "containerdVersion", properties.OrchestratorProfile.KubernetesConfig.ContainerdVersion)
}
if properties.AADProfile != nil {
addValue(parametersMap, "aadTenantId", properties.AADProfile.TenantID)
if properties.AADProfile.AdminGroupID != "" {
addValue(parametersMap, "aadAdminGroupId", properties.AADProfile.AdminGroupID)
}
}
}
}