From 3fc8cc0530c8e0fc1a094587817fcb595a5030f8 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Wed, 9 Mar 2022 14:09:00 -0800 Subject: [PATCH] Support namespace override for local stress test deployments (#3416) Co-authored-by: Ben Broderick Phillips --- .../stress-testing/deploy-stress-tests.ps1 | 5 +++- .../find-all-stress-packages.ps1 | 24 +++++++++++++++---- .../stress-test-deployment-lib.ps1 | 5 ++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 index 2a6b53d06..f4da78bd5 100644 --- a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 +++ b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 @@ -18,7 +18,10 @@ param( [string]$Subscription, # Default to true in Azure Pipelines environments - [switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID) + [switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID), + + # Optional namespace override, otherwise the shell user or chart annotation will be used + [string]$Namespace ) . $PSScriptRoot/stress-test-deployment-lib.ps1 diff --git a/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 b/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 index bda7da1a6..3456cee68 100644 --- a/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 +++ b/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 @@ -11,7 +11,12 @@ class StressTestPackageInfo { [string]$DockerBuildDir } -function FindStressPackages([string]$directory, [hashtable]$filters = @{}, [switch]$CI) { +function FindStressPackages( + [string]$directory, + [hashtable]$filters = @{}, + [switch]$CI, + [string]$namespaceOverride +) { # Bare minimum filter for stress tests $filters['stressTest'] = 'true' @@ -20,7 +25,11 @@ function FindStressPackages([string]$directory, [hashtable]$filters = @{}, [swit foreach ($chartFile in $chartFiles) { $chart = ParseChart $chartFile if (matchesAnnotations $chart $filters) { - $packages += NewStressTestPackageInfo -chart $chart -chartFile $chartFile -CI:$CI + $packages += NewStressTestPackageInfo ` + -chart $chart ` + -chartFile $chartFile ` + -CI:$CI ` + -namespaceOverride $namespaceOverride } } @@ -41,8 +50,15 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) { return $true } -function NewStressTestPackageInfo([hashtable]$chart, [System.IO.FileInfo]$chartFile, [switch]$CI) { - $namespace = if ($CI) { +function NewStressTestPackageInfo( + [hashtable]$chart, + [System.IO.FileInfo]$chartFile, + [switch]$CI, + [object]$namespaceOverride +) { + $namespace = if ($namespaceOverride) { + $namespaceOverride + } elseif ($CI) { $chart.annotations.namespace } else { # Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and diff --git a/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 b/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 index c1d875dbd..da91279fd 100644 --- a/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 +++ b/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 @@ -70,7 +70,8 @@ function DeployStressTests( [string]$deployId = 'local', [switch]$login, [string]$subscription = '', - [switch]$CI + [switch]$CI, + [string]$Namespace ) { if ($environment -eq 'test') { if ($clusterGroup -or $subscription) { @@ -97,7 +98,7 @@ function DeployStressTests( Run helm repo update if ($LASTEXITCODE) { return $LASTEXITCODE } - $pkgs = FindStressPackages -directory $searchDirectory -filters $filters -CI:$CI + $pkgs = FindStressPackages -directory $searchDirectory -filters $filters -CI:$CI -namespaceOverride $Namespace Write-Host "" "Found $($pkgs.Length) stress test packages:" Write-Host $pkgs.Directory "" foreach ($pkg in $pkgs) {