From 0a6377db1afd6f64a2d8f56cf26c61c18e04f531 Mon Sep 17 00:00:00 2001 From: Stephen Vakil Date: Wed, 25 Sep 2024 08:42:52 -0500 Subject: [PATCH] Refactor of app/generate values; pass required variables to some methods --- cnab/app/app-discovery.ps1 | 4 ---- cnab/app/{generate-values.ps1 => app.ps1} | 7 ++++++- cnab/app/container-registry-discovery.ps1 | 18 ++++++++++++------ cnab/app/run.ps1 | 9 ++++----- cnab/app/variables.GCP.json | 1 + 5 files changed, 23 insertions(+), 16 deletions(-) delete mode 100644 cnab/app/app-discovery.ps1 rename cnab/app/{generate-values.ps1 => app.ps1} (93%) diff --git a/cnab/app/app-discovery.ps1 b/cnab/app/app-discovery.ps1 deleted file mode 100644 index 388113fe..00000000 --- a/cnab/app/app-discovery.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -function Get-AppName() { - $app = 'opserver' - return $app -} \ No newline at end of file diff --git a/cnab/app/generate-values.ps1 b/cnab/app/app.ps1 similarity index 93% rename from cnab/app/generate-values.ps1 rename to cnab/app/app.ps1 index 8cff2e21..c415065c 100644 --- a/cnab/app/generate-values.ps1 +++ b/cnab/app/app.ps1 @@ -1,4 +1,9 @@ -function Generate-Values() { +function Get-AppName() { + $app = 'opserver' + return $app +} + +function Generate-Values($vars, $environment, $containerRegistryUrl, $releaseTag, $pullSecretName) { Write-MajorStep "Generating Helm values" $values = @{ tier = $environment diff --git a/cnab/app/container-registry-discovery.ps1 b/cnab/app/container-registry-discovery.ps1 index e3929467..2ae920ed 100644 --- a/cnab/app/container-registry-discovery.ps1 +++ b/cnab/app/container-registry-discovery.ps1 @@ -1,15 +1,21 @@ -function Find-ContainerRegistry([string]$imageTag) { +function Find-ContainerRegistry([string]$imageTag, [bool]$singleRegistry) { Write-MinorStep "Finding Container Registry for tag: $imageTag" - # PR container images are located in `cr-dev` in CloudSmith. As opposed to `cr` which we use for release builds. + + # default container registry; for PRs in some apps we still use cr-dev and we will override + # below if we detect a PR and singleRegistry is false + $containerRegistryUrl = 'cr.stackoverflow.software' + $pullSecretName = 'cloudsmith-cr-prod' + $isPr = IsPr $imageTag + if ($isPr) { - $containerRegistryUrl = 'cr.stackoverflow.software' - $pullSecretName = 'cloudsmith-cr-prod' + if (-not $singleRegistry) { + $containerRegistryUrl = 'cr-dev.stackoverflow.software' + $pullSecretName = 'cloudsmith-cr-dev' + } $forceUpgrade = @('--force') # This'll force pods to be recreated with freshly-pulled images } else { - $containerRegistryUrl = 'cr.stackoverflow.software' - $pullSecretName = 'cloudsmith-cr-prod' $forceUpgrade = @() } diff --git a/cnab/app/run.ps1 b/cnab/app/run.ps1 index 74817d06..5eb930ad 100644 --- a/cnab/app/run.ps1 +++ b/cnab/app/run.ps1 @@ -19,10 +19,10 @@ trap { break } -. $PSScriptRoot/app-discovery.ps1 -. $PSScriptRoot/generate-values.ps1 +. $PSScriptRoot/app.ps1 . $PSScriptRoot/container-registry-discovery.ps1 . $PSScriptRoot/utils.ps1 +. $PSScriptRoot/gcp-cluster-discovery.ps1 $app = Get-AppName @@ -51,7 +51,7 @@ $project = $vars.pipeline.project $releaseTag = $vars.pipeline.releaseTag -$containerRegistryDetails = Find-ContainerRegistry $releaseTag +$containerRegistryDetails = Find-ContainerRegistry $releaseTag $vars.vars.singleRegistry $containerRegistryUrl = $containerRegistryDetails.Url $pullSecretName = $containerRegistryDetails.PullSecretName $forceUpgrade = $containerRegistryDetails.ForceUpgrade @@ -77,7 +77,6 @@ $releaseTag = $releaseTag -replace '([a-z0-9]{40})-.*', '$1' Write-MajorStep "Running $action for Tenant: $tenant - Environment: $environment - Project: $project in cloud: $($vars.runtime.name)" if ($vars.runtime.name -eq "GCP") { - . $PSScriptRoot/gcp-cluster-discovery.ps1 Write-MajorStep "Finding Deployment Group and Deployment Targetr" $deploymentGroup = Find-DeploymentGroup $vars.deploymentDiscovery.deploymentGroupFilter $deploymentTarget = Find-DeploymentTarget $vars.deploymentDiscovery.deploymentTargetFilter $deploymentGroup @@ -101,7 +100,7 @@ switch ($action) { "install" { Write-MajorStep "Install action" - $valuesFileContent = Generate-Values + $valuesFileContent = Generate-Values $vars $environment $containerRegistryUrl $releaseTag $pullSecretName $tmpDir = [System.IO.Directory]::CreateTempSubdirectory($app + '-') $valuesFilePath = (Join-Path $tmpDir.FullName 'populated-values.yml') diff --git a/cnab/app/variables.GCP.json b/cnab/app/variables.GCP.json index 6c15265d..9d1b0224 100644 --- a/cnab/app/variables.GCP.json +++ b/cnab/app/variables.GCP.json @@ -21,6 +21,7 @@ "deploymentTargetFilter": "deployment_target=true" }, "vars": { + "singleRegistry": true, "secretStore": "cluster-secrets", "imagePullPolicy": "Always", "replicaCount": "1",