Skip to content

Commit

Permalink
make existing secret config more flexible (prometheus-community#705)
Browse files Browse the repository at this point in the history
Signed-off-by: André Bauer <[email protected]>
  • Loading branch information
monotek authored Apr 26, 2021
1 parent f183c48 commit 5f760a0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion charts/prometheus-mysql-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
description: A Helm chart for prometheus mysql exporter with cloudsqlproxy
name: prometheus-mysql-exporter
version: 1.1.0
version: 1.2.0
home: https://github.com/prometheus/mysqld_exporter
appVersion: v0.12.1
sources:
Expand Down
18 changes: 18 additions & 0 deletions charts/prometheus-mysql-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,27 @@ spec:
{{- end }}
]
{{- end }}
{{- if not .Values.mysql.existingSecret }}
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
{{- if .Values.mysql.existingPasswordSecret.name }}
name: {{ .Values.mysql.existingPasswordSecret.name }}
key: {{ .Values.mysql.existingPasswordSecret.key }}
{{- else }}
name: {{ template "prometheus-mysql-exporter.fullname" . }}
key: password
{{- end }}
{{- end }}
{{- if .Values.mysql.existingSecret }}
envFrom:
- secretRef:
name: {{ template "prometheus-mysql-exporter.secret" . }}
{{- else }}
- name: DATA_SOURCE_NAME
value: "{{ .Values.mysql.user }}:$(DB_PASSWORD)@{{ if .Values.mysql.protocol }}{{ .Values.mysql.protocol }}{{ end }}({{ .Values.mysql.host }}:{{ .Values.mysql.port }})/{{ if .Values.mysql.db }}{{ .Values.mysql.db }}{{ end }}{{ if .Values.mysql.param }}?{{ .Values.mysql.param }}{{ end }}"
{{- end }}
ports:
- containerPort: {{ .Values.service.internalPort }}
livenessProbe:
Expand Down
10 changes: 5 additions & 5 deletions charts/prometheus-mysql-exporter/templates/secret-env.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{- if or (not .Values.mysql.existingSecret) }}
{{- if and (not .Values.mysql.existingSecret) (not .Values.mysql.existingPasswordSecret.name) }}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "prometheus-mysql-exporter.fullname" . }}
labels:
{{- include "prometheus-mysql-exporter.labels" . | nindent 4 }}
{{- include "prometheus-mysql-exporter.labels" . | nindent 4 }}
type: Opaque
stringData:
DATA_SOURCE_NAME: "{{ .Values.mysql.user }}:{{ .Values.mysql.pass }}@{{ if .Values.mysql.protocol }}{{ .Values.mysql.protocol }}{{ end }}({{ .Values.mysql.host }}:{{ .Values.mysql.port }})/{{ if .Values.mysql.db }}{{ .Values.mysql.db }}{{ end }}{{ if .Values.mysql.param }}?{{ .Values.mysql.param }}{{ end }}"
{{- end }}
data:
password: "{{ .Values.mysql.pass | b64enc }}"
{{- end }}
7 changes: 6 additions & 1 deletion charts/prometheus-mysql-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ mysql:
port: 3306
protocol: ""
user: "exporter"
existingSecret: false
# secret with full DATA_SOURCE_NAME env var as stringdata
existingSecret: ""
# secret only containing the password
existingPasswordSecret:
name: ""
key: ""

# cloudsqlproxy https://cloud.google.com/sql/docs/mysql/sql-proxy
cloudsqlproxy:
Expand Down

0 comments on commit 5f760a0

Please sign in to comment.