|
| 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