Skip to content

Commit 7efa7c9

Browse files
azure-sdkbenbpweshaggard
authored
Sync eng/common directory with azure-sdk-tools for PR 3481 (Azure#18471)
* Support local addons path override in stress test deployment * Support username based deployId in local stress deployment * Support WhatIf in stress infrastructure provision script * Simplify stress user detection Co-authored-by: Wes Haggard <[email protected]> * Run helm plugin add with helper * Add WhatIf support to ps module install helper function Co-authored-by: Ben Broderick Phillips <[email protected]> Co-authored-by: Wes Haggard <[email protected]>
1 parent f29fa9a commit 7efa7c9

File tree

5 files changed

+51
-22
lines changed

5 files changed

+51
-22
lines changed

eng/common/scripts/Helpers/PSModule-Helpers.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ function Update-PSModulePath()
4848
}
4949

5050
# If we want to use another default repository other then PSGallery we can update the default parameters
51-
function Install-ModuleIfNotInstalled($moduleName, $version, $repositoryUrl = $DefaultPSRepositoryUrl)
51+
function Install-ModuleIfNotInstalled()
5252
{
53+
[CmdletBinding(SupportsShouldProcess = $true)]
54+
param(
55+
[string]$moduleName,
56+
[string]$version,
57+
[string]$repositoryUrl = $DefaultPSRepositoryUrl
58+
)
59+
5360
# Check installed modules
5461
$modules = (Get-Module -ListAvailable $moduleName)
5562
if ($version -as [Version]) {
@@ -94,4 +101,4 @@ function Install-ModuleIfNotInstalled($moduleName, $version, $repositoryUrl = $D
94101
return $modules[0]
95102
}
96103

97-
Update-PSModulePath
104+
Update-PSModulePath

eng/common/scripts/common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ $GetOnboardedDocsMsPackagesForMonikerFn = "Get-${Language}-OnboardedDocsMsPackag
5454
$GetDocsMsTocDataFn = "Get-${Language}-DocsMsTocData"
5555
$GetDocsMsTocChildrenForManagementPackagesFn = "Get-${Language}-DocsMsTocChildrenForManagementPackages"
5656
$UpdateDocsMsTocFn = "Get-${Language}-UpdatedDocsMsToc"
57-
$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme"
57+
$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme"

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ param(
2121
[switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID),
2222

2323
# Optional namespace override, otherwise the shell user or chart annotation will be used
24-
[string]$Namespace
24+
[string]$Namespace,
25+
26+
# Override remote stress-test-addons with local on-disk addons for development
27+
[System.IO.FileInfo]$LocalAddonsPath
2528
)
2629

2730
. $PSScriptRoot/stress-test-deployment-lib.ps1

eng/common/scripts/stress-testing/find-all-stress-packages.ps1

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class StressTestPackageInfo {
99
[string]$ReleaseName
1010
[string]$Dockerfile
1111
[string]$DockerBuildDir
12+
[string]$Deployer
1213
}
1314

1415
function FindStressPackages(
@@ -50,6 +51,17 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) {
5051
return $true
5152
}
5253

54+
function GetUsername() {
55+
# Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and
56+
# we would like to avoid namespace overlaps for different codespaces users.
57+
$stressUser = $env:GITHUB_USER ?? $env:USER ?? $env:USERNAME
58+
# Remove spaces, underscores, etc. that may be in $namespace.
59+
# Value must be a valid RFC 1123 DNS label: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
60+
$stressUser = $stressUser -replace '_|\W', '-'
61+
62+
return $stressUser.ToLower()
63+
}
64+
5365
function NewStressTestPackageInfo(
5466
[hashtable]$chart,
5567
[System.IO.FileInfo]$chartFile,
@@ -61,18 +73,7 @@ function NewStressTestPackageInfo(
6173
} elseif ($CI) {
6274
$chart.annotations.namespace
6375
} else {
64-
# Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and
65-
# we would like to avoid namespace overlaps for different codespaces users.
66-
$namespace = if ($env:GITHUB_USER) {
67-
$env:GITHUB_USER
68-
} elseif ($env:USER) {
69-
$env:USER
70-
} else {
71-
$env:USERNAME
72-
}
73-
# Remove spaces, underscores, etc. that may be in $namespace. Value must be a valid RFC 1123 DNS label:
74-
# https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
75-
$namespace -replace '_|\W', '-'
76+
GetUsername
7677
}
7778

7879
return [StressTestPackageInfo]@{

eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,18 @@ function DeployStressTests(
6767
[string]$repository = '',
6868
[switch]$pushImages,
6969
[string]$clusterGroup = '',
70-
[string]$deployId = 'local',
70+
[string]$deployId = '',
7171
[switch]$login,
7272
[string]$subscription = '',
7373
[switch]$CI,
74-
[string]$Namespace
74+
[string]$Namespace,
75+
[ValidateScript({
76+
if (!(Test-Path $_)) {
77+
throw "LocalAddonsPath $LocalAddonsPath does not exist"
78+
}
79+
return $true
80+
})]
81+
[System.IO.FileInfo]$LocalAddonsPath
7582
) {
7683
if ($environment -eq 'test') {
7784
if ($clusterGroup -or $subscription) {
@@ -94,26 +101,37 @@ function DeployStressTests(
94101
Login -subscription $subscription -clusterGroup $clusterGroup -pushImages:$pushImages
95102
}
96103

97-
RunOrExitOnFailure helm repo add stress-test-charts https://stresstestcharts.blob.core.windows.net/helm/
104+
$chartRepoName = 'stress-test-charts'
105+
if ($LocalAddonsPath) {
106+
$absAddonsPath = Resolve-Path $LocalAddonsPath
107+
if (!(helm plugin list | Select-String 'file')) {
108+
RunOrExitOnFailure helm plugin add (Join-Path $absAddonsPath file-plugin)
109+
}
110+
RunOrExitOnFailure helm repo add --force-update $chartRepoName file://$absAddonsPath
111+
} else {
112+
RunOrExitOnFailure helm repo add --force-update $chartRepoName https://stresstestcharts.blob.core.windows.net/helm/
113+
}
114+
98115
Run helm repo update
99116
if ($LASTEXITCODE) { return $LASTEXITCODE }
100117

118+
$deployer = if ($deployId) { $deployId } else { GetUsername }
101119
$pkgs = FindStressPackages -directory $searchDirectory -filters $filters -CI:$CI -namespaceOverride $Namespace
102120
Write-Host "" "Found $($pkgs.Length) stress test packages:"
103121
Write-Host $pkgs.Directory ""
104122
foreach ($pkg in $pkgs) {
105123
Write-Host "Deploying stress test at '$($pkg.Directory)'"
106124
DeployStressPackage `
107125
-pkg $pkg `
108-
-deployId $deployId `
126+
-deployId $deployer `
109127
-environment $environment `
110128
-repositoryBase $repository `
111129
-pushImages:$pushImages `
112130
-login:$login
113131
}
114132

115-
Write-Host "Releases deployed by $deployId"
116-
Run helm list --all-namespaces -l deployId=$deployId
133+
Write-Host "Releases deployed by $deployer"
134+
Run helm list --all-namespaces -l deployId=$deployer
117135

118136
if ($FailedCommands) {
119137
Write-Warning "The following commands failed:"

0 commit comments

Comments
 (0)