Skip to content

Commit 61f536f

Browse files
authored
feat(postgres): support existing secret with custom key names for db credentials (#20)
- Added support for reading Postgres credentials from an existing Kubernetes Secret - Introduced values: `postgres.existingSecret`, `postgres.existingSecretUsernameKey`, and `postgres.existingSecretPasswordKey` - Updated deployment template to conditionally use secret or inline values - Updated values.yaml with explanatory comments - Updated schema to validate the new secret-based fields - Updated README to document all postgres credential configuration options
1 parent 65df049 commit 61f536f

4 files changed

Lines changed: 75 additions & 24 deletions

File tree

‎charts/listmonk/README.md‎

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ $ helm uninstall --namespace listmonk listmonk
2626

2727
## Values
2828

29-
| Key | Type | Default | Description |
30-
|---------------------------|--------|-----------------------|------------------------------------------------------|
31-
| ingress.annotations | object | `{}` | annotations for the ingress |
32-
| ingress.enabled | bool | `false` | enable the ingress |
33-
| ingress.className | string | `""` | ingress class name |
34-
| ingress.host | string | `"listmonk.local"` | host for the ingress |
35-
| ingress.tls | list | `[]` | tls configuration for the ingress |
36-
| listmonk.admin.password | string | `""` | the admin password |
37-
| listmonk.admin.username | string | `""` | the admin username |
38-
| listmonk.image.repository | string | `"listmonk/listmonk"` | the listmonk image repository |
39-
| listmonk.image.tag | string | `"v5.0.0"` | the listmonk image tag |
40-
| listmonk.replicas | int | `1` | the number of listmonk deployment replicas |
41-
| postgres.enabled | bool | `true` | enable internal postgres |
42-
| postgres.hostname | string | `""` | external postgres hostname |
43-
| postgres.database | string | `"listmonk"` | the postgres database name |
44-
| postgres.image.repository | string | `"postgres"` | the postgres image repository |
45-
| postgres.image.tag | string | `"16-alpine"` | the postgres image tag |
46-
| postgres.password | string | `""` | the postgres password |
47-
| postgres.resources | object | `{}` | resources configuration for the postgres statefulset |
48-
| postgres.user | string | `""` | the postgres username |
29+
| Key | Type | Default | Description |
30+
| ---------------------------------- | ------ | --------------------- | ----------------------------------------------------------------- |
31+
| ingress.annotations | object | `{}` | annotations for the ingress |
32+
| ingress.enabled | bool | `false` | enable the ingress |
33+
| ingress.className | string | `""` | ingress class name |
34+
| ingress.host | string | `"listmonk.local"` | host for the ingress |
35+
| ingress.tls | list | `[]` | tls configuration for the ingress |
36+
| listmonk.admin.password | string | `""` | the admin password |
37+
| listmonk.admin.username | string | `""` | the admin username |
38+
| listmonk.image.repository | string | `"listmonk/listmonk"` | the listmonk image repository |
39+
| listmonk.image.tag | string | `"v5.0.0"` | the listmonk image tag |
40+
| listmonk.replicas | int | `1` | the number of listmonk deployment replicas |
41+
| postgres.database | string | `"listmonk"` | the postgres database name |
42+
| postgres.enabled | bool | `true` | enable internal postgres |
43+
| postgres.existingSecret | string | `""` | name of an existing Kubernetes Secret with database credentials |
44+
| postgres.existingSecretPasswordKey | string | `""` | key in existingSecret for the database password (required if set) |
45+
| postgres.existingSecretUsernameKey | string | `""` | key in existingSecret for the database username (required if set) |
46+
| postgres.hostname | string | `""` | external postgres hostname (used when postgres.enabled is false) |
47+
| postgres.image.repository | string | `"postgres"` | the postgres image repository |
48+
| postgres.image.tag | string | `"16-alpine"` | the postgres image tag |
49+
| postgres.password | string | `""` | the postgres password (used if existingSecret is not set) |
50+
| postgres.resources | object | `{}` | resources configuration for the postgres statefulset |
51+
| postgres.user | string | `"listmonk"` | the postgres username (used if existingSecret is not set) |

‎charts/listmonk/templates/deployment-listmonk.yaml‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,23 @@ spec:
1919
containers:
2020
- env:
2121
- name: LISTMONK_db__user
22-
value: {{ .Values.postgres.user }}
22+
{{- if .Values.postgres.existingSecret }}
23+
valueFrom:
24+
secretKeyRef:
25+
name: {{ .Values.postgres.existingSecret | quote }}
26+
key: {{ .Values.postgres.existingSecretUsernameKey | quote }}
27+
{{- else }}
28+
value: {{ .Values.postgres.user | quote }}
29+
{{- end }}
2330
- name: LISTMONK_db__password
24-
value: {{ .Values.postgres.password }}
31+
{{- if .Values.postgres.existingSecret }}
32+
valueFrom:
33+
secretKeyRef:
34+
name: {{ .Values.postgres.existingSecret | quote }}
35+
key: {{ .Values.postgres.existingSecretPasswordKey | quote }}
36+
{{- else }}
37+
value: {{ .Values.postgres.password | quote }}
38+
{{- end }}
2539
image: {{ .Values.listmonk.image.repository }}:{{ .Values.listmonk.image.tag | default .Chart.AppVersion }}
2640
name: listmonk
2741
volumeMounts:
@@ -31,9 +45,23 @@ spec:
3145
initContainers:
3246
- env:
3347
- name: LISTMONK_db__user
34-
value: {{ .Values.postgres.user }}
48+
{{- if .Values.postgres.existingSecret }}
49+
valueFrom:
50+
secretKeyRef:
51+
name: {{ .Values.postgres.existingSecret | quote }}
52+
key: {{ .Values.postgres.existingSecretUsernameKey | quote }}
53+
{{- else }}
54+
value: {{ .Values.postgres.user | quote }}
55+
{{- end }}
3556
- name: LISTMONK_db__password
36-
value: {{ .Values.postgres.password }}
57+
{{- if .Values.postgres.existingSecret }}
58+
valueFrom:
59+
secretKeyRef:
60+
name: {{ .Values.postgres.existingSecret | quote }}
61+
key: {{ .Values.postgres.existingSecretPasswordKey | quote }}
62+
{{- else }}
63+
value: {{ .Values.postgres.password | quote }}
64+
{{- end }}
3765
name: init
3866
image: {{ .Values.listmonk.image.repository }}:{{ .Values.listmonk.image.tag | default .Chart.AppVersion }}
3967
command:

‎charts/listmonk/values.schema.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@
5656
"enabled": {
5757
"type": "boolean"
5858
},
59+
"existingSecret": {
60+
"type": "string",
61+
"description": "Optional: name of an existing Kubernetes Secret with db_user and db_password keys. If not set, `user` and `password` are required."
62+
},
63+
"existingSecretPasswordKey": {
64+
"type": "string",
65+
"description": "Optional: key inside the secret to use for the database password. Defaults to 'db_password'."
66+
},
67+
"existingSecretUsernameKey": {
68+
"type": "string",
69+
"description": "Optional: key inside the secret to use for the database username. Defaults to 'db_user'."
70+
},
5971
"hostname": {
6072
"type": "string"
6173
},

‎charts/listmonk/values.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ postgres:
2222
database: listmonk
2323
# -- enable postgres
2424
enabled: true
25+
# -- optionally provide the name of an existing Kubernetes Secret containing database credentials.
26+
# If set, this takes precedence over `user` and `password` values.
27+
# The secret must include two keys: `db_user` and `db_password` (or custom keys if specified below).
28+
existingSecret: "" # e.g., "listmonk-db-credentials"
29+
# -- optional: override the key name used for the password in the secret (default: db_password)
30+
existingSecretPasswordKey: db_password
31+
# -- optional: override the key name used for the username in the secret (default: db_user)
32+
existingSecretUsernameKey: db_user
2533
# -- when not enabled, the external postgres service hostname is required
2634
hostname: ""
2735
image:

0 commit comments

Comments
 (0)