Sync eng/common directory with azure-sdk-tools for PR 3481 (#3764)
* 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 <weshaggard@users.noreply.github.com> * Run helm plugin add with helper * Add WhatIf support to ps module install helper function Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com> Co-authored-by: Wes Haggard <weshaggard@users.noreply.github.com>
This commit is contained in:
parent
e3dd52a649
commit
98d4502d3a
@ -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
|
||||
Update-PSModulePath
|
||||
|
||||
@ -54,4 +54,4 @@ $GetOnboardedDocsMsPackagesForMonikerFn = "Get-${Language}-OnboardedDocsMsPackag
|
||||
$GetDocsMsTocDataFn = "Get-${Language}-DocsMsTocData"
|
||||
$GetDocsMsTocChildrenForManagementPackagesFn = "Get-${Language}-DocsMsTocChildrenForManagementPackages"
|
||||
$UpdateDocsMsTocFn = "Get-${Language}-UpdatedDocsMsToc"
|
||||
$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme"
|
||||
$GetPackageLevelReadmeFn = "Get-${Language}-PackageLevelReadme"
|
||||
|
||||
@ -21,7 +21,10 @@ 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
|
||||
[System.IO.FileInfo]$LocalAddonsPath
|
||||
)
|
||||
|
||||
. $PSScriptRoot/stress-test-deployment-lib.ps1
|
||||
|
||||
@ -9,6 +9,7 @@ class StressTestPackageInfo {
|
||||
[string]$ReleaseName
|
||||
[string]$Dockerfile
|
||||
[string]$DockerBuildDir
|
||||
[string]$Deployer
|
||||
}
|
||||
|
||||
function FindStressPackages(
|
||||
@ -50,6 +51,17 @@ 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 = $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', '-'
|
||||
|
||||
return $stressUser.ToLower()
|
||||
}
|
||||
|
||||
function NewStressTestPackageInfo(
|
||||
[hashtable]$chart,
|
||||
[System.IO.FileInfo]$chartFile,
|
||||
@ -61,18 +73,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]@{
|
||||
|
||||
@ -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) {
|
||||
@ -94,10 +101,21 @@ 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')) {
|
||||
RunOrExitOnFailure 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 }
|
||||
|
||||
$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 ""
|
||||
@ -105,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:"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user