helm-charts icon indicating copy to clipboard operation
helm-charts copied to clipboard

[kube-prometheus-stack] Passing null to target discovery selectors

Open l-drews opened this issue 1 year ago • 1 comments

Describe the bug a clear and concise description of what the bug is.

The Prometheus API docs says that we can disable all ServiceMonitors, Probes, scrapeConfigs and podMonitors when we pass null to the corresponding selectors in the spec (source). This does not work with the current chart because is is always converted to {}.

An example for serviceMonitorSelector: https://github.com/prometheus-community/helm-charts/blob/7b83b454a0bb76a8ed2cee00eee44b74dc1f3775/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml#L156-L165

What's your helm version?

version.BuildInfo{Version:"v3.13.0", GitCommit:"825e86f6a7a38cef1112bfa606e4127a706749b1", GitTreeState:"clean", GoVersion:"go1.21.1"}

What's your kubectl version?

Client Version: v1.28.2 
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 
Server Version: v1.24.16+rke2r1 
WARNING: version difference between client (1.28) and server (1.24) exceeds the supported minor version skew of +/-1

Which chart?

kube-prometheus-stack

What's the chart version?

55.5.1

What happened?

When setting serviceMonitorSelector to null in the values.yaml it is converted to {} in the Prometheus spec.

What you expected to happen?

It should be possible to set the serviceMonitorSelector to null so that no ServiceMonitors should be selected.

How to reproduce it?

Just run the chart with the information provided below.

Enter the changed values of values.yaml?

prometheus:
  prometheusSpec:
    serviceMonitorSelector: null
    serviceMonitorSelectorNilUsesHelmValues: false

Enter the command that you execute and failing/misfunctioning.

helm template  kube-prom-stack kube-prometheus-stack --repo https://prometheus-community.github.io/helm-charts --version 55.5.1 --values ./values.yaml | grep "serviceMonitorSelector: null"

Anything else we need to know?

I confirmed that this should work by editing the Prometheus resource directly and setting serviceMonitorSelector to null. The generated secret for the Prometheus configuration and pod needs to be deleted for the changes to take effect.

l-drews avatar Jan 02 '24 10:01 l-drews

Yeah, this still exists in 58.1.3. It doesn't matter what is passed to the values, I've tried with all combinations that are said to work in the comments/docs, and always end up at the first else:

 {{ else if .Values.prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues  }} 
   serviceMonitorSelector: 
     matchLabels: 
       release: {{ $.Release.Name | quote }} 

luthes avatar Apr 26 '24 19:04 luthes