Skip to content

Commit b06d736

Browse files
fix: install DB job to use external credentials when available
1 parent 3422042 commit b06d736

7 files changed

Lines changed: 100 additions & 28 deletions

File tree

tbmq/templates/_helpers.tpl

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@
7676
{{/*Return redis cluster configurations environment variables for tbmq services*/}}
7777
{{- define "tbmq.redis.configuration.ref"}}
7878
- configMapRef:
79-
name: {{ .Release.Name }}-redis-config
80-
{{- end}}
79+
name: {{ .Values.externalRedis.existingConfigMap | default (printf "%s-redis-config" .Release.Name) }}
80+
{{- end }}
8181

8282
{{/*Returns redis cluster secret name*/}}
8383
{{- define "tbmq.redis.secretName" -}}
8484
{{- $redis := index .Values "redis-cluster" }}
85+
{{- if not $redis.enabled -}}
86+
{{- .Values.externalRedis.existingSecret -}}
87+
{{- else -}}
8588
{{- if $redis.existingSecret }}
8689
{{- $redis.existingSecret }}
8790
{{- else if $redis.fullnameOverride }}
@@ -92,18 +95,19 @@
9295
{{- printf "%s-redis-cluster" .Release.Name }}
9396
{{- end }}
9497
{{- end }}
98+
{{- end }}
9599

96100
{{/*Returns redis cluster secret key*/}}
97101
{{- define "tbmq.redis.secretKey" -}}
98102
{{- $redis := index .Values "redis-cluster" }}
99-
{{- if $redis.existingSecret -}}
103+
{{- if not $redis.enabled }}
104+
{{- .Values.externalRedis.existingSecretKey -}}
105+
{{- else if $redis.existingSecret}}
100106
{{ $redis.existingSecretPasswordKey | default "REDIS_PASSWORD" }}
101107
{{- else -}}
102108
redis-password
103-
{{- end -}}
104109
{{- end }}
105-
106-
110+
{{- end }}
107111

108112
{{/*Return redis cluster nodes*/}}
109113
{{- define "tbmq.redis.nodes" -}}
@@ -119,13 +123,17 @@ redis-password
119123
{{/*Return postgresql configurations environment variables for tbmq services*/}}
120124
{{- define "tbmq.postgres.configuration.ref"}}
121125
- configMapRef:
122-
name: {{ .Release.Name }}-postgres-config
123-
{{- end}}
126+
name: {{ .Values.externalPostgresql.existingConfigMap | default (printf "%s-postgres-config" .Release.Name) }}
127+
{{- end }}
124128

125129
{{/*Return postgresql secret name*/}}
126130
{{- define "tbmq.postgres.secretName" -}}
127131
{{- if not .Values.postgresql.enabled }}
132+
{{- if .Values.externalPostgresql.existingSecret }}
133+
{{- .Values.externalPostgresql.existingSecret }}
134+
{{- else -}}
128135
{{- printf "%s-postgres-external" .Release.Name }}
136+
{{- end }}
129137
{{- else if .Values.postgresql.auth.existingSecret }}
130138
{{- .Values.postgresql.auth.existingSecret }}
131139
{{- else if .Values.postgresql.fullnameOverride }}
@@ -137,10 +145,15 @@ redis-password
137145
{{- end }}
138146
{{- end }}
139147

148+
140149
{{/*Return postgresql secret key*/}}
141-
{{- define "tbmq.postgres.secretKey" -}}
150+
{{- define "tbmq.postgres.secretPasswordKey" -}}
142151
{{- if not .Values.postgresql.enabled -}}
152+
{{- if .Values.externalPostgresql.existingSecretPasswordKey -}}
153+
{{- .Values.externalPostgresql.existingSecretPasswordKey -}}
154+
{{- else -}}
143155
external-postgres-password
156+
{{- end }}
144157
{{- else if .Values.postgresql.auth.existingSecret }}
145158
{{- if and .Values.postgresql.auth.enablePostgresUser (not .Values.postgresql.auth.username) -}}
146159
{{- .Values.postgresql.auth.secretKeys.adminPasswordKey }}
@@ -156,6 +169,17 @@ external-postgres-password
156169
{{- end -}}
157170
{{- end }}
158171

172+
{{/*Return postgresql secret key*/}}
173+
{{- define "tbmq.postgres.secretUsernameKey" -}}
174+
{{- if not .Values.postgresql.enabled -}}
175+
{{- if .Values.externalPostgresql.existingSecretUsernameKey -}}
176+
{{- .Values.externalPostgresql.existingSecretUsernameKey -}}
177+
{{- else -}}
178+
external-postgres-username
179+
{{- end }}
180+
{{- end }}
181+
{{- end }}
182+
159183
{{/*Return postgres host*/}}
160184
{{- define "tbmq.postgres.host" -}}
161185
{{- if .Values.postgresql.enabled -}}
@@ -204,8 +228,8 @@ external-postgres-password
204228
{{/*Return kafka configurations environment variables for tbmq services*/}}
205229
{{- define "tbmq.kafka.configuration.ref"}}
206230
- configMapRef:
207-
name: {{ .Release.Name }}-kafka-config
208-
{{- end}}
231+
name: {{ .Values.externalKafka.existingConfigMap | default (printf "%s-kafka-config" .Release.Name) }}
232+
{{- end }}
209233

210234
{{/*Return kafka servers environment variables for tbmq services*/}}
211235
{{- define "tbmq.kafka.servers" -}}
@@ -238,15 +262,20 @@ external-postgres-password
238262
value: {{ include "tbmq.postgres.host" . | quote }}
239263
- name: PGDATABASE
240264
value: {{ include "tbmq.postgres.database" . | quote }}
241-
- name: PGUSER
242-
value: {{ include "tbmq.postgres.username" . | quote }}
243265
- name: QUERY_TO_VALIDATE_DATA
244266
value: {{ $query | quote }}
245267
- name: PGPASSWORD
246268
valueFrom:
247269
secretKeyRef:
248270
name: {{ include "tbmq.postgres.secretName" . }}
249-
key: {{ include "tbmq.postgres.secretKey" . }}
271+
key: {{ include "tbmq.postgres.secretPasswordKey" . }}
272+
{{- if .Values.externalPostgresql.existingSecretUsernameKey }}
273+
- name: PGUSER
274+
valueFrom:
275+
secretKeyRef:
276+
name: {{ include "tbmq.postgres.secretName" . }}
277+
key: {{ include "tbmq.postgres.secretUsernameKey" . }}
278+
{{- end }}
250279
command:
251280
- bash
252281
args:

tbmq/templates/install/post-install-job.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,15 @@ spec:
7474
valueFrom:
7575
secretKeyRef:
7676
name: {{ include "tbmq.postgres.secretName" . }}
77-
key: {{ include "tbmq.postgres.secretKey" . }}
78-
{{- if index .Values "redis-cluster" "usePassword" }}
77+
key: {{ include "tbmq.postgres.secretPasswordKey" . }}
78+
{{- if .Values.externalPostgresql.existingSecretUsernameKey }}
79+
- name: SPRING_DATASOURCE_USER
80+
valueFrom:
81+
secretKeyRef:
82+
name: {{ include "tbmq.postgres.secretName" . }}
83+
key: {{ include "tbmq.postgres.secretUsernameKey" . }}
84+
{{- end }}
85+
{{- if or (index .Values "redis-cluster" "usePassword") .Values.externalRedis.existingSecret }}
7986
- name: REDIS_PASSWORD
8087
valueFrom:
8188
secretKeyRef:

tbmq/templates/kafka/kafka-configmap.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if empty .Values.kafka.existingConfigMap }}
1+
{{- if and (empty .Values.kafka.existingConfigMap) .Values.kafka.enabled }}
22
{{- $namespace := .Release.Namespace -}}
33
{{- $releaseName := .Release.Name }}
44
apiVersion: v1

tbmq/templates/postgres/postgres-secret.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if not .Values.postgresql.enabled }}
1+
{{- if and (not .Values.postgresql.enabled) (not .Values.externalPostgresql.existingSecret) }}
22
{{- $namespace := .Release.Namespace -}}
33
{{- $releaseName := .Release.Name }}
44
apiVersion: v1

tbmq/templates/redis/redis-configmap.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if empty (index .Values "redis-cluster" "existingConfigMap") }}
1+
{{- if and (empty (index .Values "redis-cluster" "existingConfigMap")) (index .Values "redis-cluster" "enabled") }}
22
{{- $namespace := .Release.Namespace -}}
33
{{- $releaseName := .Release.Name }}
44
{{- $redisName := index .Values "redis-cluster" "nameOverride" }}

tbmq/templates/tbmq/tbmq-statefulset.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,15 @@ spec:
8181
valueFrom:
8282
secretKeyRef:
8383
name: {{ include "tbmq.postgres.secretName" . }}
84-
key: {{ include "tbmq.postgres.secretKey" . }}
85-
{{- if index .Values "redis-cluster" "usePassword" }}
84+
key: {{ include "tbmq.postgres.secretPasswordKey" . }}
85+
{{- if .Values.externalPostgresql.existingSecretUsernameKey }}
86+
- name: SPRING_DATASOURCE_USER
87+
valueFrom:
88+
secretKeyRef:
89+
name: {{ include "tbmq.postgres.secretName" . }}
90+
key: {{ include "tbmq.postgres.secretUsernameKey" . }}
91+
{{- end }}
92+
{{- if or (index .Values "redis-cluster" "usePassword") .Values.externalRedis.existingSecret }}
8693
- name: REDIS_PASSWORD
8794
valueFrom:
8895
secretKeyRef:
@@ -144,4 +151,4 @@ spec:
144151
- name: {{ $releaseName }}-tbmq-node-logs
145152
emptyDir: { }
146153
- name: {{ printf "%s-tbmq-node-data" $releaseName }}
147-
emptyDir: { }
154+
emptyDir: { }

tbmq/values.yaml

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,13 @@ tbmq-ie:
368368
# This section will bring bitnami/redis-cluster (https://artifacthub.io/packages/helm/bitnami/redis-cluster) into this chart.
369369
# If you want to add some extra configuration parameters, you can put them under the `redis-cluster` key, and they will be passed to bitnami/redis-cluster chart.
370370
redis-cluster:
371+
enabled: true
371372
## @param nameOverride String to partially override common.names.fullname template (will maintain the release name)
372373
##
373374
nameOverride: "redis"
375+
## @param Should use password?
376+
##
377+
usePassword: false
374378
## @param password Redis® password (ignored if existingSecret set)
375379
## Defaults to a random 10-character alphanumeric string if not set and usePassword is true
376380
## ref: https://github.com/bitnami/containers/tree/main/bitnami/redis#setting-the-server-password-on-first-run
@@ -381,7 +385,7 @@ redis-cluster:
381385
existingSecret: ""
382386
## @param existingSecretPasswordKey Name of key containing password to be retrieved from the existing secret
383387
##
384-
existingSecretPasswordKey: ""
388+
existingSecretKey: ""
385389
## Pod Disruption Budget configuration
386390
## ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/
387391
##
@@ -396,7 +400,6 @@ redis-cluster:
396400
## @section Redis® statefulset parameters
397401
##
398402
redis:
399-
enabled: true
400403
## @param redis.useAOFPersistence Whether to use AOF Persistence mode or not
401404
## It is strongly recommended to use this type when dealing with clusters
402405
## ref: https://redis.io/topics/persistence#append-only-file
@@ -523,6 +526,18 @@ redis-cluster:
523526
##
524527
resources: {}
525528

529+
# If you're deploying Redis externally, configure this section
530+
externalRedis:
531+
# param existingConfigMap Name of an existing ConfigMap that will override Redis configurations.
532+
##
533+
existingConfigMap: ""
534+
# @param existingSecret Name of existing secret object (for password authentication)
535+
##
536+
existingSecret: ""
537+
# @param existingSecretKey Name of key containing password to be retrieved from the existing secret
538+
##
539+
existingSecretKey: ""
540+
526541
# If you're deploying PostgreSQL externally, configure this section
527542
externalPostgresql:
528543
# @param host - External PostgreSQL server host
@@ -539,12 +554,28 @@ externalPostgresql:
539554
# @param database - PostgreSQL database name for TBMQ
540555
##
541556
database: "thingsboard_mqtt_broker"
557+
# param existingConfigMap Name of an existing ConfigMap that will override Postgres configurations.
558+
##
559+
existingConfigMap: ""
560+
# @param existingSecret - existing secret having the credentials to the Postgresql database instance
561+
##
562+
existingSecret: ""
563+
# @param existingSecretPasswordKey - key in existing secret having the credentials to the Postgresql database instance
564+
##
565+
existingSecretPasswordKey: ""
566+
# @param existingSecretUsernameKey - key in existing secret having the credentials to the Postgresql database instance
567+
##
568+
existingSecretUsernameKey: ""
569+
570+
externalKafka:
571+
# Name of an existing ConfigMap that will override Kafka configurations.
572+
existingConfigMap: ""
542573

543574
# This section will bring bitnami/postgresql (https://artifacthub.io/packages/helm/bitnami/postgresql) into this chart.
544575
# If you want to add some extra configuration parameters, you can put them under the `postgresql` key, and they will be passed to bitnami/postgresql chart
545576
postgresql:
546577
# @param enabled If enabled is set to true, externalPostgresql configuration will be ignored
547-
enabled: true
578+
enabled: false
548579
## @param nameOverride String to partially override common.names.fullname template (will maintain the release name)
549580
##
550581
nameOverride: "postgresql"
@@ -812,8 +843,6 @@ kafka:
812843
## memory: 1024Mi
813844
##
814845
resources: {}
815-
# Name of an existing ConfigMap that will override Kafka configurations.
816-
existingConfigMap: ""
817846
# Load Balancer Configuration
818847
# This section defines the load balancer settings for TBMQ.
819848
# Supported types:
@@ -835,7 +864,7 @@ loadbalancer:
835864
annotations: {}
836865
ssl:
837866
# Hosts to be configured for the ingress.
838-
hosts: {}
867+
hosts: []
839868
# Secret name with the certificate for the ssl termination.
840869
secretName: ""
841870
# Enables HTTPS termination at the load balancer level.

0 commit comments

Comments
 (0)