Skip to content

Commit

Permalink
chore: try other way
Browse files Browse the repository at this point in the history
  • Loading branch information
junjiezhang1997 committed Jan 19, 2024
1 parent 160e3fe commit f36ce3c
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 1,360 deletions.
111 changes: 16 additions & 95 deletions parts/windows/kuberneteswindowssetup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,7 @@ try
}

# Download CSE function scripts
$Configuration = @"
{
"CSEScriptsPackageUrl": "$global:CSEScriptsPackageUrl"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -EventMessage "Start to get CSE scripts" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -EventMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl"
Write-Log "Getting CSE scripts"
$tempfile = 'c:\csescripts.zip'
DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE
Expand All @@ -278,12 +273,7 @@ try
Logs-To-End-Event -TaskName "AKS.WindowsCSE.InstallOpenSSH" -IsClearTaskName $true
}

$Configuration = @"
{
"WindowsTelemetryGUID": "$global:WindowsTelemetryGUID"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.SetTelemetrySetting" -EventMessage "Start to apply telemetry data setting" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.SetTelemetrySetting" -EventMessage "Start to apply telemetry data setting. WindowsTelemetryGUID: $global:WindowsTelemetryGUID"
Write-Log "Apply telemetry data setting"
Set-TelemetrySetting -WindowsTelemetryGUID $global:WindowsTelemetryGUID
Logs-To-End-Event -TaskName "AKS.WindowsCSE.SetTelemetrySetting" -IsClearTaskName $true
Expand Down Expand Up @@ -316,22 +306,12 @@ try
Get-LogCollectionScripts
Logs-To-End-Event -TaskName "AKS.WindowsCSE.GetProvisioningAndLogCollectionScripts" -IsClearTaskName $true

$Configuration = @"
{
"WindowsPauseImageURL": "$global:WindowsPauseImageURL"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.WriteKubeClusterConfig" -EventMessage "Start to write KubeCluster Config" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.WriteKubeClusterConfig" -EventMessage "Start to write KubeCluster Config. WindowsPauseImageURL: $global:WindowsPauseImageURL"
Write-KubeClusterConfig -MasterIP $MasterIP -KubeDnsServiceIp $KubeDnsServiceIp
Logs-To-End-Event -TaskName "AKS.WindowsCSE.WriteKubeClusterConfig" -IsClearTaskName $true

$Configuration = @"
{
"KubeBinariesPackageSASURL": "$global:KubeBinariesPackageSASURL"
}
"@
Write-Log "Download kubelet binaries and unzip"
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.DownloadKubletBinaries" -EventMessage "Start to download kubelet binaries and unzip" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.DownloadKubletBinaries" -EventMessage "Start to download kubelet binaries and unzip. KubeBinariesPackageSASURL: $global:KubeBinariesPackageSASURL"
Get-KubePackage -KubeBinariesSASURL $global:KubeBinariesPackageSASURL
Logs-To-End-Event -TaskName "AKS.WindowsCSE.DownloadKubletBinaries" -IsClearTaskName $true

Expand All @@ -354,22 +334,12 @@ try
$cniBinPath = $global:CNIPath
$cniConfigPath = $global:CNIConfigPath
}
$Configuration = @"
{
"ContainerdUrl": "$global:ContainerdUrl",
"KubernetesVersion": "$global:KubeBinariesVersion"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallContainerdBasedOnKubernetesVersion" -EventMessage "Start to install ContainerD" -Configuration $Configuration

Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallContainerdBasedOnKubernetesVersion" -EventMessage "Start to install ContainerD. ContainerdUrl: $global:ContainerdUrl, KubernetesVersion: $global:KubeBinariesVersion"
Install-Containerd-Based-On-Kubernetes-Version -ContainerdUrl $global:ContainerdUrl -CNIBinDir $cniBinPath -CNIConfDir $cniConfigPath -KubeDir $global:KubeDir -KubernetesVersion $global:KubeBinariesVersion
Logs-To-End-Event -TaskName "AKS.WindowsCSE.InstallContainerdBasedOnKubernetesVersion" -IsClearTaskName $true

$Configuration = @"
{
"TargetEnvironment": "$TargetEnvironment"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.RetagImagesForAzureChinaCloud" -EventMessage "Start to retag images for Azure China Cloud" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.RetagImagesForAzureChinaCloud" -EventMessage "Start to retag images for Azure China Cloud"
Retag-ImagesForAzureChinaCloud -TargetEnvironment $TargetEnvironment
Logs-To-End-Event -TaskName "AKS.WindowsCSE.RetagImagesForAzureChinaCloud" -IsClearTaskName $true

Expand Down Expand Up @@ -417,12 +387,7 @@ try
Logs-To-End-Event -TaskName "AKS.WindowsCSE.WriteCACert" -IsClearTaskName $true

if ($global:EnableCsiProxy) {
$Configuration = @"
{
"CsiProxyUrl": "$global:CsiProxyUrl"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.StartCsiProxyService" -EventMessage "Start Csi proxy service" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.StartCsiProxyService" -EventMessage "Start Csi proxy service. CsiProxyUrl: $global:CsiProxyUrl"
New-CsiProxyService -CsiProxyPackageUrl $global:CsiProxyUrl -KubeDir $global:KubeDir
Logs-To-End-Event -TaskName "AKS.WindowsCSE.StartCsiProxyService" -IsClearTaskName $true
}
Expand Down Expand Up @@ -464,37 +429,19 @@ try
Write-Log "Configuring networking with NetworkPlugin:$global:NetworkPlugin"

# Configure network policy.
$Configuration = @"
{
"NetworkPlugin": "$global:NetworkPlugin",
"HNSModule": "$global:HNSModule"
}
"@
Logs-To-Start-Event "ASK.WindowsCSE.GetAndImportHNSModule" -EventMessage "Start to get and import hns module" -Configuration $Configuration
Logs-To-Start-Event "ASK.WindowsCSE.GetAndImportHNSModule" -EventMessage "Start to get and import hns module. NetworkPlugin: $global:NetworkPlugin, HNSModule: $global:HNSModule"
Get-HnsPsm1 -HNSModule $global:HNSModule
Import-Module $global:HNSModule
Logs-To-End-Event "AKS.WindowsCSE.GetAndImportHNSModule" -IsClearTaskName $true

$Configuration = @"
{
"VnetCNIPluginsURL": "$global:VNetCNIPluginsURL"
}
"@
Write-Log "Installing Azure VNet plugins"
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallVnetPlugins" -EventMessage "Start to install Azure VNet plugins" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallVnetPlugins" -EventMessage "Start to install Azure VNet plugins. VnetCNIPluginsURL: $global:VNetCNIPluginsURL"
Install-VnetPlugins -AzureCNIConfDir $global:AzureCNIConfDir `
-AzureCNIBinDir $global:AzureCNIBinDir `
-VNetCNIPluginsURL $global:VNetCNIPluginsURL
Logs-To-End-Event -TaskName "AKS.WindowsCSE.InstallVnetPlugins" -IsClearTaskName $true

$Configuration = @"
{
"IsDualStackEnabled": "$global:IsDualStackEnabled",
"IsAzureCNIOverlayEnabled": "$global:IsAzureCNIOverlayEnabled",
"IsDisableWindowsOutboundNat": "$global:IsDisableWindowsOutboundNat"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.SetAzureCNIConfig" -EventMessage "Start to set Azure CNI config" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.SetAzureCNIConfig" -EventMessage "Start to set Azure CNI config. IsDualStackEnabled: $global:IsDualStackEnabled, IsAzureCNIOverlayEnabled: $global:IsAzureCNIOverlayEnabled, IsDisableWindowsOutboundNat: $global:IsDisableWindowsOutboundNat"
Set-AzureCNIConfig -AzureCNIConfDir $global:AzureCNIConfDir `
-KubeDnsSearchPath $global:KubeDnsSearchPath `
-KubeClusterCIDR $global:KubeClusterCIDR `
Expand Down Expand Up @@ -553,12 +500,7 @@ try
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.RegisterLogsCleanupScriptTask" -EventMessage "Start to register logs cleanup script task"
Register-LogsCleanupScriptTask
Logs-To-End-Event -TaskName "AKS.WindowsCSE.RegisterLogsCleanupScriptTask" -IsClearTaskName $true
$Configuration = @"
{
"HNSRemediatorIntervalInMinutes": "$global:HNSRemediatorIntervalInMinutes"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.RegisterNodeResetScriptTask" -EventMessage "Start to register node reset script task" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.RegisterNodeResetScriptTask" -EventMessage "Start to register node reset script task. HNSRemediatorIntervalInMinutes: $global:HNSRemediatorIntervalInMinutes"
Register-NodeResetScriptTask
Logs-To-End-Event -TaskName "AKS.WindowsCSE.RegisterNodeResetScriptTask" -IsClearTaskName $true
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.UpdateDefenderPreferences" -EventMessage "Start to update defender preferences"
Expand All @@ -584,38 +526,22 @@ try

Enable-FIPSMode -FipsEnabled $fipsEnabled
if ($global:WindowsGmsaPackageUrl) {
$Configuration = @"
{
"WindowsGmsaPackageUrl": "$global:WindowsGmsaPackageUrl"
}
"@
Write-Log "Start to install Windows gmsa package"
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallGmsaPlugin" -EventMessage "Start to install Windows gmsa package" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallGmsaPlugin" -EventMessage "Start to install Windows gmsa package. WindowsGmsaPackageUrl: $global:WindowsGmsaPackageUrl"
Install-GmsaPlugin -GmsaPackageUrl $global:WindowsGmsaPackageUrl
Logs-To-End-Event -TaskName "AKS.WindowsCSE.InstallGmsaPlugin" -IsClearTaskName $true
}

Check-APIServerConnectivity -MasterIP $MasterIP

if ($global:WindowsCalicoPackageURL) {
$Configuration = @"
{
"WindowsCalicoPackageURL": "$global:WindowsCalicoPackageURL"
}
"@
Write-Log "Start calico installation"
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallCalico" -EventMessage "Start calico installation" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallCalico" -EventMessage "Start calico installation. WindowsCalicoPackageURL: $global:WindowsCalicoPackageURL"
Start-InstallCalico -RootDir "c:\" -KubeServiceCIDR $global:KubeServiceCIDR -KubeDnsServiceIp $KubeDnsServiceIp
Logs-To-End-Event -TaskName "AKS.WindowsCSE.InstallCalico" -IsClearTaskName $true
}

$Configuration = @"
{
"ConfigGPUDriverIfNeeded": "$global:ConfigGPUDriverIfNeeded",
"GpuDriverURL": "$global:GpuDriverURL"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallGPUDriver" -EventMessage "Start to install GPU driver" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.InstallGPUDriver" -EventMessage "Start to install GPU driver. ConfigGPUDriverIfNeeded: $global:ConfigGPUDriverIfNeeded, GpuDriverURL: $global:GpuDriverURL"
Start-InstallGPUDriver -EnableInstall $global:ConfigGPUDriverIfNeeded -GpuDriverURL $global:GpuDriverURL
Logs-To-End-Event -TaskName "AKS.WindowsCSE.InstallGPUDriver" -IsClearTaskName $true

Expand All @@ -631,12 +557,7 @@ try
Remove-Item $kubeConfigFile
}

$Configuration = @"
{
"LogGeneratorIntervalInMinutes": "$LogGeneratorIntervalInMinutes"
}
"@
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.EnableGuestVMLogs" -EventMessage "Start to enable Guest VM Logs" -Configuration $Configuration
Logs-To-Start-Event -TaskName "AKS.WindowsCSE.EnableGuestVMLogs" -EventMessage "Start to enable Guest VM Logs. LogGeneratorIntervalInMinutes: $LogGeneratorIntervalInMinutes"
Enable-GuestVMLogs -IntervalInMinutes $global:LogGeneratorIntervalInMinutes
Logs-To-End-Event -TaskName "AKS.WindowsCSE.EnableGuestVMLogs" -IsClearTaskName $true

Expand Down
11 changes: 2 additions & 9 deletions parts/windows/windowscsehelper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,22 @@ function Logs-To-Start-Event {
[Parameter(Mandatory = $true)][string]
$TaskName,
[Parameter(Mandatory = $true)][string]
$EventMessage,
$Configuration
$EventMessage
)

$global:EventTaskName = $TaskName
$eventsFileName=[DateTimeOffset]::UtcNow.ToUnixTimeMilliseconds()

$currentTime=$(Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff")

$messageJson = @"
{
"Event": "$EventMessage",
"Configuration": $Configuration
}
"@
$jsonString = @"
{
"Timestamp": "$currentTime",
"OperationId": "$global:OperationId",
"Version": "1.10",
"TaskName": "$global:EventTaskName",
"EventLevel": "Informational",
"Message": $messageJson,
"Message": "$EventMessage",
"EventPid": "0",
"EventTid": "0"
}
Expand Down
Loading

0 comments on commit f36ce3c

Please sign in to comment.