Skip to content

Commit 0168553

Browse files
committed
[library-chart] PostgreSQL discovery
1 parent 8b8b968 commit 0168553

3 files changed

Lines changed: 70 additions & 1 deletion

File tree

charts/library-chart/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
apiVersion: v2
22
name: library-chart
3-
version: 1.7.6
3+
version: 1.7.7
44
type: library

charts/library-chart/templates/_notes.tpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ It is possible to associate an initialization script with your service to set up
196196
</details>
197197
{{ end -}}
198198

199+
{{- with (include "library-chart.postgresql-discovery-help" .) }}
200+
<details>
201+
<summary>PostgreSQL</summary>
202+
{{ . }}
203+
</details>
204+
{{ end -}}
205+
199206
{{- with (include "library-chart.metaflow-discovery-help" .) }}
200207
<details>
201208
<summary>Metaflow</summary>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/* Create the name of the secret PostgreSQL to use */}}
2+
{{- define "library-chart.secretNamePostgreSQL" -}}
3+
{{- if (.Values.discovery).postgresql }}
4+
{{- $name := printf "%s-secretpostgresql" (include "library-chart.fullname" .) }}
5+
{{- default $name (.Values.postgresql).secretName }}
6+
{{- else }}
7+
{{- default "default" (.Values.postgresql).secretName }}
8+
{{- end }}
9+
{{- end }}
10+
11+
12+
{{/* Secret for PostgreSQL */}}
13+
{{- define "library-chart.secretPostgreSQL" }}
14+
{{- $context := . }}
15+
{{- if (.Values.discovery).postgresql }}
16+
{{- with $secretData := first (include "library-chart.getOnyxiaDiscoverySecrets" (list .Release.Namespace "postgres") | fromJsonArray) -}}
17+
{{- $pg_service := index $secretData "postgres-service" | default "" | b64dec }}
18+
{{- $pg_port := index $secretData "postgres-port" | default "" | b64dec }}
19+
{{- $pg_database := index $secretData "postgres-database" | default "" | b64dec }}
20+
{{- $pg_username := index $secretData "postgres-username" | default "" | b64dec }}
21+
{{- $pg_password := index $secretData "password" | default "" | b64dec }}
22+
apiVersion: v1
23+
kind: Secret
24+
metadata:
25+
name: {{ include "library-chart.secretNamePostgreSQL" $context }}
26+
labels:
27+
{{- include "library-chart.labels" $context | nindent 4 }}
28+
stringData:
29+
PGHOST: "http://{{ $pg_service }}"
30+
PGPORT: {{ $pg_port | quote }}
31+
PGDATABASE: {{ $pg_database | quote }}
32+
PGUSER: {{ $pg_username | quote }}
33+
PGPASSWORD: {{ $pg_password | quote }}
34+
{{- end }}
35+
{{- end }}
36+
{{- end }}
37+
38+
39+
{{- define "library-chart.postgresql-discovery-help" -}}
40+
{{- if (.Values.discovery).postgresql }}
41+
{{- if first (include "library-chart.getOnyxiaDiscoverySecrets" (list .Release.Namespace "postgres") | fromJsonArray) }}
42+
The connection to your PostgreSQL service is already preconfigured in your service.
43+
{{- if regexMatch "^r|r$" .Chart.Name }}
44+
```r
45+
library(DBI)
46+
conn <- dbConnect(RPostgres::Postgres())
47+
print(dbGetQuery(conn, "SELECT version();"))
48+
dbDisconnect(conn)
49+
```
50+
{{- else }}
51+
A client can be created in a Python script or interactive console:
52+
```python
53+
import psycopg
54+
conn = psycopg.connect()
55+
with conn.cursor() as cur:
56+
print(cur.execute("SELECT version();").fetchone())
57+
conn.close()
58+
```
59+
{{- end }}
60+
{{- end }}
61+
{{- end }}
62+
{{- end -}}

0 commit comments

Comments
 (0)