forked from Azure/aks-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kuberneteswindowssetup.ps1
500 lines (412 loc) · 23 KB
/
kuberneteswindowssetup.ps1
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
<#
.SYNOPSIS
Provisions VM as a Kubernetes agent.
.DESCRIPTION
Provisions VM as a Kubernetes agent.
The parameters passed in are required, and will vary per-deployment.
Notes on modifying this file:
- This file extension is PS1, but it is actually used as a template from pkg/engine/template_generator.go
- All of the lines that have braces in them will be modified. Please do not change them here, change them in the Go sources
- Single quotes are forbidden, they are reserved to delineate the different members for the ARM template concat() call
#>
[CmdletBinding(DefaultParameterSetName="Standard")]
param(
[string]
[ValidateNotNullOrEmpty()]
$MasterIP,
[parameter()]
[ValidateNotNullOrEmpty()]
$KubeDnsServiceIp,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$MasterFQDNPrefix,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$Location,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$AgentKey,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$AADClientId,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$AADClientSecret, # base64
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$NetworkAPIVersion,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
$TargetEnvironment,
[string]
$UserAssignedClientID
)
# These globals will not change between nodes in the same cluster, so they are not
# passed as powershell parameters
## SSH public keys to add to authorized_keys
$global:SSHKeys = @( {{ GetSshPublicKeysPowerShell }} )
## Certificates generated by aks-engine
$global:CACertificate = "{{WrapAsParameter "caCertificate"}}"
$global:AgentCertificate = "{{WrapAsParameter "clientCertificate"}}"
## Download sources provided by aks-engine
$global:KubeBinariesPackageSASURL = "{{WrapAsParameter "kubeBinariesSASURL"}}"
$global:WindowsKubeBinariesURL = "{{WrapAsParameter "windowsKubeBinariesURL"}}"
$global:KubeBinariesVersion = "{{WrapAsParameter "kubeBinariesVersion"}}"
$global:ContainerdUrl = "{{WrapAsParameter "windowsContainerdURL"}}"
$global:ContainerdSdnPluginUrl = "{{WrapAsParameter "windowsSdnPluginURL"}}"
## Docker Version
$global:DockerVersion = "{{WrapAsParameter "windowsDockerVersion"}}"
## ContainerD Usage
$global:ContainerRuntime = "{{WrapAsParameter "containerRuntime"}}"
$global:DefaultContainerdRuntimeHandler = "{{WrapAsParameter "defaultContainerdRuntimeHandler"}}"
$global:HypervRuntimeHandlers = "{{WrapAsParameter "hypervRuntimeHandlers"}}"
## VM configuration passed by Azure
$global:WindowsTelemetryGUID = "{{WrapAsParameter "windowsTelemetryGUID"}}"
{{if eq GetIdentitySystem "adfs"}}
$global:TenantId = "adfs"
{{else}}
$global:TenantId = "{{WrapAsVariable "tenantID"}}"
{{end}}
$global:SubscriptionId = "{{WrapAsVariable "subscriptionId"}}"
$global:ResourceGroup = "{{WrapAsVariable "resourceGroup"}}"
$global:VmType = "{{WrapAsVariable "vmType"}}"
$global:SubnetName = "{{WrapAsVariable "subnetName"}}"
$global:MasterSubnet = "{{GetWindowsMasterSubnetARMParam}}"
$global:SecurityGroupName = "{{WrapAsVariable "nsgName"}}"
$global:VNetName = "{{WrapAsVariable "virtualNetworkName"}}"
$global:RouteTableName = "{{WrapAsVariable "routeTableName"}}"
$global:PrimaryAvailabilitySetName = "{{WrapAsVariable "primaryAvailabilitySetName"}}"
$global:PrimaryScaleSetName = "{{WrapAsVariable "primaryScaleSetName"}}"
$global:KubeClusterCIDR = "{{WrapAsParameter "kubeClusterCidr"}}"
$global:KubeServiceCIDR = "{{WrapAsParameter "kubeServiceCidr"}}"
$global:VNetCIDR = "{{WrapAsParameter "vnetCidr"}}"
$global:KubeletNodeLabels = "{{GetAgentKubernetesLabels . "',variables('labelResourceGroup'),'"}}"
$global:KubeletConfigArgs = @( {{GetKubeletConfigKeyValsPsh .KubernetesConfig }} )
$global:KubeproxyFeatureGates = @( {{GetKubeProxyFeatureGatesPsh}} )
$global:UseManagedIdentityExtension = "{{WrapAsVariable "useManagedIdentityExtension"}}"
$global:UseInstanceMetadata = "{{WrapAsVariable "useInstanceMetadata"}}"
$global:LoadBalancerSku = "{{WrapAsVariable "loadBalancerSku"}}"
$global:ExcludeMasterFromStandardLB = "{{WrapAsVariable "excludeMasterFromStandardLB"}}"
# Windows defaults, not changed by aks-engine
$global:CacheDir = "c:\akse-cache"
$global:KubeDir = "c:\k"
$global:HNSModule = [Io.path]::Combine("$global:KubeDir", "hns.psm1")
$global:KubeDnsSearchPath = "svc.cluster.local"
$global:CNIPath = [Io.path]::Combine("$global:KubeDir", "cni")
$global:NetworkMode = "L2Bridge"
$global:CNIConfig = [Io.path]::Combine($global:CNIPath, "config", "`$global:NetworkMode.conf")
$global:CNIConfigPath = [Io.path]::Combine("$global:CNIPath", "config")
$global:AzureCNIDir = [Io.path]::Combine("$global:KubeDir", "azurecni")
$global:AzureCNIBinDir = [Io.path]::Combine("$global:AzureCNIDir", "bin")
$global:AzureCNIConfDir = [Io.path]::Combine("$global:AzureCNIDir", "netconf")
# Azure cni configuration
# $global:NetworkPolicy = "{{WrapAsParameter "networkPolicy"}}" # BUG: unused
$global:NetworkPlugin = "{{WrapAsParameter "networkPlugin"}}"
$global:VNetCNIPluginsURL = "{{WrapAsParameter "vnetCniWindowsPluginsURL"}}"
$global:IsDualStackEnabled = {{if IsIPv6DualStackFeatureEnabled}}$true{{else}}$false{{end}}
# Telemetry settings
$global:EnableTelemetry = "{{WrapAsVariable "enableTelemetry" }}";
$global:TelemetryKey = "{{WrapAsVariable "applicationInsightsKey" }}";
# CSI Proxy settings
$global:EnableCsiProxy = [System.Convert]::ToBoolean("{{WrapAsVariable "windowsEnableCSIProxy" }}");
$global:CsiProxyUrl = "{{WrapAsVariable "windowsCSIProxyURL" }}";
# Hosts Config Agent settings
$global:EnableHostsConfigAgent = [System.Convert]::ToBoolean("{{WrapAsVariable "enableHostsConfigAgent" }}");
$global:ProvisioningScriptsPackageUrl = "{{WrapAsVariable "windowsProvisioningScriptsPackageURL" }}";
# PauseImage
$global:WindowsPauseImageURL = "{{WrapAsVariable "windowsPauseImageURL" }}";
$global:AlwaysPullWindowsPauseImage = [System.Convert]::ToBoolean("{{WrapAsVariable "alwaysPullWindowsPauseImage" }}");
# Secure Windows TLS protocols
$global:WindowsSecureTLSEnabled = [System.Convert]::ToBoolean("{{WrapAsVariable "windowsSecureTLSEnabled" }}");
# Base64 representation of ZIP archive
$zippedFiles = "{{ GetKubernetesWindowsAgentFunctions }}"
# Extract ZIP from script
[io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles))
Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\"
# Dot-source scripts with functions that are called in this script
. c:\AzureData\k8s\kuberneteswindowsfunctions.ps1
. c:\AzureData\k8s\windowsconfigfunc.ps1
. c:\AzureData\k8s\windowskubeletfunc.ps1
. c:\AzureData\k8s\windowscnifunc.ps1
. c:\AzureData\k8s\windowsazurecnifunc.ps1
. c:\AzureData\k8s\windowscsiproxyfunc.ps1
. c:\AzureData\k8s\windowsinstallopensshfunc.ps1
. c:\AzureData\k8s\windowscontainerdfunc.ps1
. c:\AzureData\k8s\windowshostsconfigagentfunc.ps1
$useContainerD = ($global:ContainerRuntime -eq "containerd")
$global:KubeClusterConfigPath = "c:\k\kubeclusterconfig.json"
try
{
# Set to false for debugging. This will output the start script to
# c:\AzureData\CustomDataSetupScript.log, and then you can RDP
# to the windows machine, and run the script manually to watch
# the output.
if ($true) {
Write-Log ".\CustomDataSetupScript.ps1 -MasterIP $MasterIP -KubeDnsServiceIp $KubeDnsServiceIp -MasterFQDNPrefix $MasterFQDNPrefix -Location $Location -AgentKey $AgentKey -AADClientId $AADClientId -AADClientSecret $AADClientSecret -NetworkAPIVersion $NetworkAPIVersion -TargetEnvironment $TargetEnvironment"
Write-Log "Provisioning $global:DockerServiceName... with IP $MasterIP"
$global:globalTimer = [System.Diagnostics.Stopwatch]::StartNew()
$configAppInsightsClientTimer = [System.Diagnostics.Stopwatch]::StartNew()
# Get app insights binaries and set up app insights client
mkdir c:\k\appinsights
DownloadFileOverHttp -Url "https://globalcdn.nuget.org/packages/microsoft.applicationinsights.2.11.0.nupkg" -DestinationPath "c:\k\appinsights\microsoft.applicationinsights.2.11.0.zip"
Expand-Archive -Path "c:\k\appinsights\microsoft.applicationinsights.2.11.0.zip" -DestinationPath "c:\k\appinsights"
$appInsightsDll = "c:\k\appinsights\lib\net46\Microsoft.ApplicationInsights.dll"
[Reflection.Assembly]::LoadFile($appInsightsDll)
$conf = New-Object "Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration"
$conf.DisableTelemetry = -not $global:enableTelemetry
$conf.InstrumentationKey = $global:TelemetryKey
$global:AppInsightsClient = New-Object "Microsoft.ApplicationInsights.TelemetryClient"($conf)
$global:AppInsightsClient.Context.Properties["correlation_id"] = New-Guid
$global:AppInsightsClient.Context.Properties["cri"] = $global:ContainerRuntime
# TODO: Update once containerd versioning story is decided
$global:AppInsightsClient.Context.Properties["cri_version"] = if ($global:ContainerRuntime -eq "docker") { $global:DockerVersion } else { "" }
$global:AppInsightsClient.Context.Properties["k8s_version"] = $global:KubeBinariesVersion
$global:AppInsightsClient.Context.Properties["lb_sku"] = $global:LoadBalancerSku
$global:AppInsightsClient.Context.Properties["location"] = $Location
$global:AppInsightsClient.Context.Properties["os_type"] = "windows"
$global:AppInsightsClient.Context.Properties["os_version"] = Get-WindowsVersion
$global:AppInsightsClient.Context.Properties["network_plugin"] = $global:NetworkPlugin
$global:AppInsightsClient.Context.Properties["network_plugin_version"] = Get-CniVersion
$global:AppInsightsClient.Context.Properties["network_mode"] = $global:NetworkMode
$global:AppInsightsClient.Context.Properties["subscription_id"] = $global:SubscriptionId
$vhdId = ""
if (Test-Path "c:\vhd-id.txt") {
$vhdId = Get-Content "c:\vhd-id.txt"
}
$global:AppInsightsClient.Context.Properties["vhd_id"] = $vhdId
$imdsProperties = Get-InstanceMetadataServiceTelemetry
foreach ($key in $imdsProperties.keys) {
$global:AppInsightsClient.Context.Properties[$key] = $imdsProperties[$key]
}
$configAppInsightsClientTimer.Stop()
$global:AppInsightsClient.TrackMetric("Config-AppInsightsClient", $configAppInsightsClientTimer.Elapsed.TotalSeconds)
# Install OpenSSH if SSH enabled
$sshEnabled = [System.Convert]::ToBoolean("{{ WindowsSSHEnabled }}")
if ( $sshEnabled ) {
Write-Log "Install OpenSSH"
$installOpenSSHTimer = [System.Diagnostics.Stopwatch]::StartNew()
Install-OpenSSH -SSHKeys $SSHKeys
$installOpenSSHTimer.Stop()
$global:AppInsightsClient.TrackMetric("Install-OpenSSH", $installOpenSSHTimer.Elapsed.TotalSeconds)
}
Write-Log "Apply telemetry data setting"
Set-TelemetrySetting -WindowsTelemetryGUID $global:WindowsTelemetryGUID
Write-Log "Resize os drive if possible"
$resizeTimer = [System.Diagnostics.Stopwatch]::StartNew()
Resize-OSDrive
$resizeTimer.Stop()
$global:AppInsightsClient.TrackMetric("Resize-OSDrive", $resizeTimer.Elapsed.TotalSeconds)
Write-Log "Initialize data disks"
Initialize-DataDisks
Write-Log "Create required data directories as needed"
Initialize-DataDirectories
New-Item -ItemType Directory -Path "c:\k" -Force | Out-Null
Get-ProvisioningScripts
Write-KubeClusterConfig -MasterIP $MasterIP -KubeDnsServiceIp $KubeDnsServiceIp
Write-Log "Download kubelet binaries and unzip"
Get-KubePackage -KubeBinariesSASURL $global:KubeBinariesPackageSASURL
# The custom package has a few files that are nessary for future steps (nssm.exe)
# this is a temporary work around to get the binaries until we depreciate
# custom package and nssm.exe as defined in #3851.
if ($global:WindowsKubeBinariesURL){
Write-Log "Overwriting kube node binaries from $global:WindowsKubeBinariesURL"
Get-KubeBinaries -KubeBinariesURL $global:WindowsKubeBinariesURL
}
if ($useContainerD) {
Write-Log "Installing ContainerD"
$containerdTimer = [System.Diagnostics.Stopwatch]::StartNew()
$cniBinPath = $global:AzureCNIBinDir
$cniConfigPath = $global:AzureCNIConfDir
if ($global:NetworkPlugin -eq "kubenet") {
$cniBinPath = $global:CNIPath
$cniConfigPath = $global:CNIConfigPath
}
Install-Containerd -ContainerdUrl $global:ContainerdUrl -CNIBinDir $cniBinPath -CNIConfDir $cniConfigPath -KubeDir $global:KubeDir
$containerdTimer.Stop()
$global:AppInsightsClient.TrackMetric("Install-ContainerD", $containerdTimer.Elapsed.TotalSeconds)
# TODO: disable/uninstall Docker later
} else {
Write-Log "Install docker"
$dockerTimer = [System.Diagnostics.Stopwatch]::StartNew()
Install-Docker -DockerVersion $global:DockerVersion
Set-DockerLogFileOptions
$dockerTimer.Stop()
$global:AppInsightsClient.TrackMetric("Install-Docker", $dockerTimer.Elapsed.TotalSeconds)
}
Write-Log "Write Azure cloud provider config"
Write-AzureConfig `
-KubeDir $global:KubeDir `
-AADClientId $AADClientId `
-AADClientSecret $([System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($AADClientSecret))) `
-TenantId $global:TenantId `
-SubscriptionId $global:SubscriptionId `
-ResourceGroup $global:ResourceGroup `
-Location $Location `
-VmType $global:VmType `
-SubnetName $global:SubnetName `
-SecurityGroupName $global:SecurityGroupName `
-VNetName $global:VNetName `
-RouteTableName $global:RouteTableName `
-PrimaryAvailabilitySetName $global:PrimaryAvailabilitySetName `
-PrimaryScaleSetName $global:PrimaryScaleSetName `
-UseManagedIdentityExtension $global:UseManagedIdentityExtension `
-UserAssignedClientID $UserAssignedClientID `
-UseInstanceMetadata $global:UseInstanceMetadata `
-LoadBalancerSku $global:LoadBalancerSku `
-ExcludeMasterFromStandardLB $global:ExcludeMasterFromStandardLB `
-TargetEnvironment $TargetEnvironment
{{if IsCustomCloudProfile}}
$azureStackConfigFile = [io.path]::Combine($global:KubeDir, "azurestackcloud.json")
$envJSON = "{{ GetBase64EncodedEnvironmentJSON }}"
[io.file]::WriteAllBytes($azureStackConfigFile, [System.Convert]::FromBase64String($envJSON))
{{end}}
Write-Log "Write ca root"
Write-CACert -CACertificate $global:CACertificate `
-KubeDir $global:KubeDir
if ($global:EnableCsiProxy) {
New-CsiProxyService -CsiProxyPackageUrl $global:CsiProxyUrl -KubeDir $global:KubeDir
}
Write-Log "Write kube config"
Write-KubeConfig -CACertificate $global:CACertificate `
-KubeDir $global:KubeDir `
-MasterFQDNPrefix $MasterFQDNPrefix `
-MasterIP $MasterIP `
-AgentKey $AgentKey `
-AgentCertificate $global:AgentCertificate
if ($global:EnableHostsConfigAgent) {
Write-Log "Starting hosts config agent"
New-HostsConfigService
}
Write-Log "Create the Pause Container kubletwin/pause"
$infraContainerTimer = [System.Diagnostics.Stopwatch]::StartNew()
New-InfraContainer -KubeDir $global:KubeDir -ContainerRuntime $global:ContainerRuntime
$infraContainerTimer.Stop()
$global:AppInsightsClient.TrackMetric("New-InfraContainer", $infraContainerTimer.Elapsed.TotalSeconds)
if (-not (Test-ContainerImageExists -Image "kubletwin/pause" -ContainerRuntime $global:ContainerRuntime)) {
Write-Log "Could not find container with name kubletwin/pause"
if ($useContainerD) {
$o = ctr -n k8s.io image list
Write-Log $o
} else {
$o = docker image list
Write-Log $o
}
throw "kubletwin/pause container does not exist!"
}
Write-Log "Configuring networking with NetworkPlugin:$global:NetworkPlugin"
# Configure network policy.
Get-HnsPsm1 -HNSModule $global:HNSModule
Import-Module $global:HNSModule
if ($global:NetworkPlugin -eq "azure") {
Write-Log "Installing Azure VNet plugins"
Install-VnetPlugins -AzureCNIConfDir $global:AzureCNIConfDir `
-AzureCNIBinDir $global:AzureCNIBinDir `
-VNetCNIPluginsURL $global:VNetCNIPluginsURL
Set-AzureCNIConfig -AzureCNIConfDir $global:AzureCNIConfDir `
-KubeDnsSearchPath $global:KubeDnsSearchPath `
-KubeClusterCIDR $global:KubeClusterCIDR `
-MasterSubnet $global:MasterSubnet `
-KubeServiceCIDR $global:KubeServiceCIDR `
-VNetCIDR $global:VNetCIDR `
{{- /* Azure Stack has discrete Azure CNI config requirements */}}
-IsAzureStack {{if IsAzureStackCloud}}$true{{else}}$false{{end}} `
-IsDualStackEnabled $global:IsDualStackEnabled
if ($TargetEnvironment -ieq "AzureStackCloud") {
GenerateAzureStackCNIConfig `
-TenantId $global:TenantId `
-SubscriptionId $global:SubscriptionId `
-ResourceGroup $global:ResourceGroup `
-AADClientId $AADClientId `
-KubeDir $global:KubeDir `
-AADClientSecret $([System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($AADClientSecret))) `
-NetworkAPIVersion $NetworkAPIVersion `
-AzureEnvironmentFilePath $([io.path]::Combine($global:KubeDir, "azurestackcloud.json")) `
-IdentitySystem "{{ GetIdentitySystem }}"
}
}
elseif ($global:NetworkPlugin -eq "kubenet") {
Write-Log "Fetching additional files needed for kubenet"
if ($useContainerD) {
# TODO: CNI may need to move to c:\program files\containerd\cni\bin with ContainerD
Install-SdnBridge -Url $global:ContainerdSdnPluginUrl -CNIPath $global:CNIPath
} else {
Update-WinCNI -CNIPath $global:CNIPath
}
}
New-ExternalHnsNetwork -IsDualStackEnabled $global:IsDualStackEnabled
Install-KubernetesServices `
-KubeDir $global:KubeDir `
-ContainerRuntime $global:ContainerRuntime
Get-LogCollectionScripts
Write-Log "Disable Internet Explorer compat mode and set homepage"
Set-Explorer
# if multple LB policies are included for same endpoint then HNS hangs.
# this fix forces an error
Write-Host "Enable a HNS fix in 2021-2C+"
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\hns\State" -Name HNSControlFlag -Value 1 -Type DWORD
if ($global:WindowsSecureTLSEnabled) {
Write-Host "Enable secure TLS protocols"
. C:\k\windowssecuretls.ps1
Enable-SecureTls
}
Write-Log "Adjust pagefile size"
Adjust-PageFileSize
Write-Log "Start preProvisioning script"
PREPROVISION_EXTENSION
Write-Log "Update service failure actions"
Update-ServiceFailureActions -ContainerRuntime $global:ContainerRuntime
Adjust-DynamicPortRange
Register-LogsCleanupScriptTask
Register-NodeResetScriptTask
Update-DefenderPreferences
{{if IsAzureStackCloud}}
{{if UseCloudControllerManager}}
# Export the Azure Stack root cert for use in cloud node manager container setup.
$azsConfigFile = [io.path]::Combine($global:KubeDir, "azurestackcloud.json")
if (Test-Path -Path $azsConfigFile) {
$azsJson = Get-Content -Raw -Path $azsConfigFile | ConvertFrom-Json
if (-not [string]::IsNullOrEmpty($azsJson.managementPortalURL)) {
$azsARMUri = [System.Uri]$azsJson.managementPortalURL
$azsRootCert = Get-ChildItem -Path Cert:\LocalMachine\Root | Where-Object {$_.DnsNameList -contains $azsARMUri.Host.Substring($azsARMUri.Host.IndexOf(".")).TrimStart(".")}
if ($null -ne $azsRootCert) {
$azsRootCertFilePath = [io.path]::Combine($global:KubeDir, "azsroot.cer")
Export-Certificate -Cert $azsRootCert -FilePath $azsRootCertFilePath -Type CERT
}
}
}
# Copy certoc tool for use in cloud node manager container setup. [Environment]::SystemDirectory
$certocSourcePath = [io.path]::Combine([Environment]::SystemDirectory, "certoc.exe")
if (Test-Path -Path $certocSourcePath) {
Copy-Item -Path $certocSourcePath -Destination $global:KubeDir
}
# Create add cert script
$addRootCertFile = [io.path]::Combine($global:KubeDir, "addazsroot.bat")
[io.file]::WriteAllText($addRootCertFile, "${global:KubeDir}\certoc.exe -addstore root ${azsRootCertFilePath}")
{{end}}
{{end}}
if (Test-Path $CacheDir)
{
Write-Log "Removing aks-engine bits cache directory"
Remove-Item $CacheDir -Recurse -Force
}
$global:globalTimer.Stop()
$global:AppInsightsClient.TrackMetric("TotalDuration", $global:globalTimer.Elapsed.TotalSeconds)
$global:AppInsightsClient.Flush()
Write-Log "Setup Complete, reboot computer"
Restart-Computer
}
else
{
# keep for debugging purposes
Write-Log ".\CustomDataSetupScript.ps1 -MasterIP $MasterIP -KubeDnsServiceIp $KubeDnsServiceIp -MasterFQDNPrefix $MasterFQDNPrefix -Location $Location -AgentKey $AgentKey -AADClientId $AADClientId -AADClientSecret $AADClientSecret -NetworkAPIVersion $NetworkAPIVersion -TargetEnvironment $TargetEnvironment"
}
}
catch
{
$exceptionTelemtry = New-Object "Microsoft.ApplicationInsights.DataContracts.ExceptionTelemetry"
$exceptionTelemtry.Exception = $_.Exception
$global:AppInsightsClient.TrackException($exceptionTelemtry)
$global:AppInsightsClient.Flush()
Write-Error $_
throw $_
}