Skip to content

[prometheus-pushgateway] add support for basicAuth in ServiceMonitor #5489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 6, 2025
2 changes: 1 addition & 1 deletion charts/prometheus-pushgateway/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
appVersion: "v1.11.0"
appVersion: "v1.11.1"
description: A Helm chart for prometheus pushgateway
name: prometheus-pushgateway
version: 3.0.0
Expand Down
11 changes: 11 additions & 0 deletions charts/prometheus-pushgateway/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ Define Authorization
{{- $user }}:{{ $password }}
{{- end }}

{{/*
Define basicAuth
*/}}
{{- define "prometheus-pushgateway.basicAuth" -}}
{{- $users := keys .Values.webConfiguration.basicAuthUsers }}
{{- $user := first $users }}
{{- $password := index .Values.webConfiguration.basicAuthUsers $user -}}
user: {{ $user | b64enc | quote }}
password: {{ $password | b64enc | quote }}
{{- end }}

{{/*
Returns pod spec
*/}}
Expand Down
11 changes: 11 additions & 0 deletions charts/prometheus-pushgateway/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,14 @@ metadata:
data:
web-config.yaml: {{ include "prometheus-pushgateway.webConfiguration" . | b64enc}}
{{- end }}
---
apiVersion: v1
kind: Secret
metadata:
name: {{ include "prometheus-pushgateway.fullname" . }}-basic-auth
labels:
{{- include "prometheus-pushgateway.defaultLabels" . | nindent 4 }}
data:
{{- include "prometheus-pushgateway.basicAuth" . | nindent 2 }}
type: Opaque
{{- end }}
9 changes: 9 additions & 0 deletions charts/prometheus-pushgateway/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ spec:
{{- with .Values.serviceMonitor.scheme }}
scheme: {{ . }}
{{- end }}
{{- if .Values.webConfiguration }}
basicAuth:
password:
name: {{ include "prometheus-pushgateway.fullname" . }}-basic-auth
key: password
username:
name: {{ include "prometheus-pushgateway.fullname" . }}-basic-auth
key: user
{{- end }}
{{- with .Values.serviceMonitor.bearerTokenFile }}
bearerTokenFile: {{ . }}
{{- end }}
Expand Down
Loading