[bitnami/mongodb] Allow configuration of credentials for the metrics exporter (#7311)

* Add configurable credentials for metrics exporter

* Rearrange if clauses

* Rearrange if clauses

* Bump chart version once more

* Only check if metrics username exists

* Add automatic password generation

* Make linter happy

* Update comment for values and connection string

* Version bump
This commit is contained in:
Thilo
2021-09-17 14:22:09 +02:00
committed by GitHub
parent 7e03077e49
commit 2ec31edee1
8 changed files with 87 additions and 4 deletions

View File

@@ -26,4 +26,4 @@ name: mongodb
sources:
- https://github.com/bitnami/bitnami-docker-mongodb
- https://mongodb.org
version: 10.26.1
version: 10.26.2

View File

@@ -413,6 +413,8 @@ Refer to the [chart documentation for more information on each of these architec
| `metrics.image.tag` | MongoDB® Prometheus exporter image tag (immutable tags are recommended) | `0.11.2-debian-10-r266` |
| `metrics.image.pullPolicy` | MongoDB® Prometheus exporter image pull policy | `IfNotPresent` |
| `metrics.image.pullSecrets` | Specify docker-registry secret names as an array | `[]` |
| `metrics.username` | String with username for the metrics exporter | `""` |
| `metrics.password` | String with password for the metrics exporter | `""` |
| `metrics.extraFlags` | String with extra flags to the metrics exporter | `""` |
| `metrics.extraUri` | Additional URI options of the metrics service | `""` |
| `metrics.resources.limits` | The resources limits for Prometheus exporter containers | `{}` |

View File

@@ -346,9 +346,13 @@ Validate values of MongoDB® exporter URI string - auth.enabled and/or tls.en
*/}}
{{- define "mongodb.mongodb_exporter.uri" -}}
{{- $uriTlsArgs := ternary "tls=true&tlsCertificateKeyFile=/certs/mongodb.pem&tlsCAFile=/certs/mongodb-ca-cert" "" .Values.tls.enabled -}}
{{- $uriAuth := ternary "$MONGODB_ROOT_USER:$(echo $MONGODB_ROOT_PASSWORD | sed -r \"s/@/%40/g;s/:/%3A/g\")@" "" .Values.auth.enabled -}}
{{- printf "mongodb://%slocalhost:27017/admin?%s" $uriAuth $uriTlsArgs -}}
{{- if .Values.metrics.username }}
{{- $uriAuth := ternary "$(echo $MONGODB_METRICS_USERNAME | sed -r \"s/@/%40/g;s/:/%3A/g\"):$(echo $MONGODB_METRICS_PASSWORD | sed -r \"s/@/%40/g;s/:/%3A/g\")@" "" .Values.auth.enabled -}}
{{- printf "mongodb://%slocalhost:27017/admin?%s" $uriAuth $uriTlsArgs -}}
{{- else -}}
{{- $uriAuth := ternary "$MONGODB_ROOT_USER:$(echo $MONGODB_ROOT_PASSWORD | sed -r \"s/@/%40/g;s/:/%3A/g\")@" "" .Values.auth.enabled -}}
{{- printf "mongodb://%slocalhost:27017/admin?%s" $uriAuth $uriTlsArgs -}}
{{- end -}}
{{- end -}}

View File

@@ -244,6 +244,10 @@ spec:
- name: MONGODB_DATABASE
value: {{ .Values.auth.database | quote }}
{{- end }}
{{- if .Values.metrics.username }}
- name: MONGODB_METRICS_USERNAME
value: {{ .Values.metrics.username | quote }}
{{- end }}
{{- if .Values.auth.enabled }}
{{- if and .Values.auth.username .Values.auth.database }}
- name: MONGODB_PASSWORD
@@ -252,6 +256,13 @@ spec:
name: {{ include "mongodb.secretName" . }}
key: mongodb-password
{{- end }}
{{- if .Values.metrics.username }}
- name: MONGODB_METRICS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-metrics-password
{{- end }}
- name: MONGODB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
@@ -401,6 +412,7 @@ spec:
{{- end }}
env:
{{- if .Values.auth.enabled }}
{{- if not .Values.metrics.username }}
- name: MONGODB_ROOT_USER
value: {{ .Values.auth.rootUser | quote }}
- name: MONGODB_ROOT_PASSWORD
@@ -408,6 +420,15 @@ spec:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-root-password
{{- else }}
- name: MONGODB_METRICS_USERNAME
value: {{ .Values.metrics.username | quote }}
- name: MONGODB_METRICS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-metrics-password
{{- end }}
{{- end }}
volumeMounts:
{{- if .Values.tls.enabled }}

View File

@@ -249,6 +249,10 @@ spec:
- name: MONGODB_DATABASE
value: {{ .Values.auth.database | quote }}
{{- end }}
{{- if .Values.metrics.username }}
- name: MONGODB_METRICS_USERNAME
value: {{ .Values.metrics.username | quote }}
{{- end }}
{{- if .Values.auth.enabled }}
{{- if and .Values.auth.username .Values.auth.database }}
- name: MONGODB_PASSWORD
@@ -257,6 +261,13 @@ spec:
name: {{ include "mongodb.secretName" . }}
key: mongodb-password
{{- end }}
{{- if .Values.metrics.username }}
- name: MONGODB_METRICS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-metrics-password
{{- end }}
- name: MONGODB_ROOT_USER
value: {{ .Values.auth.rootUser | quote }}
- name: MONGODB_ROOT_PASSWORD
@@ -437,6 +448,7 @@ spec:
{{- end }}
env:
{{- if .Values.auth.enabled }}
{{- if not .Values.metrics.username }}
- name: MONGODB_ROOT_USER
value: {{ .Values.auth.rootUser | quote }}
- name: MONGODB_ROOT_PASSWORD
@@ -444,6 +456,15 @@ spec:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-root-password
{{- else }}
- name: MONGODB_METRICS_USERNAME
value: {{ .Values.metrics.username | quote }}
- name: MONGODB_METRICS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-metrics-password
{{- end }}
{{- end }}
volumeMounts:
{{- if .Values.tls.enabled }}

View File

@@ -26,6 +26,13 @@ data:
mongodb-password: {{ randAlphaNum 10 | b64enc | quote }}
{{- end }}
{{- end }}
{{- if .Values.metrics.username }}
{{- if .Values.metrics.password }}
mongodb-metrics-password: {{ .Values.metrics.password | toString | b64enc | quote }}
{{- else }}
mongodb-metrics-password: {{ randAlphaNum 10 | b64enc | quote }}
{{- end }}
{{- end }}
{{- if eq .Values.architecture "replicaset" }}
{{- if .Values.auth.replicaSetKey }}
mongodb-replica-set-key: {{ .Values.auth.replicaSetKey | toString | b64enc | quote }}

View File

@@ -203,6 +203,10 @@ spec:
- name: MONGODB_DATABASE
value: {{ .Values.auth.database | quote }}
{{- end }}
{{- if .Values.metrics.username }}
- name: MONGODB_METRICS_USERNAME
value: {{ .Values.metrics.username | quote }}
{{- end }}
{{- if .Values.auth.enabled }}
{{- if and .Values.auth.username .Values.auth.database }}
- name: MONGODB_PASSWORD
@@ -211,6 +215,13 @@ spec:
name: {{ include "mongodb.secretName" . }}
key: mongodb-password
{{- end }}
{{- if .Values.metrics.username }}
- name: MONGODB_METRICS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-metrics-password
{{- end }}
- name: MONGODB_ROOT_USER
value: {{ .Values.auth.rootUser | quote }}
- name: MONGODB_ROOT_PASSWORD
@@ -375,6 +386,7 @@ spec:
/bin/mongodb_exporter --web.listen-address ":{{ .Values.metrics.containerPort }}" --mongodb.uri "{{ include "mongodb.mongodb_exporter.uri" . }}" {{ .Values.metrics.extraFlags }}
env:
{{- if .Values.auth.enabled }}
{{- if not .Values.metrics.username }}
- name: MONGODB_ROOT_USER
value: {{ .Values.auth.rootUser | quote }}
- name: MONGODB_ROOT_PASSWORD
@@ -382,6 +394,15 @@ spec:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-root-password
{{- else }}
- name: MONGODB_METRICS_USERNAME
value: {{ .Values.metrics.username | quote }}
- name: MONGODB_METRICS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "mongodb.secretName" . }}
key: mongodb-metrics-password
{{- end }}
{{- end }}
volumeMounts:
{{- if .Values.tls.enabled }}

View File

@@ -1512,6 +1512,13 @@ metrics:
## - myRegistryKeySecretName
##
pullSecrets: []
## @param metrics.username String with username for the metrics exporter
## If undefined the root user will be used for the metrics exporter
username: ""
## @param metrics.password String with password for the metrics exporter
## If undefined but metrics.username is defined, a random password will be generated
password: ""
## @param metrics.extraFlags String with extra flags to the metrics exporter
## ref: https://github.com/percona/mongodb_exporter/blob/master/mongodb_exporter.go
##