From 1d2fd571655b858106161870296183d7672cbf1e Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 21 Jun 2022 11:07:43 -0400 Subject: [PATCH 1/6] Support local addons path override in stress test deployment --- .../scripts/stress-testing/deploy-stress-tests.ps1 | 6 +++++- .../stress-testing/stress-test-deployment-lib.ps1 | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 index f4da78bd5225..bbfde2eba5e9 100644 --- a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 +++ b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 @@ -21,7 +21,11 @@ param( [switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID), # Optional namespace override, otherwise the shell user or chart annotation will be used - [string]$Namespace + [string]$Namespace, + + # Override remote stress-test-addons with local on-disk addons for development + [ValidateScript({ Test-Path $_ })] + [System.IO.FileInfo]$LocalAddonsPath ) . $PSScriptRoot/stress-test-deployment-lib.ps1 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 da91279fd63b..ae81b300aa9c 100644 --- a/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 +++ b/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 @@ -94,7 +94,17 @@ function DeployStressTests( Login -subscription $subscription -clusterGroup $clusterGroup -pushImages:$pushImages } - RunOrExitOnFailure helm repo add stress-test-charts https://stresstestcharts.blob.core.windows.net/helm/ + $chartRepoName = 'stress-test-charts' + if ($LocalAddonsPath) { + $absAddonsPath = Resolve-Path $LocalAddonsPath + if (!(helm plugin list | Select-String 'file')) { + helm plugin add (Join-Path $absAddonsPath file-plugin) + } + RunOrExitOnFailure helm repo add --force-update $chartRepoName file://$absAddonsPath + } else { + RunOrExitOnFailure helm repo add --force-update $chartRepoName https://stresstestcharts.blob.core.windows.net/helm/ + } + Run helm repo update if ($LASTEXITCODE) { return $LASTEXITCODE } From f94cefe381543df4fbd31e207bbcefca106f3c32 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 21 Jun 2022 11:56:48 -0400 Subject: [PATCH 2/6] Support username based deployId in local stress deployment --- .../stress-testing/deploy-stress-tests.ps1 | 1 - .../find-all-stress-packages.ps1 | 31 ++++++++++++------- .../stress-test-deployment-lib.ps1 | 18 ++++++++--- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 index bbfde2eba5e9..01920bdcbfe1 100644 --- a/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 +++ b/eng/common/scripts/stress-testing/deploy-stress-tests.ps1 @@ -24,7 +24,6 @@ param( [string]$Namespace, # Override remote stress-test-addons with local on-disk addons for development - [ValidateScript({ Test-Path $_ })] [System.IO.FileInfo]$LocalAddonsPath ) 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 3456cee68951..24705ead1d93 100644 --- a/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 +++ b/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 @@ -9,6 +9,7 @@ class StressTestPackageInfo { [string]$ReleaseName [string]$Dockerfile [string]$DockerBuildDir + [string]$Deployer } function FindStressPackages( @@ -50,6 +51,23 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) { return $true } +function GetUsername() { + # Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and + # we would like to avoid namespace overlaps for different codespaces users. + $stressUser = if ($env:GITHUB_USER) { + $env:GITHUB_USER + } elseif ($env:USER) { + $env:USER + } else { + $env:USERNAME + } + # Remove spaces, underscores, etc. that may be in $namespace. + # Value must be a valid RFC 1123 DNS label: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names + $stressUser = $stressUser -replace '_|\W', '-' + + return $stressUser.ToLower() +} + function NewStressTestPackageInfo( [hashtable]$chart, [System.IO.FileInfo]$chartFile, @@ -61,18 +79,7 @@ function NewStressTestPackageInfo( } elseif ($CI) { $chart.annotations.namespace } else { - # Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and - # we would like to avoid namespace overlaps for different codespaces users. - $namespace = if ($env:GITHUB_USER) { - $env:GITHUB_USER - } elseif ($env:USER) { - $env:USER - } else { - $env:USERNAME - } - # Remove spaces, underscores, etc. that may be in $namespace. Value must be a valid RFC 1123 DNS label: - # https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names - $namespace -replace '_|\W', '-' + GetUsername } return [StressTestPackageInfo]@{ 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 ae81b300aa9c..92dad4eeb2a8 100644 --- a/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 +++ b/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 @@ -67,11 +67,18 @@ function DeployStressTests( [string]$repository = '', [switch]$pushImages, [string]$clusterGroup = '', - [string]$deployId = 'local', + [string]$deployId = '', [switch]$login, [string]$subscription = '', [switch]$CI, - [string]$Namespace + [string]$Namespace, + [ValidateScript({ + if (!(Test-Path $_)) { + throw "LocalAddonsPath $LocalAddonsPath does not exist" + } + return $true + })] + [System.IO.FileInfo]$LocalAddonsPath ) { if ($environment -eq 'test') { if ($clusterGroup -or $subscription) { @@ -108,6 +115,7 @@ function DeployStressTests( Run helm repo update if ($LASTEXITCODE) { return $LASTEXITCODE } + $deployer = if ($deployId) { $deployId } else { GetUsername } $pkgs = FindStressPackages -directory $searchDirectory -filters $filters -CI:$CI -namespaceOverride $Namespace Write-Host "" "Found $($pkgs.Length) stress test packages:" Write-Host $pkgs.Directory "" @@ -115,15 +123,15 @@ function DeployStressTests( Write-Host "Deploying stress test at '$($pkg.Directory)'" DeployStressPackage ` -pkg $pkg ` - -deployId $deployId ` + -deployId $deployer ` -environment $environment ` -repositoryBase $repository ` -pushImages:$pushImages ` -login:$login } - Write-Host "Releases deployed by $deployId" - Run helm list --all-namespaces -l deployId=$deployId + Write-Host "Releases deployed by $deployer" + Run helm list --all-namespaces -l deployId=$deployer if ($FailedCommands) { Write-Warning "The following commands failed:" From b90cd3c89738af526420faf7d075146d877c7386 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Tue, 21 Jun 2022 13:01:56 -0400 Subject: [PATCH 3/6] Support WhatIf in stress infrastructure provision script --- eng/common/scripts/common.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/common/scripts/common.ps1 b/eng/common/scripts/common.ps1 index c472d180341c..73fe5b7d0393 100644 --- a/eng/common/scripts/common.ps1 +++ b/eng/common/scripts/common.ps1 @@ -54,4 +54,4 @@ $GetOnboardedDocsMsPackagesForMonikerFn = "Get-${Language}-OnboardedDocsMsPackag $GetDocsMsTocDataFn = "Get-${Language}-DocsMsTocData" $GetDocsMsTocChildrenForManagementPackagesFn = "Get-${Language}-DocsMsTocChildrenForManagementPackages" $UpdateDocsMsTocFn = "Get-${Language}-UpdatedDocsMsToc" -$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme" \ No newline at end of file +$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme" From 0afcfa5b2df3008705a1f47ce448b169684f741a Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Wed, 22 Jun 2022 19:14:28 -0400 Subject: [PATCH 4/6] Simplify stress user detection Co-authored-by: Wes Haggard --- .../scripts/stress-testing/find-all-stress-packages.ps1 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) 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 24705ead1d93..24c27da485f0 100644 --- a/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 +++ b/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 @@ -54,13 +54,7 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) { function GetUsername() { # Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and # we would like to avoid namespace overlaps for different codespaces users. - $stressUser = if ($env:GITHUB_USER) { - $env:GITHUB_USER - } elseif ($env:USER) { - $env:USER - } else { - $env:USERNAME - } + $stressUser = $env:GITHUB_USER ?? $env:USER ?? $env:USERNAME # Remove spaces, underscores, etc. that may be in $namespace. # Value must be a valid RFC 1123 DNS label: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names $stressUser = $stressUser -replace '_|\W', '-' From af6d6f483ba8d7bdd105d0050e5c067c8d062b02 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Wed, 22 Jun 2022 21:07:04 -0400 Subject: [PATCH 5/6] Run helm plugin add with helper --- .../scripts/stress-testing/stress-test-deployment-lib.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 92dad4eeb2a8..0b57f1fb9338 100644 --- a/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 +++ b/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 @@ -105,7 +105,7 @@ function DeployStressTests( if ($LocalAddonsPath) { $absAddonsPath = Resolve-Path $LocalAddonsPath if (!(helm plugin list | Select-String 'file')) { - helm plugin add (Join-Path $absAddonsPath file-plugin) + RunOrExitOnFailure helm plugin add (Join-Path $absAddonsPath file-plugin) } RunOrExitOnFailure helm repo add --force-update $chartRepoName file://$absAddonsPath } else { From 4f2416838ee91f4fb033c9780f48443afe2faad4 Mon Sep 17 00:00:00 2001 From: Ben Broderick Phillips Date: Thu, 23 Jun 2022 17:56:12 -0400 Subject: [PATCH 6/6] Add WhatIf support to ps module install helper function --- eng/common/scripts/Helpers/PSModule-Helpers.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/eng/common/scripts/Helpers/PSModule-Helpers.ps1 b/eng/common/scripts/Helpers/PSModule-Helpers.ps1 index 96f34ff71f4a..fae40d650e4f 100644 --- a/eng/common/scripts/Helpers/PSModule-Helpers.ps1 +++ b/eng/common/scripts/Helpers/PSModule-Helpers.ps1 @@ -48,8 +48,15 @@ function Update-PSModulePath() } # If we want to use another default repository other then PSGallery we can update the default parameters -function Install-ModuleIfNotInstalled($moduleName, $version, $repositoryUrl = $DefaultPSRepositoryUrl) +function Install-ModuleIfNotInstalled() { + [CmdletBinding(SupportsShouldProcess = $true)] + param( + [string]$moduleName, + [string]$version, + [string]$repositoryUrl = $DefaultPSRepositoryUrl + ) + # Check installed modules $modules = (Get-Module -ListAvailable $moduleName) if ($version -as [Version]) { @@ -94,4 +101,4 @@ function Install-ModuleIfNotInstalled($moduleName, $version, $repositoryUrl = $D return $modules[0] } -Update-PSModulePath \ No newline at end of file +Update-PSModulePath