|
| 1 | +param( |
| 2 | + [string]$matrixFilePath, |
| 3 | + [string]$Selection, |
| 4 | + [Parameter(Mandatory=$False)][string]$DisplayNameFilter, |
| 5 | + [Parameter(Mandatory=$False)][array]$Filters, |
| 6 | + [Parameter(Mandatory=$False)][array]$Replace, |
| 7 | + [Parameter(Mandatory=$False)][array]$NonSparseParameters |
| 8 | +) |
| 9 | + |
| 10 | +function GenerateScenarioMatrix( |
| 11 | + [string]$matrixFilePath, |
| 12 | + [string]$Selection, |
| 13 | + [Parameter(Mandatory=$False)][string]$DisplayNameFilter, |
| 14 | + [Parameter(Mandatory=$False)][array]$Filters, |
| 15 | + [Parameter(Mandatory=$False)][array]$Replace, |
| 16 | + [Parameter(Mandatory=$False)][array]$NonSparseParameters |
| 17 | +) { |
| 18 | + $yamlConfig = Get-Content $matrixFilePath -Raw |
| 19 | + |
| 20 | + $prettyMatrix = &"$PSScriptRoot/../job-matrix/Create-JobMatrix.ps1" ` |
| 21 | + -ConfigPath $matrixFilePath ` |
| 22 | + -Selection $Selection ` |
| 23 | + -DisplayNameFilter $DisplayNameFilter ` |
| 24 | + -Filters $Filters ` |
| 25 | + -Replace $Replace ` |
| 26 | + -NonSparseParameters $NonSparseParameters |
| 27 | + Write-Host $prettyMatrix |
| 28 | + $prettyMatrix = $prettyMatrix | ConvertFrom-Json |
| 29 | + |
| 30 | + $scenariosMatrix = @() |
| 31 | + foreach($permutation in $prettyMatrix.psobject.properties) { |
| 32 | + $entry = @{} |
| 33 | + $entry.Name = $permutation.Name -replace '_', '-' |
| 34 | + $entry.Scenario = $entry.Name |
| 35 | + $entry.Remove("Name") |
| 36 | + foreach ($param in $permutation.value.psobject.properties) { |
| 37 | + $entry.add($param.Name, $param.value) |
| 38 | + } |
| 39 | + $scenariosMatrix += $entry |
| 40 | + } |
| 41 | + |
| 42 | + $valuesYaml = Get-Content -Raw (Join-Path (Split-Path $matrixFilePath) 'values.yaml') |
| 43 | + $values = $valuesYaml | ConvertFrom-Yaml -Ordered |
| 44 | + if (!$values) {$values = @{}} |
| 45 | + |
| 46 | + if ($values.ContainsKey('Scenarios')) { |
| 47 | + throw "Please use matrix generation for stress test scenarios." |
| 48 | + } |
| 49 | + |
| 50 | + $values.scenarios = $scenariosMatrix |
| 51 | + $values | ConvertTo-Yaml | Out-File -FilePath (Join-Path $matrixFilePath '../generatedValues.yaml') |
| 52 | +} |
| 53 | + |
| 54 | +function NewStressTestPackageInfo( |
| 55 | + [hashtable]$chart, |
| 56 | + [System.IO.FileInfo]$chartFile, |
| 57 | + [switch]$CI, |
| 58 | + [object]$namespaceOverride |
| 59 | +) { |
| 60 | + $namespace = if ($namespaceOverride) { |
| 61 | + $namespaceOverride |
| 62 | + } elseif ($CI) { |
| 63 | + $chart.annotations.namespace |
| 64 | + } else { |
| 65 | + GetUsername |
| 66 | + } |
| 67 | + |
| 68 | + return [StressTestPackageInfo]@{ |
| 69 | + Namespace = $namespace.ToLower() |
| 70 | + Directory = $chartFile.DirectoryName |
| 71 | + ReleaseName = $chart.name |
| 72 | + Dockerfile = $chart.annotations.dockerfile |
| 73 | + DockerBuildDir = $chart.annotations.dockerbuilddir |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +# Don't call functions when the script is being dot sourced |
| 78 | +if ($MyInvocation.InvocationName -ne ".") { |
| 79 | + GenerateScenarioMatrix ` |
| 80 | + -matrixFilePath $matrixFilePath ` |
| 81 | + -Selection $Selection ` |
| 82 | + -DisplayNameFilter $DisplayNameFilter ` |
| 83 | + -Filters $Filters ` |
| 84 | + -Replace $Replace ` |
| 85 | + -NonSparseParameters $NonSparseParameters |
| 86 | +} |
0 commit comments