From ac3f8abcc626eaf279666ddaff2358cee6ea0379 Mon Sep 17 00:00:00 2001 From: Benedict Harcourt Date: Wed, 6 May 2026 14:19:16 +0000 Subject: [PATCH] [consul-exporter] Support using environment variables in command args To increase the flexibility for options and arguments in the chart, this change adds a flag `invokeViaShell` to the values. When enabled the `consul_exporter` is not directly executed by kubernetes. Instead the same command is passed to `/bin/sh`, which will replace any environment variables. This allows users to pull in options from secrets on the cluster; kubernetes's downwardApi systems; or other environment ephemera. The option is disabled by default. Fixes: #6896 Signed-off-by: Benedict Harcourt --- charts/prometheus-consul-exporter/Chart.yaml | 2 +- .../prometheus-consul-exporter/templates/deployment.yaml | 7 +++++++ charts/prometheus-consul-exporter/values.yaml | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/charts/prometheus-consul-exporter/Chart.yaml b/charts/prometheus-consul-exporter/Chart.yaml index b1ff95f95da2..dae0a008a458 100644 --- a/charts/prometheus-consul-exporter/Chart.yaml +++ b/charts/prometheus-consul-exporter/Chart.yaml @@ -3,7 +3,7 @@ apiVersion: v2 appVersion: "v0.13.0" description: A Helm chart for the Prometheus Consul Exporter name: prometheus-consul-exporter -version: 1.1.1 +version: 1.2.0 keywords: - metrics - consul diff --git a/charts/prometheus-consul-exporter/templates/deployment.yaml b/charts/prometheus-consul-exporter/templates/deployment.yaml index 334f69e5bb35..410f18daa2f2 100644 --- a/charts/prometheus-consul-exporter/templates/deployment.yaml +++ b/charts/prometheus-consul-exporter/templates/deployment.yaml @@ -31,9 +31,16 @@ spec: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + {{- if .Values.invokeViaShell }} + command: ["/bin/sh"] + args: + - "-c" + - "consul_exporter --consul.server={{ .Values.consulServer }}" + {{- else }} command: ["consul_exporter"] args: - "--consul.server={{ .Values.consulServer }}" + {{ end }} {{- range $key, $value := .Values.options }} - "--{{ $key }}{{ if $value }}={{ $value }}{{ end }}" {{- end }} diff --git a/charts/prometheus-consul-exporter/values.yaml b/charts/prometheus-consul-exporter/values.yaml index 21bbac8de01b..1584151f5ebd 100644 --- a/charts/prometheus-consul-exporter/values.yaml +++ b/charts/prometheus-consul-exporter/values.yaml @@ -33,6 +33,12 @@ options: {} # no-consul.health-summary: # kv.filter=foobar +# By default, consul_exporter is run directly. +# If you want to use environment variables in `options` or `consulServer`, +# enable this option to have a shell interpret the command string before +# `consul_exporter` is executed. +invokeViaShell: false + service: type: ClusterIP port: 9107