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
|
param(
[string]$searchDirectory = '.',
[hashtable]$filters = @{}
)
class StressTestPackageInfo {
[string]$Namespace
[string]$Directory
[string]$ReleaseName
[string]$Dockerfile
[string]$DockerBuildDir
}
function FindStressPackages(
[string]$directory,
[hashtable]$filters = @{},
[switch]$CI,
[string]$namespaceOverride
) {
# Bare minimum filter for stress tests
$filters['stressTest'] = 'true'
$packages = @()
$chartFiles = Get-ChildItem -Recurse -Filter 'Chart.yaml' $directory
foreach ($chartFile in $chartFiles) {
$chart = ParseChart $chartFile
if (matchesAnnotations $chart $filters) {
$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] -ne $filter.Value) {
return $false
}
}
return $true
}
function NewStressTestPackageInfo(
[hashtable]$chart,
[System.IO.FileInfo]$chartFile,
[switch]$CI,
[object]$namespaceOverride
) {
$namespace = if ($namespaceOverride) {
$namespaceOverride
} 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', '-'
}
return [StressTestPackageInfo]@{
Namespace = $namespace.ToLower()
Directory = $chartFile.DirectoryName
ReleaseName = $chart.name
Dockerfile = $chart.annotations.dockerfile
DockerBuildDir = $chart.annotations.dockerbuilddir
}
}
# Don't call functions when the script is being dot sourced
if ($MyInvocation.InvocationName -ne ".") {
FindStressPackages $searchDirectory $filters
}
|