prometheus-community/helm-charts

[prometheus-postgres-exporter] Add support for `DATA_SOURCE_USER_FILE` environmental variable

ubajze opened this issue · 0 comments

Is your feature request related to a problem ?

We use Vault dynamic database secrets, where both username and password are dynamically generated. We then use a Vault injector to inject a username and password into a pod as a file. I see that Postgres exporter supports the variable DATA_SOURCE_USER_FILE, where you specify the name of the file where the username is rendered. This is currently not supported in config:

config:
## The datasource properties on config are passed through helm tpl function.
## ref: https://helm.sh/docs/developing_charts/#using-the-tpl-function
datasource:
# Specify one of both datasource or datasourceSecret
host: ''
user: postgres
userSecret: {}
# Secret name
# name:
# User key inside secret
# key:
# Only one of password, passwordFile, passwordSecret and pgpassfile can be specified
password:
# Specify passwordFile if DB password is stored in a file.
# For example, to use with vault-injector from Hashicorp
passwordFile: ''
# Specify passwordSecret if DB password is stored in secret.
passwordSecret: {}
# Secret name
# name:
# Password key inside secret
# key:
pgpassfile: ''
# If pgpassfile is set, it is used to initialize the PGPASSFILE environment variable.
# See https://www.postgresql.org/docs/14/libpq-pgpass.html for more info.
port: "5432"
database: ''
sslmode: disable
extraParams: ''

Describe the solution you'd like.

I want to specify the filename in a configuration. This is how the configuration should look like:

config:
  datasource:
    usernameFile: "/path/to/my/user/file"

The template would look similar to this:

{{- if .Values.config.datasource.passwordFile }}
- name: DATA_SOURCE_PASS_FILE
value: {{ tpl .Values.config.datasource.passwordFile . }}
{{- else }}
- name: DATA_SOURCE_PASS
valueFrom:
secretKeyRef:
{{- if .Values.config.datasource.passwordSecret }}
name: {{ tpl .Values.config.datasource.passwordSecret.name . }}
key: {{ tpl .Values.config.datasource.passwordSecret.key . }}
{{- else }}
name: {{ template "prometheus-postgres-exporter.fullname" . }}
key: data_source_password

          {{- if .Values.config.datasource.usernameFile }}
          - name: DATA_SOURCE_USER_FILE
            value: {{ tpl .Values.config.datasource.usernameFile . }}
          {{- else }}
          - name: DATA_SOURCE_USER
            valueFrom:
              secretKeyRef:
          {{- if .Values.config.datasource.usernameSecret }}
                name: {{ tpl .Values.config.datasource.usernameSecret.name . }}
                key: {{ tpl .Values.config.datasource.usernameSecret.key . }}
          {{- else }}
                name: {{ template "prometheus-postgres-exporter.fullname" . }}
                key: data_source_password

Describe alternatives you've considered.

I can manually set the environmental variable:

extraEnvs:
  - name: "DATA_SOURCE_USER_FILE"
    value: "/path/to/my/user/file"

Additional context.

No response