forked from Azure/aks-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cse_main.sh
executable file
·318 lines (272 loc) · 9.59 KB
/
cse_main.sh
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
#!/bin/bash
ERR_FILE_WATCH_TIMEOUT=6 {{/* Timeout waiting for a file */}}
set -x
if [ -f /opt/azure/containers/provision.complete ]; then
exit 0
fi
echo $(date),$(hostname), startcustomscript >>/opt/m
for i in $(seq 1 3600); do
if [ -s {{GetCSEHelpersScriptFilepath}} ]; then
grep -Fq '#HELPERSEOF' {{GetCSEHelpersScriptFilepath}} && break
fi
if [ $i -eq 3600 ]; then
exit {{GetCSEErrorCode "ERR_FILE_WATCH_TIMEOUT"}}
else
sleep 1
fi
done
sed -i "/#HELPERSEOF/d" {{GetCSEHelpersScriptFilepath}}
source {{GetCSEHelpersScriptFilepath}}
configure_prerequisites
wait_for_file 3600 1 {{GetCSEInstallScriptFilepath}} || exit {{GetCSEErrorCode "ERR_FILE_WATCH_TIMEOUT"}}
source {{GetCSEInstallScriptFilepath}}
ensureAPMZ "v0.5.1"
{{- if HasTelemetryEnabled }}
eval "$(apmz bash -n "cse" -t "{{GetLinuxDefaultTelemetryTags}}" --api-keys "{{GetApplicationInsightsTelemetryKeys}}")"
{{else}}
eval "$(apmz bash -d)"
{{end}}
wait_for_file 3600 1 {{GetCSEConfigScriptFilepath}} || exit {{GetCSEErrorCode "ERR_FILE_WATCH_TIMEOUT"}}
source {{GetCSEConfigScriptFilepath}}
{{- if IsCustomCloudProfile}}
wait_for_file 3600 1 {{GetCustomCloudConfigCSEScriptFilepath}} || exit {{GetCSEErrorCode "ERR_FILE_WATCH_TIMEOUT"}}
source {{GetCustomCloudConfigCSEScriptFilepath }}
{{end}}
set +x
ETCD_PEER_CERT=$(echo ${ETCD_PEER_CERTIFICATES} | cut -d'[' -f 2 | cut -d']' -f 1 | cut -d',' -f $((NODE_INDEX + 1)))
ETCD_PEER_KEY=$(echo ${ETCD_PEER_PRIVATE_KEYS} | cut -d'[' -f 2 | cut -d']' -f 1 | cut -d',' -f $((NODE_INDEX + 1)))
set -x
time_metric "ConfigureAdminUser" configureAdminUser
{{- if HasVHDDistroNodes}}
{{- if not NeedsContainerd}}
time_metric "CleanupContainerd" cleanUpContainerd
{{end}}
{{- if HasNSeriesSKU}}
if [[ ${GPU_NODE} != "true" ]]; then
time_metric "CleanupGPUDrivers" cleanUpGPUDrivers
fi
{{else}}
time_metric "CleanupGPUDrivers" cleanUpGPUDrivers
{{end}}
{{end}}
VHD_LOGS_FILEPATH=/opt/azure/vhd-install.complete
if [ -f $VHD_LOGS_FILEPATH ]; then
time_metric "CleanUpContainerImages" cleanUpContainerImages
FULL_INSTALL_REQUIRED=false
else
if [[ ${IS_VHD} == true ]]; then
exit {{GetCSEErrorCode "ERR_VHD_FILE_NOT_FOUND"}}
fi
FULL_INSTALL_REQUIRED=true
fi
{{- if not IsVHDDistroForAllNodes}}
if [[ $OS == $UBUNTU_OS_NAME || $OS == $DEBIAN_OS_NAME ]] && [ "$FULL_INSTALL_REQUIRED" = "true" ]; then
time_metric "InstallDeps" installDeps
if [[ ${UBUNTU_RELEASE} == "18.04" ]]; then
overrideNetworkConfig
fi
if [[ $OS == $UBUNTU_OS_NAME ]]; then
time_metric "InstallBcc" installBcc
fi
{{- if not IsDockerContainerRuntime}}
time_metric "InstallImg" installImg
{{end}}
fi
{{end}}
if [[ ${UBUNTU_RELEASE} == "18.04" ]]; then
if apt list --installed | grep 'chrony'; then
time_metric "ConfigureChrony" configureChrony
time_metric "EnsureChrony" ensureChrony
fi
fi
if [[ $OS == $UBUNTU_OS_NAME ]]; then
time_metric "EnsureAuditD" ensureAuditD
fi
{{- if not IsVHDDistroForAllNodes}}
if [[ $FULL_INSTALL_REQUIRED == "true" ]]; then
time_metric "InstallBpftrace" installBpftrace
fi
{{end}}
if [[ $OS != $FLATCAR_OS_NAME ]]; then
{{- if NeedsContainerd}}
time_metric "InstallContainerd" installContainerd
{{else}}
time_metric "installMoby" installMoby
{{end}}
time_metric "installRunc" installRunc
{{- if HasLinuxMobyURL}}
LINUX_MOBY_URL={{GetLinuxMobyURL}}
if [[ -n "${LINUX_MOBY_URL:-}" ]]; then
DEB="${LINUX_MOBY_URL##*/}"
retrycmd_no_stats 120 5 25 curl -fsSL ${LINUX_MOBY_URL} >/tmp/${DEB} || exit {{GetCSEErrorCode "ERR_DEB_DOWNLOAD_TIMEOUT"}}
dpkg_install 20 30 /tmp/${DEB} || exit {{GetCSEErrorCode "ERR_DEB_PKG_ADD_FAIL"}}
fi
{{end}}
{{- if HasLinuxContainerdURL}}
LINUX_CONTAINERD_URL={{GetLinuxContainerdURL}}
if [[ -n "${LINUX_CONTAINERD_URL:-}" ]]; then
DEB="${LINUX_CONTAINERD_URL##*/}"
retrycmd_no_stats 120 5 25 curl -fsSL ${LINUX_CONTAINERD_URL} >/tmp/${DEB} || exit {{GetCSEErrorCode "ERR_DEB_DOWNLOAD_TIMEOUT"}}
dpkg_install 20 30 /tmp/${DEB} || exit {{GetCSEErrorCode "ERR_DEB_PKG_ADD_FAIL"}}
fi
{{end}}
{{- if HasLinuxRuncURL}}
LINUX_RUNC_URL={{GetLinuxRuncURL}}
if [[ -n "${LINUX_RUNC_URL:-}" ]]; then
DEB="${LINUX_RUNC_URL##*/}"
retrycmd_no_stats 120 5 25 curl -fsSL ${LINUX_RUNC_URL} >/tmp/${DEB} || exit {{GetCSEErrorCode "ERR_DEB_DOWNLOAD_TIMEOUT"}}
dpkg_install 20 30 /tmp/${DEB} || exit {{GetCSEErrorCode "ERR_DEB_PKG_ADD_FAIL"}}
fi
{{end}}
fi
if [[ -n ${MASTER_NODE} ]] && [[ -z ${COSMOS_URI} ]]; then
{{- if IsDockerContainerRuntime}}
cli_tool="docker"
{{else}}
cli_tool="img"
{{end}}
time_metric "InstallEtcd" installEtcd $cli_tool
fi
{{/* this will capture the amount of time to install of the network plugin during cse */}}
time_metric "InstallNetworkPlugin" installNetworkPlugin
{{- if and HasNSeriesSKU IsNvidiaDevicePluginAddonEnabled}}
if [[ ${GPU_NODE} == true ]]; then
if $FULL_INSTALL_REQUIRED; then
time_metric "DownloadGPUDrivers" downloadGPUDrivers
fi
time_metric "EnsureGPUDrivers" ensureGPUDrivers
fi
{{end}}
{{- if and IsDockerContainerRuntime HasPrivateAzureRegistryServer}}
docker login -u $SERVICE_PRINCIPAL_CLIENT_ID -p $SERVICE_PRINCIPAL_CLIENT_SECRET {{GetPrivateAzureRegistryServer}}
{{end}}
time_metric "InstallKubeletAndKubectl" installKubeletAndKubectl
if [[ $OS != $FLATCAR_OS_NAME ]]; then
time_metric "EnsureRPC" ensureRPC
time_metric "EnsureCron" ensureCron
fi
time_metric "CreateKubeManifestDir" createKubeManifestDir
{{- if HasDCSeriesSKU}}
if [[ ${SGX_NODE} == true && ! -e "/dev/sgx" ]]; then
time_metric "InstallSGXDrivers" installSGXDrivers
fi
{{end}}
{{/* create etcd user if we are configured for etcd */}}
if [[ -n ${MASTER_NODE} ]] && [[ -z ${COSMOS_URI} ]]; then
time_metric "ConfigureEtcdUser" configureEtcdUser
fi
if [[ -n ${MASTER_NODE} ]]; then
{{/* this step configures all certs */}}
{{/* both configs etcd/cosmos */}}
time_metric "ConfigureSecrets" configureSecrets
fi
{{/* configure etcd if we are configured for etcd */}}
if [[ -n ${MASTER_NODE} ]] && [[ -z ${COSMOS_URI} ]]; then
time_metric "ConfigureEtcd" configureEtcd
else
time_metric "RemoveEtcd" removeEtcd
fi
{{- if HasCustomSearchDomain}}
wait_for_file 3600 1 {{GetCustomSearchDomainsCSEScriptFilepath}} || exit {{GetCSEErrorCode "ERR_FILE_WATCH_TIMEOUT"}}
{{GetCustomSearchDomainsCSEScriptFilepath}} >/opt/azure/containers/setup-custom-search-domain.log 2>&1 || exit {{GetCSEErrorCode "ERR_CUSTOM_SEARCH_DOMAINS_FAIL"}}
{{end}}
{{- if IsDockerContainerRuntime}}
time_metric "EnsureDocker" ensureDocker
{{end}}
time_metric "ConfigureK8s" configureK8s
{{- if IsCustomCloudProfile}}
time_metric "ConfigureK8sCustomCloud" configureK8sCustomCloud
{{- if and IsAzureStackCloud IsAzureCNI}}
time_metric "ConfigureAzureStackInterfaces" configureAzureStackInterfaces
{{end}}
{{end}}
time_metric "ConfigureCNI" configureCNI
if [[ -n ${MASTER_NODE} ]]; then
time_metric "ConfigAddons" configAddons
time_metric "WriteKubeConfig" writeKubeConfig
fi
{{- if NeedsContainerd}}
time_metric "EnsureContainerd" ensureContainerd
{{end}}
{{/* configure and enable dhcpv6 for ipv6 features */}}
{{- if IsIPv6Enabled}}
time_metric "EnsureDHCPv6" ensureDHCPv6
{{end}}
{{/* configure and enable kms plugin */}}
{{- if EnableEncryptionWithExternalKms}}
if [[ -n ${MASTER_NODE} ]]; then
time_metric "EnsureKMSKeyvaultKey" ensureKMSKeyvaultKey
fi
{{end}}
time_metric "EnsureKubelet" ensureKubelet
{{if IsAzurePolicyAddonEnabled}}
if [[ -n ${MASTER_NODE} ]]; then
time_metric "EnsureLabelExclusionForAzurePolicyAddon" ensureLabelExclusionForAzurePolicyAddon
fi
{{end}}
time_metric "EnsureJournal" ensureJournal
if [[ -n ${MASTER_NODE} ]]; then
if version_gte ${KUBERNETES_VERSION} 1.16; then
time_metric "EnsureLabelNodes" ensureLabelNodes
fi
{{- if IsAADPodIdentityAddonEnabled}}
time_metric "EnsureTaints" ensureTaints
{{end}}
if [[ -z ${COSMOS_URI} ]]; then
time_metric "EnsureEtcd" ensureEtcd
fi
time_metric "EnsureK8sControlPlane" ensureK8sControlPlane
time_metric "EnsureAddons" ensureAddons
{{- if HasClusterInitComponent}}
if [[ $NODE_INDEX == 0 ]]; then
retrycmd 120 5 30 $KUBECTL apply -f /opt/azure/containers/cluster-init.yaml || exit {{GetCSEErrorCode "ERR_CLUSTER_INIT_FAIL"}}
fi
{{end}}
fi
{{- if not IsVHDDistroForAllNodes}}
if $FULL_INSTALL_REQUIRED; then
if [[ $OS == $UBUNTU_OS_NAME ]]; then
{{/* mitigation for bug https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1676635 */}}
echo 2dd1ce17-079e-403c-b352-a1921ee207ee >/sys/bus/vmbus/drivers/hv_util/unbind
sed -i "13i\echo 2dd1ce17-079e-403c-b352-a1921ee207ee > /sys/bus/vmbus/drivers/hv_util/unbind\n" /etc/rc.local
fi
fi
{{end}}
{{- /* re-enable unattended upgrades */}}
{{- if EnableUnattendedUpgrades}}
rm -f /etc/apt/apt.conf.d/99periodic
{{- end}}
{{- if not IsAzureStackCloud}}
if [[ $OS == $UBUNTU_OS_NAME ]]; then
time_metric "PurgeApt" apt_get_purge apache2-utils &
fi
{{end}}
{{- if not HasBlockOutboundInternet}}
{{- if RunUnattendedUpgradesOnBootstrap}}
apt_get_update && unattended_upgrade
{{- end}}
{{- end}}
if [ -f /var/run/reboot-required ]; then
trace_info "RebootRequired" "reboot=true"
/bin/bash -c "shutdown -r 1 &"
if [[ $OS == $UBUNTU_OS_NAME ]]; then
aptmarkWALinuxAgent unhold &
fi
else
{{- if RunUnattendedUpgradesOnBootstrap}}
if [[ -z ${MASTER_NODE} ]]; then
systemctl_restart 100 5 30 kubelet
systemctl_restart 100 5 30 kubelet-monitor
fi
{{- end}}
if [[ $OS == $UBUNTU_OS_NAME ]]; then
/usr/lib/apt/apt.systemd.daily &
aptmarkWALinuxAgent unhold &
fi
fi
echo "CSE finished successfully"
echo $(date),$(hostname), endcustomscript >>/opt/m
mkdir -p /opt/azure/containers && touch /opt/azure/containers/provision.complete
ps auxfww >/opt/azure/provision-ps.log &
exit 0
#EOF