From 336d656c3908740793d44b2cb8e053a7cadbed5b Mon Sep 17 00:00:00 2001 From: Abel Hu Date: Wed, 13 Mar 2024 02:27:55 +0000 Subject: [PATCH] fix: avoid running Windows CSE multiple times --- parts/windows/kuberneteswindowssetup.ps1 | 6 ++++-- pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData | 6 ++++-- .../CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+K8S116/CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+K8S117/CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+K8S118/CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData | 6 ++++-- pkg/agent/testdata/AKSWindows2019+K8S119/CustomData | 6 ++++-- .../AKSWindows2019+KubeletClientTLSBootstrapping/CustomData | 6 ++++-- .../testdata/AKSWindows2019+ManagedIdentity/CustomData | 6 ++++-- .../testdata/AKSWindows2019+SecurityProfile/CustomData | 6 ++++-- pkg/templates/templates_generated.go | 6 ++++-- staging/cse/windows/kubernetesfunc.ps1 | 2 +- 15 files changed, 57 insertions(+), 29 deletions(-) diff --git a/parts/windows/kuberneteswindowssetup.ps1 b/parts/windows/kuberneteswindowssetup.ps1 index f98739abbbb..26d22b10042 100644 --- a/parts/windows/kuberneteswindowssetup.ps1 +++ b/parts/windows/kuberneteswindowssetup.ps1 @@ -210,7 +210,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -248,7 +248,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -488,6 +488,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData b/pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData index 870b184d524..12c2f6cb38b 100644 --- a/pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+CustomCloud/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -484,6 +484,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData b/pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData index a582972a480..f6f8c4e6818 100644 --- a/pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+CustomVnet/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+EnablePrivateClusterHostsConfigAgent/CustomData b/pkg/agent/testdata/AKSWindows2019+EnablePrivateClusterHostsConfigAgent/CustomData index bbe698783e5..98ee67d46d9 100644 --- a/pkg/agent/testdata/AKSWindows2019+EnablePrivateClusterHostsConfigAgent/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+EnablePrivateClusterHostsConfigAgent/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+K8S116/CustomData b/pkg/agent/testdata/AKSWindows2019+K8S116/CustomData index 27822cad74a..d4b0a9c43dd 100644 --- a/pkg/agent/testdata/AKSWindows2019+K8S116/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+K8S116/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+K8S117/CustomData b/pkg/agent/testdata/AKSWindows2019+K8S117/CustomData index a53adc50498..c1a35bd85a5 100644 --- a/pkg/agent/testdata/AKSWindows2019+K8S117/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+K8S117/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+K8S118/CustomData b/pkg/agent/testdata/AKSWindows2019+K8S118/CustomData index d66fcf2ff1b..bc5b2f15220 100644 --- a/pkg/agent/testdata/AKSWindows2019+K8S118/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+K8S118/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData b/pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData index 32bf338e939..ce4c3773efa 100644 --- a/pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+K8S119+CSI/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData b/pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData index d2a56b83aa0..77dfc72db1b 100644 --- a/pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+K8S119+FIPS/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+K8S119/CustomData b/pkg/agent/testdata/AKSWindows2019+K8S119/CustomData index 14b1b09b5a0..10a4eec97b6 100644 --- a/pkg/agent/testdata/AKSWindows2019+K8S119/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+K8S119/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+KubeletClientTLSBootstrapping/CustomData b/pkg/agent/testdata/AKSWindows2019+KubeletClientTLSBootstrapping/CustomData index f4c74971873..8e19c2ec483 100644 --- a/pkg/agent/testdata/AKSWindows2019+KubeletClientTLSBootstrapping/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+KubeletClientTLSBootstrapping/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+ManagedIdentity/CustomData b/pkg/agent/testdata/AKSWindows2019+ManagedIdentity/CustomData index 7b5ca5406a6..262ece221d4 100644 --- a/pkg/agent/testdata/AKSWindows2019+ManagedIdentity/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+ManagedIdentity/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/agent/testdata/AKSWindows2019+SecurityProfile/CustomData b/pkg/agent/testdata/AKSWindows2019+SecurityProfile/CustomData index 3ef5b6f45be..e05fe6bc3ab 100644 --- a/pkg/agent/testdata/AKSWindows2019+SecurityProfile/CustomData +++ b/pkg/agent/testdata/AKSWindows2019+SecurityProfile/CustomData @@ -206,7 +206,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -244,7 +244,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -478,6 +478,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/pkg/templates/templates_generated.go b/pkg/templates/templates_generated.go index 27aef8bfbe2..21c129a73f6 100644 --- a/pkg/templates/templates_generated.go +++ b/pkg/templates/templates_generated.go @@ -8392,7 +8392,7 @@ $global:RebootNeeded = $false # Extract cse helper script from ZIP [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) -Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" +Expand-Archive scripts.zip -DestinationPath "C:\\AzureData\\" -Force # Dot-source windowscsehelper.ps1 with functions that are called in this script . c:\AzureData\windows\windowscsehelper.ps1 @@ -8430,7 +8430,7 @@ try Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl" $tempfile = 'c:\csescripts.zip' DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE - Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" + Expand-Archive $tempfile -DestinationPath "C:\\AzureData\\windows" -Force Remove-Item -Path $tempfile -Force # Dot-source cse scripts with functions that are called in this script @@ -8670,6 +8670,8 @@ finally # Generate CSE result so it can be returned as the CSE response in csecmd.ps1 $ExecutionDuration=$(New-Timespan -Start $StartTime -End $(Get-Date)) Write-Log "CSE ExecutionDuration: $ExecutionDuration. ExitCode: $global:ExitCode" + # $CSEResultFilePath is used to avoid running CSE multiple times + Set-Content -Path $CSEResultFilePath -Value $global:ExitCode -Force Logs-To-Event -TaskName "AKS.WindowsCSE.cse_main" -TaskMessage "ExitCode: $global:ExitCode. ErrorMessage: $global:ErrorMessage." # Please not use Write-Log or Logs-To-Events after Stop-Transcript Stop-Transcript diff --git a/staging/cse/windows/kubernetesfunc.ps1 b/staging/cse/windows/kubernetesfunc.ps1 index 08fc59953ba..47c34d30f1e 100644 --- a/staging/cse/windows/kubernetesfunc.ps1 +++ b/staging/cse/windows/kubernetesfunc.ps1 @@ -3,7 +3,7 @@ function Get-ProvisioningScripts { Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_NOT_FOUND_PROVISIONING_SCRIPTS -ErrorMessage "Failed to found provisioning scripts" } Write-Log "Copying provisioning scripts" - Move-Item 'c:\AzureData\windows\provisioningscripts\*' 'c:\k' + Move-Item 'c:\AzureData\windows\provisioningscripts\*' 'c:\k' -Force Remove-Item -Path 'c:\AzureData\windows\provisioningscripts' -Force }