Skip to content

Commit 0a05cdc

Browse files
committed
feat: separate database credentials from configuration
- 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 0a05cdc

5 files changed

Lines changed: 40 additions & 18 deletions

File tree

38 KB
Binary file not shown.

charts/devlake/templates/_helpers.tpl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,6 @@ The database port
165165
{{- end }}
166166

167167

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-
178168
{{/*
179169
The probe for check database connection
180170
*/}}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.fullname" . }}-config
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_LOCATION: "{{ .Values.commonEnvs.TZ }}"
33+
{{- 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.fullname" . }}-config
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=utf8mb4&parseTime=True&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

0 commit comments

Comments
 (0)