diff --git a/parts/common/components.json b/parts/common/components.json index f9aa47eb7c7..0a0fdf40bf3 100644 --- a/parts/common/components.json +++ b/parts/common/components.json @@ -820,7 +820,7 @@ "previousLatestVersion": "0.0.50" } ], - "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip" } } } @@ -837,7 +837,7 @@ "latestVersion": "1.1.5" } ], - "downloadURL": "https://acs-mirror.azureedge.net/ccgakvplugin/v1.1.5/binaries/windows-gmsa-ccgakvplugin-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/ccgakvplugin/v1.1.5/binaries/windows-gmsa-ccgakvplugin-v${version}.zip" } } } @@ -854,7 +854,7 @@ "latestVersion": "1.1.2-hotfix.20230807" } ], - "downloadURL": "https://acs-mirror.azureedge.net/csi-proxy/v[version]/binaries/csi-proxy-v[version].tar.gz" + "downloadURL": "https://acs-mirror.azureedge.net/csi-proxy/v${version}/binaries/csi-proxy-v${version}.tar.gz" } } } @@ -872,7 +872,7 @@ "previousLatestVersion": "1.30.0" } ], - "downloadURL": "https://acs-mirror.azureedge.net/cloud-provider-azure/v[version]/binaries/azure-acr-credential-provider-windows-amd64-v[version].tar.gz" + "downloadURL": "https://acs-mirror.azureedge.net/cloud-provider-azure/v${version}/binaries/azure-acr-credential-provider-windows-amd64-v${version}.tar.gz" } } } @@ -889,7 +889,7 @@ "latestVersion": "3.24.0" } ], - "downloadURL": "https://acs-mirror.azureedge.net/calico-node/v[version]/binaries/calico-windows-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/calico-node/v${version}/binaries/calico-windows-v${version}.zip" } } } @@ -907,7 +907,7 @@ "previousLatestVersion": "1.5.38" } ], - "downloadURL": "https://acs-mirror.azureedge.net/azure-cni/v[version]/binaries/azure-vnet-cni-windows-amd64-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/azure-cni/v${version}/binaries/azure-vnet-cni-windows-amd64-v${version}.zip" } } } @@ -925,7 +925,7 @@ "previousLatestVersion": "1.4.58" } ], - "downloadURL": "https://acs-mirror.azureedge.net/azure-cni/v[version]/binaries/azure-vnet-cni-swift-windows-amd64-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/azure-cni/v${version}/binaries/azure-vnet-cni-swift-windows-amd64-v${version}.zip" } } } @@ -943,7 +943,7 @@ "previousLatestVersion": "1.4.58" } ], - "downloadURL": "https://acs-mirror.azureedge.net/azure-cni/v[version]/binaries/azure-vnet-cni-overlay-windows-amd64-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/azure-cni/v${version}/binaries/azure-vnet-cni-overlay-windows-amd64-v${version}.zip" } } } @@ -1092,7 +1092,7 @@ "previousLatestVersion": "v1.7.17-azure.1" } ], - "downloadURL": "https://acs-mirror.azureedge.net/containerd/windows/[version]/binaries/containerd-[version]-windows-amd64.tar.gz" + "downloadURL": "https://acs-mirror.azureedge.net/containerd/windows/${version}/binaries/containerd-${version}-windows-amd64.tar.gz" }, "ws2022": { "versionsV2": [ @@ -1106,7 +1106,7 @@ "previousLatestVersion": "v1.7.17-azure.1" } ], - "downloadURL": "https://acs-mirror.azureedge.net/containerd/windows/[version]/binaries/containerd-[version]-windows-amd64.tar.gz" + "downloadURL": "https://acs-mirror.azureedge.net/containerd/windows/${version}/binaries/containerd-${version}-windows-amd64.tar.gz" }, "default": { "versionsV2": [ @@ -1116,7 +1116,7 @@ "previousLatestVersion": "v1.7.17-azure.1" } ], - "downloadURL": "https://acs-mirror.azureedge.net/containerd/windows/[version]/binaries/containerd-[version]-windows-amd64.tar.gz" + "downloadURL": "https://acs-mirror.azureedge.net/containerd/windows/${version}/binaries/containerd-${version}-windows-amd64.tar.gz" } }, "default": { @@ -1247,7 +1247,7 @@ } ], "downloadURL": "mcr.microsoft.com/oss/binaries/kubernetes/kubernetes-node:${version}-linux-${CPU_ARCH}", - "windowsDownloadURL": "https://acs-mirror.azureedge.net/kubernetes/[version]/windowszip/[version]-1int.zip" + "windowsDownloadURL": "https://acs-mirror.azureedge.net/kubernetes/${version}/windowszip/${version}-1int.zip" } } } diff --git a/vhdbuilder/packer/windows/components_json_helpers.ps1 b/vhdbuilder/packer/windows/components_json_helpers.ps1 index afa20634ce8..d5fde34bdaf 100644 --- a/vhdbuilder/packer/windows/components_json_helpers.ps1 +++ b/vhdbuilder/packer/windows/components_json_helpers.ps1 @@ -1,3 +1,19 @@ + +function SafeReplaceString { + Param( + [Parameter(Mandatory = $true)][string] + $stringToReplace + ) + + $stringToReplace = &{ + Clear-Variable -Name * -Exclude version,CPU_ARCH,stringToReplace -ErrorAction SilentlyContinue + $executionContext.InvokeCommand.ExpandString($stringToReplace) + } + + return $stringToReplace +} + + function GetComponentsFromComponentsJson { Param( @@ -26,12 +42,16 @@ function GetComponentsFromComponentsJson $skuMatch = $windowsVersion.windowsSkuMatch if ($skuMatch -eq $null -or $windowsSku -eq $null -or $windowsSku -Like $skuMatch) { - $url = $downloadUrl.replace("*", $windowsVersion.latestVersion) + $version = $windowsVersion.latestVersion + $url = SafeReplaceString($downloadUrl) + $url = $url.replace("*", $windowsVersion.latestVersion) $output += $url if (-not [string]::IsNullOrEmpty($windowsVersion.previousLatestVersion)) { - $url = $downloadUrl.replace("*", $windowsVersion.previousLatestVersion) + $version = $windowsVersion.previousLatestVersion + $url = SafeReplaceString($downloadUrl) + $url = $url.replace("*", $windowsVersion.previousLatestVersion) $output += $url } } @@ -102,12 +122,14 @@ function GetPackagesFromComponentsJson foreach ($windowsVersion in $items) { - $url = $downloadUrl.replace("[version]", $windowsVersion.latestVersion) + $version = $windowsVersion.latestVersion + $url = SafeReplaceString($downloadUrl) $thisList += $url if (-not [string]::IsNullOrEmpty($windowsVersion.previousLatestVersion)) { - $url = $downloadUrl.replace("[version]", $windowsVersion.previousLatestVersion) + $version = $windowsVersion.previousLatestVersion + $url = SafeReplaceString($downloadUrl) $thisList += $url } } diff --git a/vhdbuilder/packer/windows/components_json_helpers.tests.ps1 b/vhdbuilder/packer/windows/components_json_helpers.tests.ps1 index d9a6445f5dd..63616b88ff7 100644 --- a/vhdbuilder/packer/windows/components_json_helpers.tests.ps1 +++ b/vhdbuilder/packer/windows/components_json_helpers.tests.ps1 @@ -3,6 +3,36 @@ BeforeAll { . $PSCommandPath.Replace('.tests.ps1', '.ps1') } +Describe 'SafeReplaceString' { + It 'given no vars are present, it returns the string' { + SafeReplaceString "this is a string" | Should -Be "this is a string" + } + + It 'given version var is present, it replaces version' { + # set the str before the $version env var so that we know it's being replaced in the function. + $str = "this is a `${version}` string" + $version = "versioned" + SafeReplaceString $str | Should -Be "this is a versioned string" + } + + It 'given CPU_ARCH var is present, it replaces version' { + # set the str before the $version env var so that we know it's being replaced in the function. + $str = "this is an `${CPU_ARCH}` string" + $CPU_ARCH = "architecture" + SafeReplaceString $str | Should -Be "this is an architecture string" + } + + It 'given BOBBY var is present, it replaces with empty string' { + # set the str before the $version env var so that we know it's being replaced in the function. + $str = "this is an `${BOBBY}` string" + $BOBBY = "architecture" + SafeReplaceString $str | Should -Be "this is an string" + } + +} + + + Describe 'GetWindowsDefenderInfo' { BeforeEach { $testString = '{ @@ -344,7 +374,7 @@ Describe 'Gets the Binaries' { "previousLatestVersion": "0.0.51" } ], - "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip" } } } @@ -385,7 +415,7 @@ Describe 'Gets the Binaries' { } ) $componentsJson.Packages[0].windowsDownloadLocation = "location" - $componentsJson.Packages[0].downloadUris.windows.default.downloadURL = "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + $componentsJson.Packages[0].downloadUris.windows.default.downloadURL = "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v`${version}.zip" $packages = GetPackagesFromComponentsJson $componentsJson @@ -403,7 +433,7 @@ Describe 'Gets the Binaries' { } ) $componentsJson.Packages[0].windowsDownloadLocation = "location" - $componentsJson.Packages[0].downloadUris.windows.default.downloadURL = "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + $componentsJson.Packages[0].downloadUris.windows.default.downloadURL = "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v`${version}.zip" $packages = GetPackagesFromComponentsJson $componentsJson @@ -418,7 +448,7 @@ Describe 'Gets the Binaries' { } ) $componentsJson.Packages[0].windowsDownloadLocation = "location" - $componentsJson.Packages[0].downloadUris.windows.default.downloadURL = "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + $componentsJson.Packages[0].downloadUris.windows.default.downloadURL = "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v`${version}.zip" $packages = GetPackagesFromComponentsJson $componentsJson @@ -439,7 +469,7 @@ Describe 'Gets the Binaries' { "latestVersion": "0.0.48" } ], - "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip" } } } @@ -455,7 +485,7 @@ Describe 'Gets the Binaries' { "latestVersion": "0.0.49" } ], - "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip" } } } @@ -484,7 +514,7 @@ Describe 'Gets the Binaries' { "latestVersion": "0.0.49" } ], - "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip" }, "default": { "versionsV2": [ @@ -493,7 +523,7 @@ Describe 'Gets the Binaries' { "latestVersion": "0.0.48" } ], - "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v[version].zip" + "downloadURL": "https://acs-mirror.azureedge.net/aks/windows/cse/aks-windows-cse-scripts-v${version}.zip" } } } @@ -522,6 +552,36 @@ Describe 'Gets The Versions' { $componentsJson = echo $testString | ConvertFrom-Json } + It 'replaces CPU_ARCH in the string' { + $componentsJson.ContainerImages[0].windowsVersions = @( + [PSCustomObject]@{ + latestVersion = "1.8.22" + } + ) + $componentsJson.ContainerImages[0].downloadURL = "mcr.microsoft.com/oss/kubernetes/autoscaler/`${CPU_ARCH}/addon-resizer:*" + + $CPU_ARCH="x86" + $components = GetComponentsFromComponentsJson $componentsJson + + $components | Should -HaveCount 1 + $components | Should -Contain "mcr.microsoft.com/oss/kubernetes/autoscaler/x86/addon-resizer:1.8.22" + } + + It 'does not replace varvarvar in the string' { + $componentsJson.ContainerImages[0].windowsVersions = @( + [PSCustomObject]@{ + latestVersion = "1.8.22" + } + ) + $componentsJson.ContainerImages[0].downloadURL = "mcr.microsoft.com/oss/kubernetes/autoscaler/`${varvarvar}/addon-resizer:*" + + $varvarvar="x86" + $components = GetComponentsFromComponentsJson $componentsJson + + $components | Should -HaveCount 1 + $components | Should -Contain "mcr.microsoft.com/oss/kubernetes/autoscaler//addon-resizer:1.8.22" + } + It 'given there are no container images, it returns an empty array' { $componentsJson.ContainerImages = @() diff --git a/vhdbuilder/packer/windows/windows-vhd-configuration.ps1 b/vhdbuilder/packer/windows/windows-vhd-configuration.ps1 index dfc9fd45924..2e5c2e42377 100644 --- a/vhdbuilder/packer/windows/windows-vhd-configuration.ps1 +++ b/vhdbuilder/packer/windows/windows-vhd-configuration.ps1 @@ -13,6 +13,27 @@ $global:aksToolsDir = "c:\aks-tools" # We need to guarantee that the node provisioning will not fail because the vhd is full before resize-osdisk is called in AKS Windows CSE script. $global:lowestFreeSpace = 1*1024*1024*1024 # 1GB +$cpu = Get-WmiObject -Class Win32_Processor +$CPU_ARCH = switch ($cpu.Architecture) { + 0 { "amd64" } # x86 + 1 { "" } # MIPS + 2 { "" } # Alpha + 3 { "" } # PowerPC + 5 { "arm64" } # ARM + 6 { "amd64" } # Itanium + 9 { "amd64" } # x64 + default { "" } +} + +Write-Output ($cpu | ConvertTo-Json) + +if ([string]::IsNullOrEmpty($CPU_ARCH)) { + $cpuName = $cpu.Name + $cpuArch = $cpu.Architecture + Write-Output "Unknown architecture for CPU $cpuName with arch $cpuArch" + throw "Unsupported architecture for SKU $windowsSKU for CPU $cpuName with arch $cpuArch" +} + $HelpersFile = "c:/k/components_json_helpers.ps1" $ComponentsJsonFile = "c:/k/components.json" $WindowsSettingsFile = "c:/k/windows_settings.json"