Skip to content

Commit faaee9f

Browse files
wrenixWrenIX
authored andcommitted
fixt(nextcloud): extract db environment
Signed-off-by: WrenIX <dev.github@wrenix.eu>
1 parent 0937a1c commit faaee9f

5 files changed

Lines changed: 103 additions & 81 deletions

File tree

charts/nextcloud/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: nextcloud
3-
version: 9.1.3
3+
version: 9.1.4
44
# renovate: image=docker.io/library/nextcloud
55
appVersion: 33.0.5
66
description: A file sharing server that puts the control and security of your own data back into your hands.

charts/nextcloud/templates/_helpers.tpl

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ Create image name that is used in the deployment
6464
{{/*
6565
Create environment variables used to configure the nextcloud container as well as the cron sidecar container.
6666
*/}}
67-
{{- define "nextcloud.env" -}}
68-
{{- if .Values.phpClientHttpsFix.enabled }}
69-
- name: OVERWRITEPROTOCOL
70-
value: {{ .Values.phpClientHttpsFix.protocol | quote }}
71-
{{- end }}
67+
{{- define "nextcloud.env.database" -}}
7268
{{- if .Values.internalDatabase.enabled }}
7369
- name: SQLITE_DATABASE
7470
value: {{ .Values.internalDatabase.name | quote }}
@@ -87,6 +83,8 @@ Create environment variables used to configure the nextcloud container as well a
8783
secretKeyRef:
8884
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
8985
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
86+
- name: DATABASE_URL
87+
value: "mysql://$(MYSQL_USER):$(MYSQL_PASSWORD)@$(MYSQL_HOST)/$(MYSQL_DATABASE)"
9088
{{- else if .Values.postgresql.enabled }}
9189
- name: POSTGRES_HOST
9290
value: {{ template "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
@@ -106,7 +104,9 @@ Create environment variables used to configure the nextcloud container as well a
106104
secretKeyRef:
107105
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
108106
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
109-
{{- else }}
107+
- name: DATABASE_URL
108+
value: "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST)/$(POSTGRES_DB)"
109+
{{- else }}{{/* mariadb.enable or postgresql.enabled -> now external */}}
110110
{{- if eq .Values.externalDatabase.type "postgresql" }}
111111
- name: POSTGRES_HOST
112112
{{- if .Values.externalDatabase.existingSecret.hostKey }}
@@ -136,7 +136,9 @@ Create environment variables used to configure the nextcloud container as well a
136136
secretKeyRef:
137137
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
138138
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
139-
{{- else }}
139+
- name: DATABASE_URL
140+
value: "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST)/$(POSTGRES_DB)"
141+
{{- else }}{{/* external.type = postgresql */}}
140142
- name: MYSQL_HOST
141143
{{- if .Values.externalDatabase.existingSecret.hostKey }}
142144
valueFrom:
@@ -165,8 +167,72 @@ Create environment variables used to configure the nextcloud container as well a
165167
secretKeyRef:
166168
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
167169
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
168-
{{- end }}
170+
- name: DATABASE_URL
171+
value: "mysql://$(MYSQL_USER):$(MYSQL_PASSWORD)@$(MYSQL_HOST)/$(MYSQL_DATABASE)"
172+
{{- end }}{{/* external.type = postgresql */}}
173+
{{- end }}{{/* not mariadb.enable or postgresql.enabled -> just external*/}}
174+
{{- end }}
175+
176+
{{/*
177+
Redis env vars
178+
*/}}
179+
{{- define "nextcloud.env.redis" -}}
180+
{{- if .Values.redis.enabled }}
181+
- name: REDIS_HOST
182+
value: {{ template "nextcloud.redis.fullname" . }}-master
183+
- name: REDIS_HOST_PORT
184+
value: {{ .Values.redis.master.service.ports.redis | quote }}
185+
{{- if .Values.redis.auth.enabled }}
186+
{{- if and .Values.redis.auth.existingSecret .Values.redis.auth.existingSecretPasswordKey }}
187+
- name: REDIS_HOST_PASSWORD
188+
valueFrom:
189+
secretKeyRef:
190+
name: {{ .Values.redis.auth.existingSecret }}
191+
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
192+
{{- else }}
193+
- name: REDIS_HOST_PASSWORD
194+
value: {{ .Values.redis.auth.password }}
195+
{{- end }}
196+
{{- end }}
197+
{{- else if .Values.externalRedis.enabled }}
198+
- name: REDIS_HOST
199+
value: {{ .Values.externalRedis.host | quote }}
200+
- name: REDIS_HOST_PORT
201+
value: {{ .Values.externalRedis.port | quote }}
202+
{{- if .Values.externalRedis.existingSecret.enabled }}
203+
{{- if and .Values.externalRedis.existingSecret.secretName .Values.externalRedis.existingSecret.passwordKey }}
204+
- name: REDIS_HOST_PASSWORD
205+
valueFrom:
206+
secretKeyRef:
207+
name: {{ .Values.externalRedis.existingSecret.secretName | quote }}
208+
key: {{ .Values.externalRedis.existingSecret.passwordKey | quote }}
209+
{{- end }}
210+
{{- else if .Values.externalRedis.password }}
211+
- name: REDIS_HOST_PASSWORD
212+
value: {{ .Values.externalRedis.password | quote }}
169213
{{- end }}
214+
{{- end }}{{/* end-of redis-enabled*/}}
215+
{{- if or
216+
(and .Values.redis.auth.enabled .Values.redis.auth.password)
217+
(and .Values.redis.auth.enabled .Values.redis.auth.existingSecret .Values.redis.auth.existingSecretPasswordKey)
218+
(and .Values.externalRedis.enabled .Values.externalRedis.existingSecret.secretName .Values.externalRedis.existingSecret.passwordKey)
219+
(and .Values.externalRedis.enabled .Values.externalRedis.password)
220+
}}
221+
- name: REDIS_URL
222+
value: "redis://:$(REDIS_HOST_PASSWORD)@$(REDIS_HOST):$(REDIS_HOST_PORT)"
223+
{{- else }}
224+
- name: REDIS_URL
225+
value: "redis://$(REDIS_HOST):$(REDIS_HOST_PORT)"
226+
{{- end }}{{/* end-of redis-url*/}}
227+
{{- end }}{{/* end-of env.redis definition */}}
228+
229+
{{- define "nextcloud.env" -}}
230+
{{- if .Values.phpClientHttpsFix.enabled }}
231+
- name: OVERWRITEPROTOCOL
232+
value: {{ .Values.phpClientHttpsFix.protocol | quote }}
233+
{{- end }}
234+
{{- template "nextcloud.env.database" . }}
235+
{{- template "nextcloud.env.redis" . }}
170236
- name: NEXTCLOUD_ADMIN_USER
171237
valueFrom:
172238
secretKeyRef:
@@ -221,44 +287,6 @@ Create environment variables used to configure the nextcloud container as well a
221287
key: {{ .Values.nextcloud.existingSecret.smtpPasswordKey }}
222288
{{- end }}
223289
{{/*
224-
Redis env vars
225-
*/}}
226-
{{- if .Values.redis.enabled }}
227-
- name: REDIS_HOST
228-
value: {{ template "nextcloud.redis.fullname" . }}-master
229-
- name: REDIS_HOST_PORT
230-
value: {{ .Values.redis.master.service.ports.redis | quote }}
231-
{{- if .Values.redis.auth.enabled }}
232-
{{- if and .Values.redis.auth.existingSecret .Values.redis.auth.existingSecretPasswordKey }}
233-
- name: REDIS_HOST_PASSWORD
234-
valueFrom:
235-
secretKeyRef:
236-
name: {{ .Values.redis.auth.existingSecret }}
237-
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
238-
{{- else }}
239-
- name: REDIS_HOST_PASSWORD
240-
value: {{ .Values.redis.auth.password }}
241-
{{- end }}
242-
{{- end }}
243-
{{- else if .Values.externalRedis.enabled }}
244-
- name: REDIS_HOST
245-
value: {{ .Values.externalRedis.host | quote }}
246-
- name: REDIS_HOST_PORT
247-
value: {{ .Values.externalRedis.port | quote }}
248-
{{- if .Values.externalRedis.existingSecret.enabled }}
249-
{{- if and .Values.externalRedis.existingSecret.secretName .Values.externalRedis.existingSecret.passwordKey }}
250-
- name: REDIS_HOST_PASSWORD
251-
valueFrom:
252-
secretKeyRef:
253-
name: {{ .Values.externalRedis.existingSecret.secretName | quote }}
254-
key: {{ .Values.externalRedis.existingSecret.passwordKey | quote }}
255-
{{- end }}
256-
{{- else if .Values.externalRedis.password }}
257-
- name: REDIS_HOST_PASSWORD
258-
value: {{ .Values.externalRedis.password | quote }}
259-
{{- end }}
260-
{{- end }}{{/* end if redis.enabled */}}
261-
{{/*
262290
S3 as primary object store env vars
263291
*/}}
264292
{{- if .Values.nextcloud.objectStore.s3.enabled }}
@@ -363,7 +391,6 @@ Swift as primary object store env vars
363391
{{- end }}
364392
{{- end -}}
365393

366-
367394
{{/*
368395
Create volume mounts for the nextcloud container as well as the cron sidecar container.
369396
*/}}

charts/nextcloud/templates/db-secret.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ metadata:
1010
type: Opaque
1111
data:
1212
{{- if .Values.mariadb.enabled }}
13-
db-username: {{ .Values.mariadb.auth.username | b64enc | quote }}
14-
db-password: {{ .Values.mariadb.auth.password | b64enc | quote }}
13+
{{- with .Values.mariadb.auth }}
14+
db-username: {{ .username | b64enc | quote }}
15+
db-password: {{ .password | b64enc | quote }}
16+
{{- end }}
1517
{{- else if .Values.postgresql.enabled }}
16-
db-username: {{ .Values.postgresql.global.postgresql.auth.username | b64enc | quote }}
17-
db-password: {{ .Values.postgresql.global.postgresql.auth.password | b64enc | quote }}
18+
{{- with .Values.postgresql.global.postgresql.auth }}
19+
db-username: {{ .username | b64enc | quote }}
20+
db-password: {{ .password | b64enc | quote }}
21+
{{- end }}
1822
{{- else }}
19-
db-username: {{ .Values.externalDatabase.user | b64enc | quote }}
20-
db-password: {{ .Values.externalDatabase.password | b64enc | quote }}
23+
{{- with .Values.externalDatabase }}
24+
db-username: {{ .user | b64enc | quote }}
25+
db-password: {{ .password | b64enc | quote }}
26+
{{- end }}
2127
{{- end }}
2228
{{- end }}
2329
{{- end }}

charts/nextcloud/templates/deployment.yaml

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,11 @@ spec:
299299
{{- toYaml .securityContext | nindent 12 }}
300300
{{- end }}
301301
env:
302-
- name: MYSQL_USER
303-
valueFrom:
304-
secretKeyRef:
305-
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
306-
key: {{ .Values.externalDatabase.existingSecret.usernameKey }}
307-
- name: MYSQL_PASSWORD
308-
valueFrom:
309-
secretKeyRef:
310-
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
311-
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
302+
{{- include "nextcloud.env.database" . | nindent 12 }}
312303
command:
313304
- "sh"
314305
- "-c"
315-
- {{ printf "until mysql --host=%s-mariadb --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --execute=\"SELECT 1;\"; do echo waiting for mysql; sleep 2; done;" .Release.Name }}
306+
- {{ printf "until mysql --host=${MYSQL_HOST} --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --execute=\"SELECT 1;\"; do echo waiting for mysql; sleep 2; done;" }}
316307
{{- else if .Values.postgresql.enabled }}
317308
- name: postgresql-isready
318309
image: {{ coalesce .Values.global.image.registry .Values.postgresql.image.registry "docker.io" }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
@@ -323,13 +314,7 @@ spec:
323314
{{- toYaml .securityContext | nindent 12 }}
324315
{{- end }}
325316
env:
326-
- name: POSTGRES_USER
327-
valueFrom:
328-
secretKeyRef:
329-
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
330-
key: {{ .Values.externalDatabase.existingSecret.usernameKey }}
331-
- name: POSTGRES_HOST
332-
value: {{ template "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
317+
{{- include "nextcloud.env.database" . | nindent 12 }}
333318
command:
334319
- "sh"
335320
- "-c"

charts/nextcloud/values.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,14 @@ externalDatabase:
468468
## Use a existing secret
469469
existingSecret:
470470
enabled: false
471-
# secretName: nameofsecret
471+
# -- e.g. nameofsecret
472+
secretName:
472473
usernameKey: db-username
473474
passwordKey: db-password
474-
# hostKey: db-hostname-or-ip
475-
# databaseKey: db-name
475+
# -- e.g. db-hostname-or-ip
476+
hostKey:
477+
# -- e.g. db-name
478+
databaseKey:
476479

477480
##
478481
## MariaDB chart configuration
@@ -866,12 +869,13 @@ topologySpreadConstraints: []
866869

867870
affinity: {}
868871

869-
dnsConfig: {}
870-
# Custom dns config for Nextcloud containers.
871-
# You can for example configure ndots. This may be needed in some clusters with alpine images.
872-
# options:
873-
# - name: ndots
874-
# value: "1"
872+
dnsConfig:
873+
# -- Custom dns config for Nextcloud containers.
874+
# You can for example configure ndots. This may be needed in some clusters with alpine images.
875+
# options:
876+
# - name: ndots
877+
# value: "1"
878+
options: []
875879

876880
imaginary:
877881
# -- Start Imgaginary

0 commit comments

Comments
 (0)