...

Text file src/github.com/Azure/azure-sdk-for-go/eng/common/scripts/stress-testing/find-all-stress-packages.ps1

Documentation: github.com/Azure/azure-sdk-for-go/eng/common/scripts/stress-testing

     1param(
     2    [string]$searchDirectory = '.',
     3    [hashtable]$filters = @{}
     4)
     5
     6class StressTestPackageInfo {
     7    [string]$Namespace
     8    [string]$Directory
     9    [string]$ReleaseName
    10    [string]$Dockerfile
    11    [string]$DockerBuildDir
    12}
    13
    14function FindStressPackages(
    15    [string]$directory,
    16    [hashtable]$filters = @{},
    17    [switch]$CI,
    18    [string]$namespaceOverride
    19) {
    20    # Bare minimum filter for stress tests
    21    $filters['stressTest'] = 'true'
    22
    23    $packages = @()
    24    $chartFiles = Get-ChildItem -Recurse -Filter 'Chart.yaml' $directory 
    25    foreach ($chartFile in $chartFiles) {
    26        $chart = ParseChart $chartFile
    27        if (matchesAnnotations $chart $filters) {
    28            $packages += NewStressTestPackageInfo `
    29                            -chart $chart `
    30                            -chartFile $chartFile `
    31                            -CI:$CI `
    32                            -namespaceOverride $namespaceOverride
    33        }
    34    }
    35
    36    return $packages
    37}
    38
    39function ParseChart([string]$chartFile) {
    40    return ConvertFrom-Yaml (Get-Content -Raw $chartFile)
    41}
    42
    43function MatchesAnnotations([hashtable]$chart, [hashtable]$filters) {
    44    foreach ($filter in $filters.GetEnumerator()) {
    45        if (!$chart.annotations -or $chart.annotations[$filter.Key] -ne $filter.Value) {
    46            return $false
    47        }
    48    }
    49
    50    return $true
    51}
    52
    53function NewStressTestPackageInfo(
    54    [hashtable]$chart,
    55    [System.IO.FileInfo]$chartFile,
    56    [switch]$CI,
    57    [object]$namespaceOverride
    58) {
    59    $namespace = if ($namespaceOverride) {
    60        $namespaceOverride
    61    } elseif ($CI) {
    62        $chart.annotations.namespace
    63    } else {
    64        # Check GITHUB_USER for users in codespaces environments, since the default user is `codespaces` and
    65        # we would like to avoid namespace overlaps for different codespaces users.
    66        $namespace = if ($env:GITHUB_USER) {
    67            $env:GITHUB_USER
    68        } elseif ($env:USER) {
    69            $env:USER
    70        } else {
    71            $env:USERNAME
    72        }
    73        # Remove spaces, underscores, etc. that may be in $namespace. Value must be a valid RFC 1123 DNS label:
    74        # https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
    75        $namespace -replace '_|\W', '-'
    76    }
    77
    78    return [StressTestPackageInfo]@{
    79        Namespace = $namespace.ToLower()
    80        Directory = $chartFile.DirectoryName
    81        ReleaseName = $chart.name
    82        Dockerfile = $chart.annotations.dockerfile
    83        DockerBuildDir = $chart.annotations.dockerbuilddir
    84    }
    85}
    86
    87# Don't call functions when the script is being dot sourced
    88if ($MyInvocation.InvocationName -ne ".") {
    89    FindStressPackages $searchDirectory $filters
    90}

View as plain text