Skip to content

Commit

Permalink
feat: added templating to postgres connection
Browse files Browse the repository at this point in the history
Signed-off-by: Mateusz Urbanek <mateusz.urbanek.98@gmail.com>
  • Loading branch information
shanduur committed Jul 27, 2024
1 parent 26db419 commit db6646f
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
9 changes: 6 additions & 3 deletions anza-labs/lubelog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,13 @@ LubeLogger is a web-based vehicle maintenance and fuel mileage tracker
| podAnnotations | object | `{}` | Annotations to be added to the pods. |
| podLabels | object | `{}` | Labels to be added to the pods. |
| podSecurityContext | object | `{}` | |
| postgres | object | `{"connect":false,"database":"postgres","host":"postgres","password":"postgres","port":5432,"user":"postgres"}` | PostgreSQL connection details. |
| postgres.connect | bool | `false` | Defines if the secret with Postgres connection details should be created. |
| postgres | object | `{"connect":false,"create":false,"database":"postgres","host":"postgres","keyRef":"POSTGRES_CONNECTION","name":"","password":"postgres","port":5432,"user":"postgres"}` | PostgreSQL connection details. |
| postgres.connect | bool | `false` | Defines if the LubeLogger should connect to the Postgres backend. It has no effect when `postgres.create=true`. |
| postgres.create | bool | `false` | Defines if the secret with Postgres connection details should be created. |
| postgres.database | string | `"postgres"` | Database name. |
| postgres.host | string | `"postgres"` | Host of the Postgres database. |
| postgres.keyRef | string | `"POSTGRES_CONNECTION"` | Defines the key under which postgres connection string can be found. It uses Npgsql connection format. |
| postgres.name | string | `""` | Specifies name of a secret used to configure the LubeLogger's Postgres backend. If not filled, uses full name. |
| postgres.password | string | `"postgres"` | Password for the user used to connect to the Postgres database. |
| postgres.port | int | `5432` | Port of the Postgres database. |
| postgres.user | string | `"postgres"` | User used to connect to the Postgres database. |
Expand All @@ -45,7 +48,7 @@ LubeLogger is a web-based vehicle maintenance and fuel mileage tracker
| secret.create | bool | `true` | Specifies whether a secret should be created. |
| secret.emailFrom | string | `""` | Email from address for the secret. |
| secret.emailServer | string | `""` | Email server for the secret. |
| secret.name | string | `""` | Specifies name of a secret used to configure the lubelog. |
| secret.name | string | `""` | Specifies name of a secret used to configure the LubeLogger's mail connection. If not filled, uses full name. |
| secret.password | string | `""` | Password for the email server. |
| secret.port | int | `587` | Port for the email server. |
| secret.username | string | `""` | Username for the email server. |
Expand Down
14 changes: 14 additions & 0 deletions anza-labs/lubelog/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,17 @@ Create secret name used for configuring mail.
{{- define "lubelog.mailSecret" -}}
{{- default (include "lubelog.fullname" .) .Values.secret.name }}
{{- end }}

{{/*
Create secret name used for configuring PostgreSQL connection.
*/}}
{{- define "lubelog.postgresSecret" -}}
{{- default ( printf "%s-postgres-connection" (include "lubelog.fullname" .)) .Values.postgres.name }}
{{- end }}

{{/*
Create key under which PostgreSQL connection string can be found.
*/}}
{{- define "lubelog.postgresSecretKey" -}}
{{- default "POSTGRES_CONNECTION" .Values.postgres.keyRef }}
{{- end }}
4 changes: 2 additions & 2 deletions anza-labs/lubelog/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ spec:
secretKeyRef:
name: {{ include "lubelog.mailSecret" . }}
key: MailConfig__Password
{{- if .Values.postgres.connect }}
{{- if or .Values.postgres.connect .Values.postgres.create }}
- name: POSTGRES_CONNECTION
valueFrom:
secretKeyRef:
name: {{ include "lubelog.fullname" . }}-postgres-connection
name: {{ include "lubelog.postgresSecret" . }}
key: POSTGRES_CONNECTION
{{- end }}
{{- with .Values.nodeSelector }}
Expand Down
2 changes: 1 addition & 1 deletion anza-labs/lubelog/templates/postgres-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ metadata:
{{- end }}
type: Opaque
stringData:
POSTGRES_CONNECTION: "Host={{ $pgHost }}:{{ $pgPort }};Username={{ $pgUser }};Password={{ $pgPass }};Database={{ $pgDatabase }};"
{{- include "lubelog.postgresSecretKey" . | nindent 2}}: "Host={{ $pgHost }}:{{ $pgPort }};Username={{ $pgUser }};Password={{ $pgPass }};Database={{ $pgDatabase }};"
{{- end }}
12 changes: 11 additions & 1 deletion anza-labs/lubelog/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ serviceAccount:
secret:
# -- Specifies whether a secret should be created.
create: true
# -- Specifies name of a secret used to configure the lubelog.
# -- Specifies name of a secret used to configure the LubeLogger's mail connection.
# If not filled, uses full name.
name: ""
# -- Email server for the secret.
emailServer: ""
Expand All @@ -59,7 +60,16 @@ secret:
# -- PostgreSQL connection details.
postgres:
# -- Defines if the secret with Postgres connection details should be created.
create: false
# -- Defines if the LubeLogger should connect to the Postgres backend.
# It has no effect when `postgres.create=true`.
connect: false
# -- Specifies name of a secret used to configure the LubeLogger's Postgres backend.
# If not filled, uses full name.
name: ""
# -- Defines the key under which postgres connection string can be found.
# It uses Npgsql connection format.
keyRef: "POSTGRES_CONNECTION"
# -- Host of the Postgres database.
host: "postgres"
# -- Port of the Postgres database.
Expand Down

0 comments on commit db6646f

Please sign in to comment.