Skip to content

Commit 77b5630

Browse files
committed
f
1 parent 9b49cbe commit 77b5630

21 files changed

Lines changed: 913 additions & 575 deletions

File tree

parts/windows/kuberneteswindowssetup.ps1

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ $global:WindowsCiliumInstallPath = Join-Path -Path $global:WindowsCiliumNetworki
223223
# Network isolated cluster
224224
$global:BootstrapProfileContainerRegistryServer="{{GetBootstrapProfileContainerRegistryServer}}"
225225
$global:MCRRepositoryBase="{{GetMCRRepositoryBase}}"
226+
$global:NetworkIsolatedClusterTestMode = [System.Convert]::ToBoolean("{{GetNetworkIsolatedClusterTestMode}}"); # for ab e2e only for local ab test with remote cse package
226227

227228
$global:OrasCacheDir="c:\aks-tools\oras\" # refer to components.json
228229
$global:OrasPath="c:\aks-tools\oras\oras.exe"
@@ -245,49 +246,61 @@ try {
245246

246247
$global:OperationId = New-Guid
247248

248-
if (
249-
-not (Test-Path "C:\AzureData\windows\azurecnifunc.ps1") -and
250-
([string]::IsNullOrWhiteSpace($global:BootstrapProfileContainerRegistryServer)) # skip download for network isolated cluster which will use cached scripts
251-
) {
252-
# Determine the CSE package URL
253-
$WindowsCSEScriptsPackage = "aks-windows-cse-scripts-current.zip"
249+
if (-not (Test-Path "C:\AzureData\windows\azurecnifunc.ps1")) {
254250
# CSEScriptsPackage is cached on VHD. Previously the cse package version was managed in components.json, whereas RP set the package URL which is a storage account.
255-
# From 2025-06 The CSE packages is eleased on the VHD. RP can use fully qualified URL to download CSE scripts package when required out of VHD release cycle.
251+
# From 2025-06 The CSE packages is released on the VHD. RP can use fully qualified URL to download CSE scripts package when required out of VHD release cycle.
256252
# In the transition period, it is important that when deal with older VHD versions, the agentbaker runtime provision script needs to be compatible with the latest known storage account package, 0.0.52.
257-
Write-Log "Requested CSEScriptsPackageUrl is $global:CSEScriptsPackageUrl"
258-
if ($global:CSEScriptsPackageUrl.EndsWith("/")) {
259-
$search = @()
260-
if ($global:CacheDir -and (Test-Path $global:CacheDir)) {
261-
$search = [IO.Directory]::GetFiles($global:CacheDir, $WindowsCSEScriptsPackage, [IO.SearchOption]::AllDirectories)
262-
# list files in the cache directory.
263-
Write-Log "the directory $global:CacheDir contains the following files:"
264-
Get-ChildItem -Path $global:CacheDir | ForEach-Object { Write-Log " $_" }
253+
254+
$WindowsCSEScriptsPackage = "aks-windows-cse-scripts-current.zip"
255+
$scriptsZip = $null
256+
$shouldCleanup = $false
257+
258+
# Step 1: Try to find cached scripts on VHD
259+
if ($global:CacheDir -and (Test-Path $global:CacheDir)) {
260+
$searchCachedScripts = [IO.Directory]::GetFiles($global:CacheDir, $WindowsCSEScriptsPackage, [IO.SearchOption]::AllDirectories)
261+
Write-Log "the directory $global:CacheDir contains the following files:"
262+
Get-ChildItem -Path $global:CacheDir | ForEach-Object { Write-Log " $_" }
263+
if ($searchCachedScripts.Count -gt 0) {
264+
$scriptsZip = $searchCachedScripts[0]
265+
Write-Log "Found cached CSE scripts at $scriptsZip"
265266
}
267+
}
266268

267-
if ($search.Count -eq 0) {
268-
Write-Log "Could not find windows cse package on VHD. Use remote version instead."
269-
$WindowsCSEScriptsPackage = "aks-windows-cse-scripts-v0.0.52.zip"
269+
# Step 2: For non-network-isolated clusters, download scripts if needed (overrides cached version when appropriate)
270+
$isNetworkIsolated = -not [string]::IsNullOrWhiteSpace($global:BootstrapProfileContainerRegistryServer) -and -not $global:NetworkIsolatedClusterTestMode
271+
if (-not $isNetworkIsolated) {
272+
Write-Log "Requested CSEScriptsPackageUrl is $global:CSEScriptsPackageUrl"
273+
if ($global:CSEScriptsPackageUrl.EndsWith("/")) {
274+
if (-not $scriptsZip) {
275+
Write-Log "Could not find windows cse package on VHD. Use remote version instead."
276+
$WindowsCSEScriptsPackage = "aks-windows-cse-scripts-v0.0.52.zip"
277+
}
278+
Write-Log "WindowsCSEScriptsPackage is $WindowsCSEScriptsPackage"
279+
$global:CSEScriptsPackageUrl = $global:CSEScriptsPackageUrl + $WindowsCSEScriptsPackage
280+
}
281+
Write-Log "CSEScriptsPackageUrl used for provision is $global:CSEScriptsPackageUrl"
282+
283+
# Download CSE function scripts
284+
$downloadedFile = 'c:\csescripts.zip'
285+
Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl"
286+
DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $downloadedFile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE
287+
$scriptsZip = $downloadedFile
288+
$shouldCleanup = $true
289+
} else {
290+
Write-Log "Network isolated cluster detected (BootstrapProfileContainerRegistryServer is set), skip CSE scripts download and use cached scripts"
291+
if (-not $scriptsZip) {
292+
Set-ExitCode -ExitCode $global:WINDOWS_CSE_ERROR_NETWORK_ISOLATED_CLUSTER_CSE_NOT_CACHED -ErrorMessage "Cached CSE scripts package '$WindowsCSEScriptsPackage' not found under cache directory '$global:CacheDir'"
270293
}
271-
Write-Log "WindowsCSEScriptsPackage is $WindowsCSEScriptsPackage"
272-
$global:CSEScriptsPackageUrl = $global:CSEScriptsPackageUrl + $WindowsCSEScriptsPackage
273294
}
274-
Write-Log "CSEScriptsPackageUrl used for provision is $global:CSEScriptsPackageUrl"
275-
276-
# Download CSE function scripts
277-
Logs-To-Event -TaskName "AKS.WindowsCSE.DownloadAndExpandCSEScriptPackageUrl" -TaskMessage "Start to get CSE scripts. CSEScriptsPackageUrl: $global:CSEScriptsPackageUrl"
278-
$tempfile = 'c:\csescripts.zip'
279-
DownloadFileOverHttp -Url $global:CSEScriptsPackageUrl -DestinationPath $tempfile -ExitCode $global:WINDOWS_CSE_ERROR_DOWNLOAD_CSE_PACKAGE
280-
AKS-Expand-Archive -Path $tempfile -DestinationPath "C:\\AzureData\\windows"
281-
Remove-Item -Path $tempfile -Force
282-
} else {
283-
Write-Log "CSE scripts already exist or detect network isolated cluster, skipping download"
284-
}
285295

286-
# always use the cached scripts for network isolated cluster
287-
if (-not (Test-Path "C:\AzureData\windows\azurecnifunc.ps1") -and
288-
(-not [string]::IsNullOrWhiteSpace($global:BootstrapProfileContainerRegistryServer))) {
289-
Write-Log "BootstrapProfileContainerRegistryServer is set, skip CSE scripts download"
290-
Install-CachedScripts -ExitCode $global:WINDOWS_CSE_ERROR_NETWORK_ISOLATED_CLUSTER_CSE_NOT_CACHED
296+
# Step 3: Extract scripts from the resolved zip
297+
Write-Log "Extracting CSE scripts from $scriptsZip"
298+
AKS-Expand-Archive -Path $scriptsZip -DestinationPath "C:\\AzureData\\windows"
299+
if ($shouldCleanup) {
300+
Remove-Item -Path $scriptsZip -Force
301+
}
302+
} else {
303+
Write-Log "CSE scripts already exist, skipping download"
291304
}
292305

293306
# Dot-source cse scripts with functions that are called in this script

parts/windows/windowscsehelper.ps1

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -651,37 +651,3 @@ function Resolve-Error ($ErrorRecord=$Error[0])
651651
$Exception |Format-List * -Force
652652
}
653653
}
654-
655-
function Install-CachedScripts {
656-
Param(
657-
[Parameter(Mandatory = $true)][int]
658-
$ExitCode
659-
)
660-
661-
$fileName = "aks-windows-cse-scripts-current.zip"
662-
663-
$search = @()
664-
if ($global:CacheDir -and (Test-Path $global:CacheDir)) {
665-
$search = [IO.Directory]::GetFiles($global:CacheDir, $fileName, [IO.SearchOption]::AllDirectories)
666-
}
667-
668-
if ($search.Count -ne 0) {
669-
$tempfile = 'c:\csescripts.zip'
670-
Write-Log "Using cached version of $fileName - Copying file from $($search[0]) to $tempfile"
671-
try {
672-
Copy-Item -Path $search[0] -Destination $tempfile -Force
673-
AKS-Expand-Archive -Path $tempfile -DestinationPath "C:\\AzureData\\windows"
674-
}
675-
catch {
676-
Set-ExitCode -ExitCode $ExitCode -ErrorMessage ("failed to install cached CSE scripts: {0}" -f $_.Exception.Message)
677-
return
678-
}
679-
finally {
680-
Remove-Item -Path $tempfile -Force -ErrorAction SilentlyContinue
681-
}
682-
}
683-
else {
684-
Set-ExitCode -ExitCode $ExitCode -ErrorMessage "cached CSE not found in VHD"
685-
}
686-
}
687-

parts/windows/windowscsehelper.tests.ps1

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -429,61 +429,6 @@ Describe "DownloadFileOverHttp" {
429429
}
430430
}
431431

432-
Describe "Install-CachedScripts" {
433-
BeforeEach {
434-
$script:originalCacheDir = $global:CacheDir
435-
$global:CacheDir = Join-Path $TestDrive ([guid]::NewGuid().ToString())
436-
437-
Mock Copy-Item -MockWith {}
438-
Mock AKS-Expand-Archive -MockWith {}
439-
Mock Remove-Item -MockWith {}
440-
Mock Set-ExitCode -MockWith {
441-
param(
442-
[Parameter(Mandatory = $true)][int]$ExitCode,
443-
[Parameter(Mandatory = $true)][string]$ErrorMessage
444-
)
445-
throw "Set-ExitCode:${ExitCode}:${ErrorMessage}"
446-
}
447-
}
448-
449-
AfterEach {
450-
$global:CacheDir = $script:originalCacheDir
451-
}
452-
453-
It "copies and expands cached CSE scripts when cache file exists" {
454-
$nestedDir = Join-Path $global:CacheDir "nested"
455-
New-Item -ItemType Directory -Path $nestedDir -Force | Out-Null
456-
457-
$cachedArchive = Join-Path $nestedDir "aks-windows-cse-scripts-current.zip"
458-
New-Item -ItemType File -Path $cachedArchive -Force | Out-Null
459-
460-
{ Install-CachedScripts -ExitCode 33 } | Should -Not -Throw
461-
462-
Assert-MockCalled -CommandName 'Copy-Item' -Times 1 -ParameterFilter {
463-
$Path -eq $cachedArchive -and $Destination -eq 'c:\csescripts.zip'
464-
}
465-
Assert-MockCalled -CommandName 'AKS-Expand-Archive' -Times 1 -ParameterFilter {
466-
$Path -eq 'c:\csescripts.zip' -and $DestinationPath -eq 'C:\\AzureData\\windows'
467-
}
468-
Assert-MockCalled -CommandName 'Remove-Item' -Times 1
469-
Assert-MockCalled -CommandName 'Set-ExitCode' -Times 0
470-
}
471-
472-
It "sets exit code when cached CSE scripts are not found" {
473-
New-Item -ItemType Directory -Path $global:CacheDir -Force | Out-Null
474-
475-
{
476-
Install-CachedScripts -ExitCode 33
477-
} | Should -Throw "*Set-ExitCode:33:cached CSE not found in VHD*"
478-
479-
Assert-MockCalled -CommandName 'Copy-Item' -Times 0
480-
Assert-MockCalled -CommandName 'AKS-Expand-Archive' -Times 0
481-
Assert-MockCalled -CommandName 'Set-ExitCode' -Times 1 -ParameterFilter {
482-
$ExitCode -eq 33 -and $ErrorMessage -eq 'cached CSE not found in VHD'
483-
}
484-
}
485-
}
486-
487432
Describe "Update-BaseUrl" {
488433
BeforeEach {
489434
# Reset the PackageDownloadFqdn before each test

0 commit comments

Comments
 (0)