-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathfind-all-stress-packages.ps1
More file actions
133 lines (114 loc) · 4.31 KB
/
find-all-stress-packages.ps1
File metadata and controls
133 lines (114 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
param(
[string]$searchDirectory = '.',
[hashtable]$filters = @{}
)
class StressTestPackageInfo {
[string]$Namespace
[string]$Directory
[string]$ReleaseName
[string]$Dockerfile
[string]$DockerBuildDir
[string]$Deployer
}
. $PSScriptRoot/../job-matrix/job-matrix-functions.ps1
. $PSScriptRoot/generate-scenario-matrix.ps1
function FindStressPackages(
[string]$directory,
[hashtable]$filters = @{},
[switch]$CI,
[string]$namespaceOverride,
[string]$MatrixSelection,
[Parameter(Mandatory=$False)][string]$MatrixFileName,
[Parameter(Mandatory=$False)][string]$MatrixDisplayNameFilter,
[Parameter(Mandatory=$False)][array]$MatrixFilters,
[Parameter(Mandatory=$False)][array]$MatrixReplace,
[Parameter(Mandatory=$False)][array]$MatrixNonSparseParameters
) {
# Bare minimum filter for stress tests
$filters['stressTest'] = 'true'
$packages = @()
$chartFiles = Get-ChildItem -Recurse -Filter 'Chart.yaml' $directory
Write-Host "Found chart files:"
Write-Host ($chartFiles -join "`n")
if (!$MatrixFileName) {
$MatrixFileName = 'scenarios-matrix.yaml'
}
foreach ($chartFile in $chartFiles) {
$chart = ParseChart $chartFile
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
}
function ParseChart([string]$chartFile) {
return ConvertFrom-Yaml (Get-Content -Raw $chartFile)
}
function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) {
foreach ($filter in $filters.GetEnumerator()) {
if (!$chart["annotations"] -or $chart["annotations"][$filter.Key] -notmatch $filter.Value) {
return $false
}
}
return $true
}
function VerifyAddonsVersion([hashtable]$chart, [string]$chartFile) {
foreach ($dependency in $chart.dependencies) {
if ($dependency.name -eq "stress-test-addons" -and
$dependency.version -like '0.1.*' -or
$dependency.version -like '^0.1.*') {
throw "The stress-test-addons version in use for '$chartFile' is $($dependency.version), please use versions >= 0.2.0"
}
}
}
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,
[switch]$CI,
[object]$namespaceOverride
) {
$namespace = if ($namespaceOverride) {
$namespaceOverride
} elseif ($CI) {
$chart.annotations.namespace
} else {
GetUsername
}
return [StressTestPackageInfo]@{
Namespace = $namespace.ToLower()
Directory = $chartFile.DirectoryName
ReleaseName = $chart.name
Dockerfile = "dockerfile" -in $chart.annotations.keys ? $chart.annotations.dockerfile : $null
DockerBuildDir = "dockerbuilddir" -in $chart.annotations.keys ? $chart.annotations.dockerbuilddir : $null
}
}
# Don't call functions when the script is being dot sourced
if ($MyInvocation.InvocationName -ne ".") {
FindStressPackages $searchDirectory $filters
}