Skip to content

Commit

Permalink
Refactor of app/generate values; pass required variables to some methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-vakil committed Sep 25, 2024
1 parent 1ec63e0 commit 0a6377d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
4 changes: 0 additions & 4 deletions cnab/app/app-discovery.ps1

This file was deleted.

7 changes: 6 additions & 1 deletion cnab/app/generate-values.ps1 → cnab/app/app.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 12 additions & 6 deletions cnab/app/container-registry-discovery.ps1
Original file line number Diff line number Diff line change
@@ -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 = @()
}

Expand Down
9 changes: 4 additions & 5 deletions cnab/app/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')
Expand Down
1 change: 1 addition & 0 deletions cnab/app/variables.GCP.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"deploymentTargetFilter": "deployment_target=true"
},
"vars": {
"singleRegistry": true,
"secretStore": "cluster-secrets",
"imagePullPolicy": "Always",
"replicaCount": "1",
Expand Down

0 comments on commit 0a6377d

Please sign in to comment.