Skip to content

Commit 42e02ad

Browse files
authored
feat: separate database credentials from configuration (#337)
- Move non-sensitive database config to ConfigMap - Keep only passwords in Secret for better ExternalSecret integration - Add configMapRef to deployment envFrom section This change allows users to inject only passwords via ExternalSecret while keeping database configuration in ConfigMap, following Kubernetes best practices.
1 parent 4073c79 commit 42e02ad

6 files changed

Lines changed: 50 additions & 18 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
17+
*.tgz

charts/devlake/templates/_helpers.tpl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ The ui endpoint
104104
{{- end -}}
105105
{{- end -}}
106106

107+
{{- define "devlake.mysql.configmap" -}}
108+
{{ include "devlake.fullname" . }}-config
109+
{{- end -}}
110+
107111
{{- define "devlake.ui.auth.secret" -}}
108112
{{- if .Values.ui.basicAuth.secretName -}}
109113
{{- .Values.ui.basicAuth.secretName -}}
@@ -165,16 +169,6 @@ The database port
165169
{{- end }}
166170

167171

168-
{{/*
169-
The database url
170-
*/}}
171-
{{- define "database.url" -}}
172-
{{- if eq .Values.option.database "mysql" -}}
173-
mysql://{{ .Values.mysql.username }}:{{ .Values.mysql.password }}@{{ include "mysql.server" . }}:{{ include "mysql.port" . }}/{{ .Values.mysql.database }}?charset=utf8mb4&parseTime=True&loc={{ .Values.commonEnvs.TZ }}
174-
{{- end }}
175-
{{- end }}
176-
177-
178172
{{/*
179173
The probe for check database connection
180174
*/}}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
---
18+
apiVersion: v1
19+
kind: ConfigMap
20+
metadata:
21+
name: {{ include "devlake.mysql.configmap" . }}
22+
labels:
23+
{{- include "devlake.labels" . | nindent 4 }}
24+
data:
25+
# Database connection configuration (non-sensitive)
26+
{{- if (eq .Values.option.database "mysql") }}
27+
MYSQL_USER: "{{ .Values.mysql.username }}"
28+
MYSQL_DATABASE: "{{ .Values.mysql.database }}"
29+
MYSQL_URL: "{{ include "mysql.server" . }}:{{ include "mysql.port" . }}"
30+
MYSQL_SERVER: "{{ include "mysql.server" . }}"
31+
MYSQL_PORT: "{{ include "mysql.port" . }}"
32+
DB_CHARSET: "utf8mb4"
33+
DB_PARSE_TIME: "True"
34+
DB_LOCATION: "{{ .Values.commonEnvs.TZ }}"
35+
{{- end }}

charts/devlake/templates/deployments.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ spec:
162162
{{- with .Values.lake.containerSecurityContext }}
163163
securityContext:
164164
{{- toYaml . | nindent 12 }}
165-
{{- end }}
165+
{{- end }}
166166
containers:
167167
- name: lake
168168
{{- if .Values.lake.image.tag }}
@@ -182,6 +182,8 @@ spec:
182182
{{- toYaml . | nindent 12 }}
183183
{{- end }}
184184
envFrom:
185+
- configMapRef:
186+
name: {{ include "devlake.mysql.configmap" . }}
185187
- secretRef:
186188
name: {{ include "devlake.mysql.secret" . }}
187189
- secretRef:
@@ -193,6 +195,10 @@ spec:
193195
env:
194196
- name: PORT
195197
value: "{{ .Values.lake.port }}"
198+
{{- if (eq .Values.option.database "mysql") }}
199+
- name: DB_URL
200+
value: "mysql://$(MYSQL_USER):$(MYSQL_PASSWORD)@$(MYSQL_SERVER):$(MYSQL_PORT)/$(MYSQL_DATABASE)?charset=$(DB_CHARSET)&parseTime=$(DB_PARSE_TIME)&loc=$(DB_LOCATION)"
201+
{{- end }}
196202
{{- range $key1, $value1 := .Values.lake.envs }}
197203
- name: "{{ tpl $key1 $ }}"
198204
value: "{{ tpl (print $value1) $ }}"

charts/devlake/templates/secrets.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@ metadata:
2222
name: {{ include "devlake.mysql.secret" . }}
2323
stringData:
2424
{{- if (eq .Values.option.database "mysql") }}
25-
MYSQL_USER: "{{ .Values.mysql.username }}"
2625
MYSQL_PASSWORD: "{{ .Values.mysql.password }}"
27-
MYSQL_DATABASE: "{{ .Values.mysql.database }}"
2826
MYSQL_ROOT_PASSWORD: "{{ .Values.mysql.rootPassword }}"
29-
DB_URL: "{{ include "database.url" . }}"
30-
MYSQL_URL: "{{ include "mysql.server" . }}:{{ include "mysql.port" . }}"
3127
#{{- else if (eq .Values.option.database "pgsql")}}
32-
# POSTGRES_USER: "{{ .Values.pgsql.username }}"
3328
# POSTGRES_PASSWORD: "{{ .Values.pgsql.password }}"
34-
# POSTGRES_DB: "{{ .Values.pgsql.database }}"
35-
# DB_URL: "{{ include "database.url" . }}"
3629
{{- end }}
3730
{{- end }}
3831

charts/devlake/templates/statefulsets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ spec:
9090
{{- toYaml . | nindent 12 }}
9191
{{- end }}
9292
envFrom:
93+
- configMapRef:
94+
name: {{ include "devlake.mysql.configmap" . }}
9395
- secretRef:
9496
name: {{ include "devlake.mysql.secret" . }}
9597
env:

0 commit comments

Comments
 (0)