prometheus-community / helm-charts

Prometheus community Helm charts
Apache License 2.0
5.12k stars 5.02k forks source link

[kube-prometheus-stack]: Apply tpl on additionalScrapeConfigsSecret #4905

Closed VietND96 closed 1 month ago

VietND96 commented 1 month ago

What this PR does / why we need it

I am using kube-prometheus-stack as a sub-chart. I want to config key prometheus.prometheusSpec.additionalScrapeConfigsSecret.name to point to a Secret resource which is created in main chart. The resource name has the prefix is .Release.Name, so I also want to apply tpl. A test is done as below

Chart values.yaml

# -- Configuration for dependency chart kube-prometheus-stack
kube-prometheus-stack:
  # enabled: false
  cleanPrometheusOperatorObjectNames: true
  prometheus:
    prometheusSpec:
      additionalScrapeConfigsSecret:
        enabled: true
        name: '{{ .Release.Name }}-external-secret'
        key: '{{ .Release.Name }}-app-scrape'

Via helm template, the output looks like

# Source: kube-prometheus-stack/templates/prometheus/prometheus.yaml
...
  scrapeConfigNamespaceSelector: {}
  additionalScrapeConfigs:
    name: test-external-secret
    key: test-app-scrape
  portName: http-web
  hostNetwork: false

Which issue this PR fixes

(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged)

Special notes for your reviewer

Checklist

jkroepke commented 1 month ago

Did you try

kube-prometheus-stack:
  prometheus:
    prometheusSpec:
      additionalConfig:
        additionalScrapeConfigs:
          enabled: true
          name: '{{ .Release.Name }}-external-secret'
          key: '{{ .Release.Name }}-app-scrape'
VietND96 commented 1 month ago

@jkroepke, without tpl it didn't work. Here is error and output

Error: YAML parse error on selenium-grid/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml: error converting YAML to JSON: yaml: line 85: did not find expected key
helm.go:86: 2024-10-09 02:42:04.299876628 +0000 UTC m=+10.536352312 [debug] error converting YAML to JSON: yaml: line 85: did not find expected key
YAML parse error on selenium-grid/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml
# Source: selenium-grid/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml
  additionalScrapeConfigs:
    name: {{ .Release.Name }}-metrics-exporter
    key: {{ .Release.Name }}-selenium-grid
  portName: http-web
  hostNetwork: false
jkroepke commented 1 month ago

Please re-check my comment, prometheusSpec.additionalConfig has tpl.

VietND96 commented 1 month ago

@jkroepke, oops, my mistake, I was confused about the config key. That config key works now. Thanks! I will close the PR.