Skip to content

Commit

Permalink
fix(env): move DATABASE_URL and REDIS_URL to env helper
Browse files Browse the repository at this point in the history
Signed-off-by: WrenIX <dev.github@wrenix.eu>
  • Loading branch information
wrenix committed Dec 19, 2024
1 parent a0e3854 commit a6d5be4
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 60 deletions.
76 changes: 48 additions & 28 deletions charts/nextcloud/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ Create image name that is used in the deployment
{{/*
Create environment variables used to configure the nextcloud container as well as the cron sidecar container.
*/}}
{{- define "nextcloud.env" -}}
{{- if .Values.phpClientHttpsFix.enabled }}
- name: OVERWRITEPROTOCOL
value: {{ .Values.phpClientHttpsFix.protocol | quote }}
{{- end }}
{{- define "nextcloud.env.database" -}}
{{- if .Values.internalDatabase.enabled }}
- name: SQLITE_DATABASE
value: {{ .Values.internalDatabase.name | quote }}
Expand All @@ -87,6 +83,8 @@ Create environment variables used to configure the nextcloud container as well a
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
- name: DATABASE_URL
value: "mysql://$(MYSQL_USER):$(MYSQL_PASSWORD)@$(MYSQL_HOST)/$(MYSQL_DATABASE)"
{{- else if .Values.postgresql.enabled }}
- name: POSTGRES_HOST
value: {{ template "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
Expand All @@ -106,7 +104,9 @@ Create environment variables used to configure the nextcloud container as well a
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
{{- else }}
- name: DATABASE_URL
value: "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST)/$(POSTGRES_DB)"
{{- else }}{{/* mariadb.enable or postgresql.enabled -> now external */}}
{{- if eq .Values.externalDatabase.type "postgresql" }}
- name: POSTGRES_HOST
{{- if .Values.externalDatabase.existingSecret.hostKey }}
Expand Down Expand Up @@ -136,7 +136,9 @@ Create environment variables used to configure the nextcloud container as well a
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
{{- else }}
- name: DATABASE_URL
value: "postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST)/$(POSTGRES_DB)"
{{- else }}{{/* external.type = postgresql */}}
- name: MYSQL_HOST
{{- if .Values.externalDatabase.existingSecret.hostKey }}
valueFrom:
Expand Down Expand Up @@ -165,8 +167,45 @@ Create environment variables used to configure the nextcloud container as well a
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
{{- end }}
- name: DATABASE_URL
value: "mysql://$(MYSQL_USER):$(MYSQL_PASSWORD)@$(MYSQL_HOST)/$(MYSQL_DATABASE)"
{{- end }}{{/* external.type = postgresql */}}
{{- end }}{{/* not mariadb.enable or postgresql.enabled -> just external*/}}
{{- end }}

{{/*
Redis env vars
*/}}
{{- define "nextcloud.env.redis" -}}
- name: REDIS_HOST
value: {{ template "nextcloud.redis.fullname" . }}-master
- name: REDIS_HOST_PORT
value: {{ .Values.redis.master.service.ports.redis | quote }}
{{- if .Values.redis.auth.enabled }}
{{- if and .Values.redis.auth.existingSecret .Values.redis.auth.existingSecretPasswordKey }}
- name: REDIS_HOST_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.redis.auth.existingSecret }}
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
{{- else }}
- name: REDIS_HOST_PASSWORD
value: {{ .Values.redis.auth.password }}
{{- end }}
- name: REDIS_URL
value: "redis://:$(REDIS_HOST_PASSWORD)@$(REDIS_HOST):$(REDIS_HOST_PORT)"
{{- else }}
- name: REDIS_URL
value: "redis://$(REDIS_HOST):$(REDIS_HOST_PORT)"
{{- end }}
{{- end }}

{{- define "nextcloud.env" -}}
{{- if .Values.phpClientHttpsFix.enabled }}
- name: OVERWRITEPROTOCOL
value: {{ .Values.phpClientHttpsFix.protocol | quote }}
{{- end }}
{{- template "nextcloud.env.database" . }}
- name: NEXTCLOUD_ADMIN_USER
valueFrom:
secretKeyRef:
Expand Down Expand Up @@ -216,26 +255,8 @@ Create environment variables used to configure the nextcloud container as well a
name: {{ .Values.nextcloud.existingSecret.secretName | default (include "nextcloud.fullname" .) }}
key: {{ .Values.nextcloud.existingSecret.smtpPasswordKey }}
{{- end }}
{{/*
Redis env vars
*/}}
{{- if .Values.redis.enabled }}
- name: REDIS_HOST
value: {{ template "nextcloud.redis.fullname" . }}-master
- name: REDIS_HOST_PORT
value: {{ .Values.redis.master.service.ports.redis | quote }}
{{- if .Values.redis.auth.enabled }}
{{- if and .Values.redis.auth.existingSecret .Values.redis.auth.existingSecretPasswordKey }}
- name: REDIS_HOST_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.redis.auth.existingSecret }}
key: {{ .Values.redis.auth.existingSecretPasswordKey }}
{{- else }}
- name: REDIS_HOST_PASSWORD
value: {{ .Values.redis.auth.password }}
{{- end }}
{{- end }}
{{ template "nextcloud.env.redis" . }}
{{- end }}{{/* end if redis.enabled */}}
{{/*
S3 as primary object store env vars
Expand Down Expand Up @@ -342,7 +363,6 @@ Swift as primary object store env vars
{{- end }}
{{- end -}}


{{/*
Create volume mounts for the nextcloud container as well as the cron sidecar container.
*/}}
Expand Down
3 changes: 0 additions & 3 deletions charts/nextcloud/templates/db-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ data:
{{- with .Values.mariadb.auth }}
db-username: {{ .username | b64enc | quote }}
db-password: {{ .password | b64enc | quote }}
db-url: {{ printf "mysql://%s:%s@%s/%s" .username .password (include "mariadb.primary.fullname" $.Subcharts.mariadb) .database | b64enc | quote }}
{{- end }}
{{- else if .Values.postgresql.enabled }}
{{- with .Values.postgresql.global.postgresql.auth }}
db-username: {{ .username | b64enc | quote }}
db-password: {{ .password | b64enc | quote }}
db-url: {{ printf "postgres://%s:%s@%s/%s" .username .password (include "postgresql.v1.primary.fullname" $.Subcharts.postgresql) .database | b64enc | quote }}
{{- end }}
{{- else }}
{{- with .Values.externalDatabase }}
db-username: {{ .user | b64enc | quote }}
db-password: {{ .password | b64enc | quote }}
db-url: {{ printf "%s://%s:%s@%s/%s" .type .user .password .host .database | b64enc | quote }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
25 changes: 5 additions & 20 deletions charts/nextcloud/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -300,45 +300,30 @@ spec:
{{- end }}
{{- if .Values.mariadb.enabled }}
- name: mariadb-isalive
image: {{ .Values.mariadb.image.registry | default "docker.io" }}/{{ .Values.mariadb.image.repository }}:{{ .Values.mariadb.image.tag }}
image: {{ .Values.mariadb.image.registry }}/{{ .Values.mariadb.image.repository }}:{{ .Values.mariadb.image.tag }}
{{- with .Values.nextcloud.mariaDbInitContainer }}
resources:
{{- toYaml .resources | nindent 12 }}
securityContext:
{{- toYaml .securityContext | nindent 12 }}
{{- end }}
env:
- name: MYSQL_USER
valueFrom:
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.usernameKey }}
- name: MYSQL_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.passwordKey }}
{{- include "nextcloud.env.database" . | nindent 12 }}
command:
- "sh"
- "-c"
- {{ 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 }}
- {{ printf "until mysql --host=${MYSQL_HOST} --user=${MYSQL_USER} --password=${MYSQL_PASSWORD} --execute=\"SELECT 1;\"; do echo waiting for mysql; sleep 2; done;" }}
{{- else if .Values.postgresql.enabled }}
- name: postgresql-isready
image: {{ .Values.postgresql.image.registry | default "docker.io" }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
image: {{ .Values.postgresql.image.registry }}/{{ .Values.postgresql.image.repository }}:{{ .Values.postgresql.image.tag }}
{{- with .Values.nextcloud.postgreSqlInitContainer }}
resources:
{{- toYaml .resources | nindent 12 }}
securityContext:
{{- toYaml .securityContext | nindent 12 }}
{{- end }}
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.usernameKey }}
- name: POSTGRES_HOST
value: {{ template "postgresql.v1.primary.fullname" .Subcharts.postgresql }}
{{- include "nextcloud.env.database" . | nindent 12 }}
command:
- "sh"
- "-c"
Expand Down
17 changes: 10 additions & 7 deletions charts/nextcloud/templates/notify_push/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,16 @@ spec:
value: "7867"
- name: METRICS_PORT
value: "9867"
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: {{ .Values.externalDatabase.existingSecret.secretName | default (printf "%s-db" .Release.Name) }}
key: {{ .Values.externalDatabase.existingSecret.databaseURLKey }}
- name: REDIS_URL
value: "redis://{{ if .Values.redis.auth.enabled }}:{{ .Values.redis.auth.password }}@{{ end }}{{ template "nextcloud.redis.fullname" . }}-master:{{ .Values.redis.master.service.ports.redis }}"
{{- include "nextcloud.env.database" . | nindent 12 }}
{{- with .Values.notifyPush.redisURLEnv }}
- name: "REDIS_URL"
{{- toYaml . | nindent 14 }}
{{- else }}
{{- if not .Values.redis.enabled }}
{{- fail "notify-push needs an redis (redis.enabled=true or notifyPush.redisURLEnv={...})" }}
{{- end }}
{{- include "nextcloud.env.redis" . | nindent 12 }}
{{- end }}
- name: NEXTCLOUD_URL # deployment.namespace.svc.cluster.local
value: "http{{ if .Values.notifyPush.https }}s{{ end }}://{{ template "nextcloud.fullname" . }}.{{ .Release.Namespace }}.svc.cluster.local:{{ .Values.service.port }}"
ports:
Expand Down
8 changes: 8 additions & 0 deletions charts/nextcloud/test-values/notify_push.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
redis:
enabled: true

internalDatabase:
enabled: false
mariadb:
enabled: true

notifyPush:
enabled: true
9 changes: 7 additions & 2 deletions charts/nextcloud/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,6 @@ externalDatabase:
hostKey:
# -- e.g. db-name
databaseKey:
# -- complete URL with type, username and password (current only for notify_push used)
databaseURLKey: db-url

##
## MariaDB chart configuration
Expand All @@ -421,6 +419,9 @@ mariadb:
# To use an ALREADY DEPLOYED mariadb database, set this to false and configure the externalDatabase parameters
enabled: false

image:
registry: "docker.io"

# see: https://github.com/bitnami/charts/tree/main/bitnami/mariadb#global-parameters
global:
# overwrites the primary.persistence.storageClass value
Expand Down Expand Up @@ -454,6 +455,8 @@ mariadb:
##
postgresql:
enabled: false
image:
registry: "docker.io"
global:
postgresql:
# global.postgresql.auth overrides postgresql.auth
Expand Down Expand Up @@ -705,6 +708,8 @@ notifyPush:
pullPolicy: IfNotPresent
pullSecrets:
# - myRegistrKeySecretName
# -- option to set the redis_url per env (if a external redis is used) e.g.: `value: ""` or `valueFrom: {secretKeyRef:{name:"",key:""}}`
redisURLEnv:

resources: {}

Expand Down

0 comments on commit a6d5be4

Please sign in to comment.