feat(helm): add bearer token authentication to ServiceMonitor

This commit is contained in:
Patrick Deubel 2026-02-10 20:32:48 +01:00 committed by Patrick Deubel
parent 3bbc25a3f0
commit fa2213535a
3 changed files with 38 additions and 0 deletions

View file

@ -0,0 +1,11 @@
{{- if and (eq .Values.serviceMonitor.enabled true) (eq .Values.serviceMonitor.secret.create true) .Values.serviceMonitor.secret.value }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "litellm.fullname" . }}-servicemonitor-token
labels:
{{- include "litellm.labels" . | nindent 4 }}
data:
token: {{ .Values.serviceMonitor.secret.value | b64enc }}
type: Opaque
{{- end }}

View file

@ -31,6 +31,18 @@ spec:
interval: {{ .interval }}
scrapeTimeout: {{ .scrapeTimeout }}
scheme: http
{{- /*
Render bearerTokenSecret block if either chart creates the secret (secret.create=true) or
user explicitly sets all three fields (name, key, optional).
*/ -}}
{{- if or (eq .secret.create true) (and .bearerTokenSecret.name .bearerTokenSecret.key }}
bearerTokenSecret:
name: {{ .bearerTokenSecret.name | default (print (include "litellm.fullname" $) "-servicemonitor-token") }}
key: {{ .bearerTokenSecret.key | default "token" }}
{{- if hasKey .bearerTokenSecret "optional" }}
optional: {{ .bearerTokenSecret.optional }}
{{- end }}
{{- end }}
{{- if .relabelings }}
relabelings:
{{- toYaml .relabelings | nindent 4 }}

View file

@ -339,3 +339,18 @@ serviceMonitor:
namespaceSelector:
matchNames: []
# - test-namespace
# Bearer token authentication for metrics endpoint
# Creates a K8s secret with the API key you want to use. With that you do not need to specify
# bearerTokenSecret manually.
secret:
create: false # Set to true to have the chart create the secret
value: "" # Token value (required if create: true)
# Use this if you want to configure the bearerTokenSecret manually.
bearerTokenSecret: {}
# name: "" # Secret name. Defaults to: {{ include "litellm.fullname" . }}-servicemonitor-token
# key: "token" # Secret key. Defaults to: "token"
# optional: false # Mark secret as optional. Defaults to: false