From 7e3e4bce1a2a063d8e75c22570b55ad1046d9ffa Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 17 Aug 2021 17:48:59 -0400 Subject: [PATCH 1/2] Stress test deployment script resiliency fixes --- .../stress-testing/deploy-stress-tests.ps1 | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 index 25af8c9edd72..d34e3cba6e16 100644 --- a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 +++ b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 @@ -20,7 +20,8 @@ $ErrorActionPreference = 'Stop' . $PSScriptRoot/find-all-stress-packages.ps1 $FailedCommands = New-Object Collections.Generic.List[hashtable] -if (!(Get-Module powershell-yaml)) { +if (!(Get-Module -ListAvailable powershell-yaml)) { + Write-Host "Installing powershell-yaml module..." Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser } @@ -51,7 +52,10 @@ function Login([string]$subscription, [string]$clusterGroup, [boolean]$pushImage RunOrExitOnFailure az login --allow-no-subscriptions } - $clusterName = (az aks list -g $clusterGroup -o json| ConvertFrom-Json).name + # Discover cluster name, only one cluster per group is expected + Write-Host "Listing AKS cluster in $subscription/$clusterGroup" + $cluster = RunOrExitOnFailure az aks list -g $clusterGroup --subscription $subscription -o json + $clusterName = ($cluster | ConvertFrom-Json).name RunOrExitOnFailure az aks get-credentials ` -n "$clusterName" ` @@ -60,8 +64,9 @@ function Login([string]$subscription, [string]$clusterGroup, [boolean]$pushImage --overwrite-existing if ($pushImages) { - $registry = (az acr list -g $clusterGroup -o json | ConvertFrom-Json).name - RunOrExitOnFailure az acr login -n $registry + $registry = RunOrExitOnFailure az acr list -g $clusterGroup --subscription $subscription -o json + $registryName = ($registry | ConvertFrom-Json).name + RunOrExitOnFailure az acr login -n $registryName } } @@ -110,11 +115,8 @@ function DeployStressPackage( [string]$repository, [boolean]$pushImages ) { - $registry = (az acr list -g $clusterGroup -o json | ConvertFrom-Json).name - if (!$registry) { - Write-Host "Could not find container registry in resource group $clusterGroup" - exit 1 - } + $registry = RunOrExitOnFailure az acr list -g $clusterGroup --subscription $subscription -o json + $registryName = ($registry | ConvertFrom-Json).name Run helm dependency update $pkg.Directory if ($LASTEXITCODE) { return } @@ -133,7 +135,7 @@ function DeployStressPackage( if (!$imageName) { $imageName = $dockerFile.Directory.Name } - $imageTag = "${registry}.azurecr.io/$($repository.ToLower())/$($imageName):$deployId" + $imageTag = "${registryName}.azurecr.io/$($repository.ToLower())/$($imageName):$deployId" Write-Host "Building and pushing stress test docker image '$imageTag'" Run docker build -t $imageTag -f $dockerFile.FullName $dockerFile.DirectoryName if ($LASTEXITCODE) { return } @@ -154,7 +156,7 @@ function DeployStressPackage( Run helm upgrade $pkg.ReleaseName $pkg.Directory ` -n $pkg.Namespace ` --install ` - --set repository=$registry.azurecr.io/$repository ` + --set repository=$registryName.azurecr.io/$repository ` --set tag=$deployId ` --set stress-test-addons.env=$environment if ($LASTEXITCODE) { @@ -176,4 +178,7 @@ function DeployStressPackage( Run kubectl label secret -n $pkg.Namespace --overwrite $helmReleaseConfig deployId=$deployId } -DeployStressTests @PSBoundParameters +# Don't call functions when the script is being dot sourced +if ($MyInvocation.InvocationName -ne ".") { + DeployStressTests @PSBoundParameters +} From 9218cec5c3b140ad6500450f1ff1c1866ba8adb3 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Wed, 18 Aug 2021 14:14:43 -0400 Subject: [PATCH 2/2] Use PSModule-Helpers to install powershell-yaml --- eng/common/scripts/stress-testing/deploy-stress-tests.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 index d34e3cba6e16..a95ce62ff02b 100644 --- a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 +++ b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 @@ -20,10 +20,8 @@ $ErrorActionPreference = 'Stop' . $PSScriptRoot/find-all-stress-packages.ps1 $FailedCommands = New-Object Collections.Generic.List[hashtable] -if (!(Get-Module -ListAvailable powershell-yaml)) { - Write-Host "Installing powershell-yaml module..." - Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser -} +. (Join-Path $PSScriptRoot "../Helpers" PSModule-Helpers.ps1) +Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module # Powershell does not (at time of writing) treat exit codes from external binaries # as cause for stopping execution, so do this via a wrapper function.