mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-03 12:44:18 -03:00
**Description** <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ⚒️ Fixes #622 **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> **📃 Notes:** <!-- Please enter any other relevant information here --> **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._
103 lines
4.5 KiB
Smarty
103 lines
4.5 KiB
Smarty
{{/* Renders the cnpg objects required by the chart */}}
|
|
{{- define "tc.v1.common.spawner.cnpg" -}}
|
|
|
|
{{- $fullname := include "tc.v1.common.lib.chart.names.fullname" $ -}}
|
|
|
|
{{- range $name, $cnpg := $.Values.cnpg -}}
|
|
|
|
{{- $enabled := (include "tc.v1.common.lib.util.enabled" (dict
|
|
"rootCtx" $ "objectData" $cnpg
|
|
"name" $name "caller" "CNPG"
|
|
"key" "cnpg")) -}}
|
|
|
|
{{/* Create a copy */}}
|
|
{{- $objectData := mustDeepCopy $cnpg -}}
|
|
{{- $objectName := printf "%s-cnpg-%s" $fullname $name -}}
|
|
|
|
{{/* Set the name */}}
|
|
{{- $_ := set $objectData "name" $objectName -}}
|
|
{{/* Short name is the one that defined on the chart*/}}
|
|
{{- $_ := set $objectData "shortName" $name -}}
|
|
{{/* Set the cluster name */}}
|
|
{{- $_ := set $objectData "clusterName" (include "tc.v1.common.lib.cnpg.clusterName" (dict "objectData" $objectData)) -}}
|
|
|
|
{{/* Handle recovery string */}}
|
|
{{- $recoveryValue := "" -}}
|
|
{{- $recoveryKey := "recovery-string" -}}
|
|
{{- $recoveryConfigMapName := printf "cnpg-%s-%s" $objectData.shortName $recoveryKey -}}
|
|
|
|
{{/* If there are previous configmap, fetch value */}}
|
|
{{- with (lookup "v1" "ConfigMap" $.Release.Namespace $recoveryConfigMapName) -}}
|
|
{{- $recoveryValue = (index .data $recoveryKey) -}}
|
|
{{- end -}}
|
|
|
|
{{/* If forced recovery is requested... */}}
|
|
{{- if $objectData.forceRecovery -}}
|
|
{{- $recoveryValue = randAlphaNum 5 -}}
|
|
{{- end -}}
|
|
|
|
{{/* Recreate the configmap if there is a recovery value */}}
|
|
{{- if $recoveryValue -}}
|
|
{{- $_ := set $objectData "recoveryValue" $recoveryValue -}}
|
|
{{- $recConfig := include "tc.v1.common.lib.cnpg.configmap.recoverystring" (dict "recoveryString" $recoveryValue "recoveryKey" $recoveryKey) | fromYaml -}}
|
|
{{- $_ := set $.Values.configmap $recoveryConfigMapName $recConfig -}}
|
|
{{- end -}}
|
|
|
|
{{- if eq $enabled "true" -}}
|
|
|
|
{{- include "tc.v1.common.lib.util.metaListToDict" (dict "objectData" $objectData) -}}
|
|
|
|
{{/* Handle Backups/ScheduledBackups */}}
|
|
{{- if and (hasKey $objectData "backups") $objectData.backups.enabled -}}
|
|
|
|
{{/* Create Backups */}}
|
|
{{- include "tc.v1.common.lib.cnpg.spawner.backups" (dict "rootCtx" $ "objectData" $objectData) -}}
|
|
|
|
{{/* Create ScheduledBackups */}}
|
|
{{- include "tc.v1.common.lib.cnpg.spawner.scheduledBackups" (dict "rootCtx" $ "objectData" $objectData) -}}
|
|
|
|
{{/* Create secret for backup store */}}
|
|
{{- include "tc.v1.common.lib.cnpg.provider.secret.spawner" (dict "rootCtx" $ "objectData" $objectData "type" "backup") -}}
|
|
{{- end -}}
|
|
|
|
{{/* Handle Pooler(s) */}}
|
|
{{- include "tc.v1.common.lib.cnpg.spawner.pooler" (dict "rootCtx" $ "objectData" $objectData) -}}
|
|
|
|
{{/* Handle Cluster */}}
|
|
{{/* Validate Cluster */}}
|
|
{{- include "tc.v1.common.lib.cnpg.cluster.validation" (dict "objectData" $objectData) -}}
|
|
|
|
{{- if and (eq $objectData.mode "recovery") (eq $objectData.recovery.method "object_store") -}}
|
|
{{/* Create secret for recovery store */}}
|
|
{{- include "tc.v1.common.lib.cnpg.provider.secret.spawner" (dict "rootCtx" $ "objectData" $objectData "type" "recovery") -}}
|
|
{{- end -}}
|
|
|
|
{{/* Create the Cluster object */}}
|
|
{{- include "tc.v1.common.class.cnpg.cluster" (dict "rootCtx" $ "objectData" $objectData) -}}
|
|
|
|
{{/* TODO: Create configmaps for cluster.monitoring.customQueries */}}
|
|
{{- end -}}
|
|
|
|
{{/* Fetch db pass from Secret */}}
|
|
{{- $dbPass := "" -}}
|
|
{{- with (lookup "v1" "Secret" $.Release.Namespace (printf "%s-user" $objectData.name)) -}}
|
|
{{- $dbPass = (index .data "password") | b64dec -}}
|
|
{{- end -}}
|
|
|
|
{{/* Either enebled or if there was a dbpass fetched. Required to keep the generated password around */}}
|
|
{{- if or (eq $enabled "true") $dbPass -}}
|
|
{{/* If enabled or dbPass fetched from secret, recreate the secret */}}
|
|
{{- if not $dbPass -}}
|
|
{{/* Use provided password or fallback to generating new password */}}
|
|
{{- $dbPass = $objectData.password | default (randAlphaNum 62) -}}
|
|
{{- end -}}
|
|
{{/* Set password back to password field */}}
|
|
{{- $_ := set $objectData "password" $dbPass -}}
|
|
|
|
{{/* Handle DB Credentials Secret, will also inject creds to cnpg.creds */}}
|
|
{{- include "tc.v1.common.lib.cnpg.db.credentials.secrets" (dict "rootCtx" $ "cnpg" $cnpg "objectData" $objectData) -}}
|
|
{{- end -}}
|
|
|
|
{{- end -}}
|
|
{{- end -}}
|