diff --git a/eng/common/scripts/job-matrix/Create-JobMatrix.ps1 b/eng/common/scripts/job-matrix/Create-JobMatrix.ps1 index ea4923daa..fe98ca172 100644 --- a/eng/common/scripts/job-matrix/Create-JobMatrix.ps1 +++ b/eng/common/scripts/job-matrix/Create-JobMatrix.ps1 @@ -14,7 +14,8 @@ param ( [Parameter(Mandatory=$False)][string] $DisplayNameFilter, [Parameter(Mandatory=$False)][array] $Filters, [Parameter(Mandatory=$False)][array] $Replace, - [Parameter(Mandatory=$False)][array] $NonSparseParameters + [Parameter(Mandatory=$False)][array] $NonSparseParameters, + [Parameter()][switch] $CI = ($null -ne $env:SYSTEM_TEAMPROJECTID) ) . $PSScriptRoot/job-matrix-functions.ps1 @@ -39,6 +40,6 @@ $serialized = SerializePipelineMatrix $matrix Write-Output $serialized.pretty -if ($null -ne $env:SYSTEM_TEAMPROJECTID) { +if ($CI) { Write-Output "##vso[task.setVariable variable=matrix;isOutput=true]$($serialized.compressed)" -} \ No newline at end of file +} 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 673e64e73..491ce30d8 100644 --- a/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 +++ b/eng/common/scripts/stress-testing/find-all-stress-packages.ps1 @@ -30,32 +30,40 @@ function FindStressPackages( # Bare minimum filter for stress tests $filters['stressTest'] = 'true' $packages = @() - $chartFiles = Get-ChildItem -Recurse -Filter 'Chart.yaml' $directory + $chartFiles = Get-ChildItem -Recurse -Filter 'Chart.yaml' $directory + Write-Host "Found chart files:" + Write-Host ($chartFiles -join "`n") + if (!$MatrixFileName) { - $MatrixFileName = '/scenarios-matrix.yaml' + $MatrixFileName = 'scenarios-matrix.yaml' } + foreach ($chartFile in $chartFiles) { $chart = ParseChart $chartFile - - VerifyAddonsVersion $chart - if (matchesAnnotations $chart $filters) { - $matrixFilePath = (Join-Path $chartFile.Directory.FullName $MatrixFileName) - if (Test-Path $matrixFilePath) { - GenerateScenarioMatrix ` - -matrixFilePath $matrixFilePath ` - -Selection $MatrixSelection ` - -DisplayNameFilter $MatrixDisplayNameFilter ` - -Filters $MatrixFilters ` - -Replace $MatrixReplace ` - -NonSparseParameters $MatrixNonSparseParameters - } - $packages += NewStressTestPackageInfo ` - -chart $chart ` - -chartFile $chartFile ` - -CI:$CI ` - -namespaceOverride $namespaceOverride + if (!(matchesAnnotations $chart $filters)) { + Write-Host "Skipping chart file '$chartFile'" + continue } + + VerifyAddonsVersion $chart $chartFile + + $matrixFilePath = (Join-Path $chartFile.Directory.FullName $MatrixFileName) + if (Test-Path $matrixFilePath) { + GenerateScenarioMatrix ` + -matrixFilePath $matrixFilePath ` + -Selection $MatrixSelection ` + -DisplayNameFilter $MatrixDisplayNameFilter ` + -Filters $MatrixFilters ` + -Replace $MatrixReplace ` + -NonSparseParameters $MatrixNonSparseParameters + } + + $packages += NewStressTestPackageInfo ` + -chart $chart ` + -chartFile $chartFile ` + -CI:$CI ` + -namespaceOverride $namespaceOverride } return $packages @@ -67,7 +75,7 @@ function ParseChart([string]$chartFile) { function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) { foreach ($filter in $filters.GetEnumerator()) { - if (!$chart.annotations -or $chart.annotations[$filter.Key] -ne $filter.Value) { + if (!$chart["annotations"] -or $chart["annotations"][$filter.Key] -ne $filter.Value) { return $false } } @@ -75,11 +83,11 @@ function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) { return $true } -function VerifyAddonsVersion([hashtable]$chart) { +function VerifyAddonsVersion([hashtable]$chart, [string]$chartFile) { foreach ($dependency in $chart.dependencies) { if ($dependency.name -eq "stress-test-addons" -and $dependency.version -lt "0.2.0") { - throw "The stress-test-addons version in use is $($dependency.version), please use versions >= 0.2.0" + throw "The stress-test-addons version in use for '$chartFile' is $($dependency.version), please use versions >= 0.2.0" } } } diff --git a/eng/common/scripts/stress-testing/generate-scenario-matrix.ps1 b/eng/common/scripts/stress-testing/generate-scenario-matrix.ps1 index 1ddb05cd0..d0f23f486 100644 --- a/eng/common/scripts/stress-testing/generate-scenario-matrix.ps1 +++ b/eng/common/scripts/stress-testing/generate-scenario-matrix.ps1 @@ -7,9 +7,11 @@ param( [Parameter(Mandatory=$False)][array]$NonSparseParameters ) +$ErrorActionPreference = 'Stop' + function GenerateScenarioMatrix( - [string]$matrixFilePath, - [string]$Selection, + [Parameter(Mandatory=$True)][string]$matrixFilePath, + [Parameter(Mandatory=$True)][string]$Selection, [Parameter(Mandatory=$False)][string]$DisplayNameFilter, [Parameter(Mandatory=$False)][array]$Filters, [Parameter(Mandatory=$False)][array]$Replace, @@ -23,12 +25,17 @@ function GenerateScenarioMatrix( -DisplayNameFilter $DisplayNameFilter ` -Filters $Filters ` -Replace $Replace ` - -NonSparseParameters $NonSparseParameters + -NonSparseParameters $NonSparseParameters ` + -CI:$False + + Write-Host "==================================================" + Write-Host "Generated matrix for $matrixFilePath" Write-Host $prettyMatrix - $prettyMatrix = $prettyMatrix | ConvertFrom-Json + Write-Host "==================================================" + $matrixObj = $prettyMatrix | ConvertFrom-Json $scenariosMatrix = @() - foreach($permutation in $prettyMatrix.psobject.properties) { + foreach($permutation in $matrixObj.psobject.properties) { $entry = @{} $entry.Name = $permutation.Name -replace '_', '-' $entry.Scenario = $entry.Name @@ -46,13 +53,14 @@ function GenerateScenarioMatrix( $values = $valuesYaml | ConvertFrom-Yaml -Ordered if (!$values) {$values = @{}} - if ($values.ContainsKey('Scenarios')) { - throw "Please use matrix generation for stress test scenarios." + if ($values.Contains('Scenarios')) { + throw "Please remove the 'Scenarios' key from $valuesConfig as it is deprecated." } } $values.scenarios = $scenariosMatrix - $values | ConvertTo-Yaml | Out-File -FilePath (Join-Path $matrixFilePath '../generatedValues.yaml') + $generatedValues = Join-Path (Split-Path $matrixFilePath) 'generatedValues.yaml' + $values | ConvertTo-Yaml | Out-File -FilePath $generatedValues } function NewStressTestPackageInfo( 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 0365bbb30..e6f9ee191 100644 --- a/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 +++ b/eng/common/scripts/stress-testing/stress-test-deployment-lib.ps1 @@ -40,8 +40,12 @@ function Login([string]$subscription, [string]$clusterGroup, [switch]$pushImages $cluster = RunOrExitOnFailure az aks list -g $clusterGroup --subscription $subscription -o json $clusterName = ($cluster | ConvertFrom-Json).name - $kubeContext = (RunOrExitOnFailure kubectl config view -o json) | ConvertFrom-Json - $defaultNamespace = $kubeContext.contexts.Where({ $_.name -eq $clusterName }).context.namespace + $kubeContext = (RunOrExitOnFailure kubectl config view -o json) | ConvertFrom-Json -AsHashtable + $defaultNamespace = $null + $targetContext = $kubeContext.contexts.Where({ $_.name -eq $clusterName }) | Select -First 1 + if ($targetContext -ne $null) { + $defaultNamespace = $targetContext.context.namespace + } RunOrExitOnFailure az aks get-credentials ` -n "$clusterName" ` @@ -201,6 +205,9 @@ function DeployStressPackage( $dockerFilePath = "$($pkg.Directory)/Dockerfile" } $dockerFilePath = [System.IO.Path]::GetFullPath($dockerFilePath).Trim() + if (!(Test-Path $dockerFilePath)) { + continue + } if ("imageBuildDir" -in $scenario.keys) { $dockerBuildDir = Join-Path $pkg.Directory $scenario.imageBuildDir @@ -212,7 +219,7 @@ function DeployStressPackage( } } if ($pkg.Dockerfile -or $pkg.DockerBuildDir) { - throw "The chart.yaml docker config is depracated, please use the scenarios matrix instead." + throw "The chart.yaml docker config is deprecated, please use the scenarios matrix instead." } @@ -249,9 +256,10 @@ function DeployStressPackage( } } $genVal.scenarios = @( foreach ($scenario in $genVal.scenarios) { - $dockerPath = Join-Path $pkg.Directory $scenario.image - if ("image" -notin $scenario) { - $dockerPath = $dockerFilePath + $dockerPath = if ("image" -notin $scenario) { + $dockerFilePath + } else { + Join-Path $pkg.Directory $scenario.image } if ([System.IO.Path]::GetFullPath($dockerPath) -eq $dockerFilePath) { $scenario.imageTag = $imageTag @@ -267,7 +275,7 @@ function DeployStressPackage( -n $pkg.Namespace ` --install ` --set stress-test-addons.env=$environment ` - --values generatedValues.yaml + --values (Join-Path $pkg.Directory generatedValues.yaml) if ($LASTEXITCODE) { # Issues like 'UPGRADE FAILED: another operation (install/upgrade/rollback) is in progress' # can be the result of cancelled `upgrade` operations (e.g. ctrl-c).