feat(cnpg): add pooler urls to the secret (#679)

**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  # <!--(issue)-->

**⚙️ Type of change**

- [x] ⚙️ Feature/App addition
- [x] 🪛 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:**

- [x] ⚖️ My code follows the style guidelines of this project
- [x] 👀 I have performed a self-review of my own code
- [x] #️⃣ I have commented my code, particularly in hard-to-understand
areas
- [ ] 📄 I have made corresponding changes to the documentation
- [x] ⚠️ My changes generate no new warnings
- [x] 🧪 I have added tests to this description that prove my fix is
effective or that my feature works
- [x] ⬆️ 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._
This commit is contained in:
Stavros Kois
2024-01-21 14:52:06 +02:00
committed by GitHub
parent 3f4d795cae
commit 814cf9e63c
4 changed files with 91 additions and 19 deletions

View File

@@ -56,6 +56,9 @@ tests:
porthost: test-release-name-common-test-cnpg-my-pg-rw:5432
host: test-release-name-common-test-cnpg-my-pg-rw
jdbc: jdbc:postgresql://test-release-name-common-test-cnpg-my-pg-rw:5432/test-db
poolerporthost: test-release-name-common-test-cnpg-my-pg-pooler-rw:5432
poolerhost: test-release-name-common-test-cnpg-my-pg-pooler-rw
poolerjdbc: jdbc:postgresql://test-release-name-common-test-cnpg-my-pg-pooler-rw:5432/test-db
- documentIndex: *secretDoc
matchRegex:
path: stringData.std
@@ -64,6 +67,14 @@ tests:
matchRegex:
path: stringData.nossl
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-rw:5432/test-db\?sslmode=disable
- documentIndex: *secretDoc
matchRegex:
path: stringData.poolerstd
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-pooler-rw:5432/test-db
- documentIndex: *secretDoc
matchRegex:
path: stringData.poolernossl
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-pooler-rw:5432/test-db\?sslmode=disable
- it: should generate correct secret with ro pooler
set:
@@ -95,9 +106,15 @@ tests:
porthost: test-release-name-common-test-cnpg-my-pg-rw:5432
host: test-release-name-common-test-cnpg-my-pg-rw
jdbc: jdbc:postgresql://test-release-name-common-test-cnpg-my-pg-rw:5432/test-db
poolerporthost: test-release-name-common-test-cnpg-my-pg-pooler-rw:5432
poolerhost: test-release-name-common-test-cnpg-my-pg-pooler-rw
poolerjdbc: jdbc:postgresql://test-release-name-common-test-cnpg-my-pg-pooler-rw:5432/test-db
hostRO: test-release-name-common-test-cnpg-my-pg-ro
jdbcRO: jdbc:postgresql://test-release-name-common-test-cnpg-my-pg-ro:5432/test-db
porthostRO: test-release-name-common-test-cnpg-my-pg-ro:5432
poolerhostRO: test-release-name-common-test-cnpg-my-pg-pooler-ro
poolerjdbcRO: jdbc:postgresql://test-release-name-common-test-cnpg-my-pg-pooler-ro:5432/test-db
poolerporthostRO: test-release-name-common-test-cnpg-my-pg-pooler-ro:5432
- documentIndex: *secretDoc
matchRegex:
path: stringData.std
@@ -106,6 +123,14 @@ tests:
matchRegex:
path: stringData.nossl
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-rw:5432/test-db\?sslmode=disable
- documentIndex: *secretDoc
matchRegex:
path: stringData.poolerstd
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-pooler-rw:5432/test-db
- documentIndex: *secretDoc
matchRegex:
path: stringData.poolernossl
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-pooler-rw:5432/test-db\?sslmode=disable
- documentIndex: *secretDoc
matchRegex:
path: stringData.stdRO
@@ -114,6 +139,14 @@ tests:
matchRegex:
path: stringData.nosslRO
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-ro:5432/test-db\?sslmode=disable
- documentIndex: *secretDoc
matchRegex:
path: stringData.poolerstdRO
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-pooler-ro:5432/test-db
- documentIndex: *secretDoc
matchRegex:
path: stringData.poolernosslRO
pattern: postgresql://test-user:[a-zA-Z0-9]{62}@test-release-name-common-test-cnpg-my-pg-pooler-ro:5432/test-db\?sslmode=disable
- it: should generate correct secret with password set
set:

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 17.2.23
version: 17.2.24

View File

@@ -2,24 +2,43 @@
{{- $objectData := .objectData -}}
{{- $cnpg := .cnpg -}}
{{- $rootCtx := .rootCtx -}}
{{- $dbPass := $objectData.password -}}
{{- $auth := printf "%s:%s" $objectData.user $dbPass -}}
{{/* Double "%" to escape the interpolation and use the template on another printf */}}
{{- $stdTmpl := printf "postgresql://%s@%s-%%s:5432/%s" $auth $objectData.name $objectData.database -}}
{{- $nosslTmpl := printf "postgresql://%s@%s-%%s:5432/%s?sslmode=disable" $auth $objectData.name $objectData.database -}}
{{- $portHostTmpl := printf "%s-%%s:5432" $objectData.name -}}
{{- $hostTmpl := printf "%s-%%s" $objectData.name -}}
{{- $jdbcTmpl := printf "jdbc:postgresql://%s-%%s:5432/%s" $objectData.name $objectData.database -}}
{{- $creds := (dict
"std" (printf "postgresql://%v:%v@%v-rw:5432/%v" $objectData.user $dbPass $objectData.name $objectData.database)
"nossl" (printf "postgresql://%v:%v@%v-rw:5432/%v?sslmode=disable" $objectData.user $dbPass $objectData.name $objectData.database)
"porthost" (printf "%s-rw:5432" $objectData.name)
"host" (printf "%s-rw" $objectData.name)
"jdbc" (printf "jdbc:postgresql://%v-rw:5432/%v" $objectData.name $objectData.database)
"std" (printf $stdTmpl "rw")
"nossl" (printf $nosslTmpl "rw")
"portHost" (printf $portHostTmpl "rw")
"host" (printf $hostTmpl "rw")
"jdbc" (printf $jdbcTmpl "rw")
"poolerStd" (printf $stdTmpl "pooler-rw")
"poolerNossl" (printf $nosslTmpl "pooler-rw")
"poolerPortHost" (printf $portHostTmpl "pooler-rw")
"poolerHost" (printf $hostTmpl "pooler-rw")
"poolerJdbc" (printf $jdbcTmpl "pooler-rw")
) -}}
{{- $credsRO := dict -}}
{{- if $objectData.pooler.createRO -}}
{{- $credsRO = (dict
"std" (printf "postgresql://%v:%v@%v-ro:5432/%v" $objectData.user $dbPass $objectData.name $objectData.database)
"nossl" (printf "postgresql://%v:%v@%v-ro:5432/%v?sslmode=disable" $objectData.user $dbPass $objectData.name $objectData.database)
"porthost" (printf "%s-ro:5432" $objectData.name)
"host" (printf "%s-ro" $objectData.name)
"jdbc" (printf "jdbc:postgresql://%v-ro:5432/%v" $objectData.name $objectData.database)
"std" (printf $stdTmpl "ro")
"nossl" (printf $nosslTmpl "ro")
"portHost" (printf $portHostTmpl "ro")
"host" (printf $hostTmpl "ro")
"jdbc" (printf $jdbcTmpl "ro")
"poolerStd" (printf $stdTmpl "pooler-ro")
"poolerNossl" (printf $nosslTmpl "pooler-ro")
"poolerPortHost" (printf $portHostTmpl "pooler-ro")
"poolerHost" (printf $hostTmpl "pooler-ro")
"poolerJdbc" (printf $jdbcTmpl "pooler-ro")
) -}}
{{- end -}}
@@ -40,16 +59,26 @@
{{- $_ := set $cnpg.creds "std" $creds.std -}}
{{- $_ := set $cnpg.creds "nossl" $creds.nossl -}}
{{- $_ := set $cnpg.creds "porthost" $creds.porthost -}}
{{- $_ := set $cnpg.creds "porthost" $creds.portHost -}}
{{- $_ := set $cnpg.creds "host" $creds.host -}}
{{- $_ := set $cnpg.creds "jdbc" $creds.jdbc -}}
{{- $_ := set $cnpg.creds "poolerstd" $creds.poolerStd -}}
{{- $_ := set $cnpg.creds "poolernossl" $creds.poolerNossl -}}
{{- $_ := set $cnpg.creds "poolerporthost" $creds.poolerPortHost -}}
{{- $_ := set $cnpg.creds "poolerhost" $creds.poolerHost -}}
{{- $_ := set $cnpg.creds "poolerjdbc" $creds.poolerJdbc -}}
{{- if $objectData.pooler.createRO -}}
{{- $_ := set $cnpg.creds "stdRO" $credsRO.std -}}
{{- $_ := set $cnpg.creds "nosslRO" $credsRO.nossl -}}
{{- $_ := set $cnpg.creds "porthostRO" $credsRO.porthost -}}
{{- $_ := set $cnpg.creds "porthostRO" $credsRO.portHost -}}
{{- $_ := set $cnpg.creds "hostRO" $credsRO.host -}}
{{- $_ := set $cnpg.creds "jdbcRO" $credsRO.jdbc -}}
{{- $_ := set $cnpg.creds "poolerstdRO" $credsRO.poolerStd -}}
{{- $_ := set $cnpg.creds "poolernosslRO" $credsRO.poolerNossl -}}
{{- $_ := set $cnpg.creds "poolerporthostRO" $credsRO.poolerPortHost -}}
{{- $_ := set $cnpg.creds "poolerhostRO" $credsRO.poolerHost -}}
{{- $_ := set $cnpg.creds "poolerjdbcRO" $credsRO.poolerJdbc -}}
{{- end -}}
{{- end -}}
@@ -61,15 +90,25 @@ enabled: true
data:
std: {{ $creds.std }}
nossl: {{ $creds.nossl }}
porthost: {{ $creds.porthost }}
porthost: {{ $creds.portHost }}
host: {{ $creds.host }}
jdbc: {{ $creds.jdbc }}
poolerstd: {{ $creds.poolerStd }}
poolernossl: {{ $creds.poolerNossl }}
poolerporthost: {{ $creds.poolerPortHost }}
poolerhost: {{ $creds.poolerHost }}
poolerjdbc: {{ $creds.poolerJdbc }}
{{- if $credsRO }}
stdRO: {{ $credsRO.std }}
nosslRO: {{ $credsRO.nossl }}
porthostRO: {{ $credsRO.porthost }}
porthostRO: {{ $credsRO.portHost }}
hostRO: {{ $credsRO.host }}
jdbcRO: {{ $credsRO.jdbc }}
poolerstdRO: {{ $credsRO.poolerStd }}
poolernosslRO: {{ $credsRO.poolerNossl }}
poolerporthostRO: {{ $credsRO.poolerPortHost }}
poolerhostRO: {{ $credsRO.poolerHost }}
poolerjdbcRO: {{ $credsRO.poolerJdbc }}
{{- end -}}
{{- end -}}

View File

@@ -368,15 +368,15 @@ command:
{{ $cnpgName = printf "%v-cnpg-%v" $cnpgName $name }}
echo "Detected RW pooler, testing RW pooler availability..."
until
echo "Testing database on url: {{ $cnpgName }}-rw"
pg_isready -U {{ .user }} -d {{ .database }} -h {{ $cnpgName }}-rw
echo "Testing database on url: {{ $cnpgName }}-pooler-rw"
pg_isready -U {{ .user }} -d {{ .database }} -h {{ $cnpgName }}-pooler-rw
do sleep 5
done
{{ if $cnpg.acceptRO }}
echo "Detected RO pooler, testing RO pooler availability..."
until
echo "Testing database on url: {{ $cnpgName }}-ro"
pg_isready -U {{ .user }} -d {{ .database }} -h {{ $cnpgName }}-ro
echo "Testing database on url: {{ $cnpgName }}-pooler-ro"
pg_isready -U {{ .user }} -d {{ .database }} -h {{ $cnpgName }}-pooler-ro
do sleep 5
done
{{ end }}