-
Notifications
You must be signed in to change notification settings - Fork 250
Xinhl/niabwin3 #8037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Xinhl/niabwin3 #8037
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…er in windows
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -221,8 +221,13 @@ $global:WindowsCiliumNetworkingPath = Join-Path -Path $global:cacheDir -ChildPat | |
| $global:WindowsCiliumInstallPath = Join-Path -Path $global:WindowsCiliumNetworkingPath -ChildPath 'install' | ||
|
|
||
| # Network isolated cluster | ||
| $global:BOOTSTRAP_PROFILE_CONTAINER_REGISTRY_SERVER="{{GetBootstrapProfileContainerRegistryServer}}" | ||
| $global:MCR_REPOSITORY_BASE="{{GetMCRRepositoryBase}}" | ||
| $global:BootstrapProfileContainerRegistryServer="{{GetBootstrapProfileContainerRegistryServer}}" | ||
| $global:MCRRepositoryBase="{{GetMCRRepositoryBase}}" | ||
|
|
||
| $global:OrasCacheDir="c:\aks-tools\oras\" # refer to components.json | ||
| $global:OrasPath="c:\aks-tools\oras\oras.exe" | ||
| $global:OrasOutput="c:\aks-tools\oras\oras_verbose.out" | ||
| $global:OrasRegistryConfigFile="c:\aks-tools\oras\config.yaml" # oras registry auth config file, not used, but have to define to avoid error "Error: failed to get user home directory: $HOME is not defined" | ||
|
Comment on lines
223
to
+230
|
||
|
|
||
| # Extract cse helper script from ZIP | ||
| [io.file]::WriteAllBytes("scripts.zip", [System.Convert]::FromBase64String($zippedFiles)) | ||
|
|
@@ -291,6 +296,12 @@ if (Test-Path -Path 'c:\AzureData\windows\windowsciliumnetworkingfunc.ps1') { | |
| Write-Log "Windows Cilium Networking function script not found, skipping dot-source" | ||
| } | ||
|
|
||
| if (Test-Path -Path 'c:\AzureData\windows\networkisolatedclusterfunc.ps1') { | ||
| . c:\AzureData\windows\networkisolatedclusterfunc.ps1 | ||
| } else { | ||
| Write-Log "Network Isolated Cluster function script not found, skipping dot-source" | ||
| } | ||
|
|
||
| # ====== BASE PREP: BASE IMAGE PREPARATION ====== | ||
| # All operations that prepare the base VHD image | ||
| function BasePrep { | ||
|
|
@@ -333,6 +344,18 @@ function BasePrep { | |
|
|
||
| Write-KubeClusterConfig -MasterIP $MasterIP -KubeDnsServiceIp $KubeDnsServiceIp | ||
|
|
||
| # oras login must be in front of Install-CredentialProvider, Get-KubePackage and Install-Containerd-Based-On-Kubernetes-Version | ||
| if ((Test-Path variable:global:BootstrapProfileContainerRegistryServer) -and | ||
| -not [string]::IsNullOrWhiteSpace($global:BootstrapProfileContainerRegistryServer)) { | ||
| # variable exists and is not empty/whitespace | ||
| if (Get-Command -Name Ensure-Oras -ErrorAction SilentlyContinue) { | ||
| Logs-To-Event -TaskName "AKS.WindowsCSE.EnsureOras" -TaskMessage "Ensure oras is installed for network isolated cluster" | ||
| Ensure-Oras | ||
| } else { | ||
| Write-Log "Ensure-Oras is not a recognized function, will skip oras installation for network isolated cluster" | ||
| } | ||
| } | ||
|
|
||
| # to ensure we don't introduce any incompatibility between base CSE + CSE package versions | ||
| if (Get-Command -Name Install-SecureTLSBootstrapClient -ErrorAction SilentlyContinue) { | ||
| Install-SecureTLSBootstrapClient -KubeDir $global:KubeDir -CustomSecureTLSBootstrapClientDownloadUrl $global:CustomSecureTLSBootstrappingClientDownloadURL | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,67 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # functions for network isolated cluster | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # unpackage and install oras from cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Oras is used for pulling windows binaries, e.g. windowszip, from private container registry when it is network isolated cluster. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function Ensure-Oras { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check if OrasPath variable exists to avoid latest cached cse in vhd with possible old ab svc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $orasPathVarExists = Test-Path variable:global:OrasPath | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (-not $orasPathVarExists) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Log "OrasPath variable does not exist. Setting OrasPath to default value C:\aks-tools\oras\oras.exe" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $global:OrasPath = "C:\aks-tools\oras\oras.exe" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $orasFileExists = $false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ($orasPathVarExists -and -not [string]::IsNullOrWhiteSpace($global:OrasPath)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $orasFileExists = Test-Path -Path $global:OrasPath -PathType Leaf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Test-Path -Path $global:OrasPath) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # oras already installed, skip | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Write-Log "Oras already installed at $($global:OrasPath)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Ensure cache directory exists before checking for archives or downloading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (-Not (Test-Path $global:OrasCacheDir)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| New-Item -ItemType Directory -Path $global:OrasCacheDir -Force | Out-Null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (-Not (Test-Path $global:OrasCacheDir)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+28
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Test-Path -Path $global:OrasPath) { | |
| # oras already installed, skip | |
| Write-Log "Oras already installed at $($global:OrasPath)" | |
| return | |
| } | |
| # Ensure cache directory exists before checking for archives or downloading | |
| if (-Not (Test-Path $global:OrasCacheDir)) { | |
| New-Item -ItemType Directory -Path $global:OrasCacheDir -Force | Out-Null | |
| } | |
| if (-Not (Test-Path $global:OrasCacheDir)) { | |
| # Check if OrasCacheDir variable exists to avoid calling Test-Path with a null path when mixing old/new components | |
| $orasCacheDirVarExists = Test-Path variable:global:OrasCacheDir | |
| if (-not $orasCacheDirVarExists) { | |
| Write-Log "OrasCacheDir variable does not exist. Setting OrasCacheDir to default value C:\aks-tools\oras-cache" | |
| $global:OrasCacheDir = "C:\aks-tools\oras-cache" | |
| } | |
| if (Test-Path -Path $global:OrasPath) { | |
| # oras already installed, skip | |
| Write-Log "Oras already installed at $($global:OrasPath)" | |
| return | |
| } | |
| # Ensure cache directory exists before checking for archives or downloading | |
| if (-Not (Test-Path -Path $global:OrasCacheDir)) { | |
| New-Item -ItemType Directory -Path $global:OrasCacheDir -Force | Out-Null | |
| } | |
| if (-Not (Test-Path -Path $global:OrasCacheDir)) { |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
|
|
||
| BeforeAll { | ||
| . $PSScriptRoot\..\..\..\parts\windows\windowscsehelper.ps1 | ||
| . $PSCommandPath.Replace('.tests.ps1', '.ps1') | ||
|
|
||
| } | ||
|
|
||
| Describe "Ensure-Oras" { | ||
| BeforeEach { | ||
| $global:OrasPath = "C:\aks-tools\oras\oras.exe" | ||
| $global:OrasCacheDir = "C:\akse-cache\oras" | ||
| $script:archiveExtractCalls = 0 | ||
|
|
||
| Mock New-Item -MockWith {} | ||
| Mock Expand-Archive -MockWith { $script:archiveExtractCalls++ } | ||
| Mock AKS-Expand-Archive -MockWith { | ||
| param($Path, $DestinationPath, $Force) | ||
| $script:archiveExtractCalls++ | ||
| } | ||
| Mock tar -MockWith {} | ||
| Mock Set-ExitCode -MockWith { | ||
| Param( | ||
| [Parameter(Mandatory = $true)][int]$ExitCode, | ||
| [Parameter(Mandatory = $true)][string]$ErrorMessage | ||
| ) | ||
| throw "Set-ExitCode:${ExitCode}:${ErrorMessage}" | ||
| } | ||
| } | ||
|
|
||
| It "should return early when oras executable already exists" { | ||
| Mock Test-Path -MockWith { | ||
| Param($Path) | ||
| return $Path -eq $global:OrasPath | ||
| } | ||
|
|
||
| { Ensure-Oras } | Should -Not -Throw | ||
| Assert-MockCalled -CommandName 'New-Item' -Times 0 | ||
| Assert-MockCalled -CommandName 'Expand-Archive' -Times 0 | ||
| Assert-MockCalled -CommandName 'AKS-Expand-Archive' -Times 0 | ||
| } | ||
|
|
||
| It "should extract cached zip archive and install oras" { | ||
| $script:orasInstalled = $false | ||
|
|
||
| Mock Test-Path -MockWith { | ||
| Param($Path) | ||
| switch ($Path) { | ||
| { $_ -eq $global:OrasPath } { return $script:orasInstalled } | ||
| { $_ -eq $global:OrasCacheDir } { return $true } | ||
| { $_ -eq "C:\aks-tools\oras" } { return $false } | ||
| default { return $true } | ||
| } | ||
| } | ||
|
|
||
| Mock Get-ChildItem -MockWith { | ||
| return [pscustomobject]@{ Name = "oras_1.3.0_windows_amd64.zip"; FullName = "C:\akse-cache\oras\oras_1.3.0_windows_amd64.zip" } | ||
| } | ||
|
|
||
| Mock Expand-Archive -MockWith { | ||
| $script:archiveExtractCalls++ | ||
| $script:orasInstalled = $true | ||
| } | ||
| Mock AKS-Expand-Archive -MockWith { | ||
| param($Path, $DestinationPath, $Force) | ||
| $script:archiveExtractCalls++ | ||
| $script:orasInstalled = $true | ||
| } | ||
|
|
||
| { Ensure-Oras } | Should -Not -Throw | ||
| $script:archiveExtractCalls | Should -Be 1 | ||
| } | ||
|
|
||
| It "should fail when no cached oras archive exists" { | ||
| Mock Test-Path -MockWith { | ||
| Param($Path) | ||
| return $Path -ne $global:OrasPath | ||
| } | ||
|
|
||
| Mock Get-ChildItem -MockWith { @() } | ||
|
|
||
| { | ||
| Ensure-Oras | ||
| } | Should -Throw "*Set-ExitCode:$($global:WINDOWS_CSE_ERROR_ORAS_NOT_FOUND):No oras archive*" | ||
| } | ||
|
|
||
| It "should fail when tar extraction returns non-zero exit code" { | ||
| Mock Test-Path -MockWith { | ||
| Param($Path) | ||
| switch ($Path) { | ||
| { $_ -eq $global:OrasPath } { return $false } | ||
| { $_ -eq $global:OrasCacheDir } { return $true } | ||
| { $_ -eq "C:\aks-tools\oras" } { return $true } | ||
| default { return $true } | ||
| } | ||
| } | ||
|
|
||
| Mock Get-ChildItem -MockWith { | ||
| return [pscustomobject]@{ Name = "oras_1.3.0_windows_amd64.tar.gz"; FullName = "C:\akse-cache\oras\oras_1.3.0_windows_amd64.tar.gz" } | ||
| } | ||
|
|
||
| Mock tar -MockWith { $global:LASTEXITCODE = 1 } | ||
|
|
||
| { | ||
| Ensure-Oras | ||
| } | Should -Throw "*Set-ExitCode:$($global:WINDOWS_CSE_ERROR_ORAS_NOT_FOUND):Failed to extract oras archive*" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment for
$global:OrasRegistryConfigFilesays it is “not used”, but the new network-isolated-cluster functions pass it toorasvia--registry-config. Please update the comment to reflect actual usage (and, if applicable, why a custom path is required in this environment).