Skip to content

Commit 96190dd

Browse files
azure-sdkbenbp
andauthored
Sync eng/common directory with azure-sdk-tools for PR 1918 (Azure#23655)
* Stress test deployment script resiliency fixes * Use PSModule-Helpers to install powershell-yaml Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent 92ab3ab commit 96190dd

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

eng/common/scripts/stress-testing/deploy-stress-tests.ps1

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ $ErrorActionPreference = 'Stop'
2020
. $PSScriptRoot/find-all-stress-packages.ps1
2121
$FailedCommands = New-Object Collections.Generic.List[hashtable]
2222

23-
if (!(Get-Module powershell-yaml)) {
24-
Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser
25-
}
23+
. (Join-Path $PSScriptRoot "../Helpers" PSModule-Helpers.ps1)
24+
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
2625

2726
# Powershell does not (at time of writing) treat exit codes from external binaries
2827
# as cause for stopping execution, so do this via a wrapper function.
@@ -51,7 +50,10 @@ function Login([string]$subscription, [string]$clusterGroup, [boolean]$pushImage
5150
RunOrExitOnFailure az login --allow-no-subscriptions
5251
}
5352

54-
$clusterName = (az aks list -g $clusterGroup -o json| ConvertFrom-Json).name
53+
# Discover cluster name, only one cluster per group is expected
54+
Write-Host "Listing AKS cluster in $subscription/$clusterGroup"
55+
$cluster = RunOrExitOnFailure az aks list -g $clusterGroup --subscription $subscription -o json
56+
$clusterName = ($cluster | ConvertFrom-Json).name
5557

5658
RunOrExitOnFailure az aks get-credentials `
5759
-n "$clusterName" `
@@ -60,8 +62,9 @@ function Login([string]$subscription, [string]$clusterGroup, [boolean]$pushImage
6062
--overwrite-existing
6163

6264
if ($pushImages) {
63-
$registry = (az acr list -g $clusterGroup -o json | ConvertFrom-Json).name
64-
RunOrExitOnFailure az acr login -n $registry
65+
$registry = RunOrExitOnFailure az acr list -g $clusterGroup --subscription $subscription -o json
66+
$registryName = ($registry | ConvertFrom-Json).name
67+
RunOrExitOnFailure az acr login -n $registryName
6568
}
6669
}
6770

@@ -110,11 +113,8 @@ function DeployStressPackage(
110113
[string]$repository,
111114
[boolean]$pushImages
112115
) {
113-
$registry = (az acr list -g $clusterGroup -o json | ConvertFrom-Json).name
114-
if (!$registry) {
115-
Write-Host "Could not find container registry in resource group $clusterGroup"
116-
exit 1
117-
}
116+
$registry = RunOrExitOnFailure az acr list -g $clusterGroup --subscription $subscription -o json
117+
$registryName = ($registry | ConvertFrom-Json).name
118118

119119
Run helm dependency update $pkg.Directory
120120
if ($LASTEXITCODE) { return }
@@ -133,7 +133,7 @@ function DeployStressPackage(
133133
if (!$imageName) {
134134
$imageName = $dockerFile.Directory.Name
135135
}
136-
$imageTag = "${registry}.azurecr.io/$($repository.ToLower())/$($imageName):$deployId"
136+
$imageTag = "${registryName}.azurecr.io/$($repository.ToLower())/$($imageName):$deployId"
137137
Write-Host "Building and pushing stress test docker image '$imageTag'"
138138
Run docker build -t $imageTag -f $dockerFile.FullName $dockerFile.DirectoryName
139139
if ($LASTEXITCODE) { return }
@@ -154,7 +154,7 @@ function DeployStressPackage(
154154
Run helm upgrade $pkg.ReleaseName $pkg.Directory `
155155
-n $pkg.Namespace `
156156
--install `
157-
--set repository=$registry.azurecr.io/$repository `
157+
--set repository=$registryName.azurecr.io/$repository `
158158
--set tag=$deployId `
159159
--set stress-test-addons.env=$environment
160160
if ($LASTEXITCODE) {
@@ -176,4 +176,7 @@ function DeployStressPackage(
176176
Run kubectl label secret -n $pkg.Namespace --overwrite $helmReleaseConfig deployId=$deployId
177177
}
178178

179-
DeployStressTests @PSBoundParameters
179+
# Don't call functions when the script is being dot sourced
180+
if ($MyInvocation.InvocationName -ne ".") {
181+
DeployStressTests @PSBoundParameters
182+
}

0 commit comments

Comments
 (0)