Skip to content

Commit

Permalink
[kube-prometheus-stack] Add downward compat for Prom CRD (#4818)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan-Otto Kröpke <joe@cloudeteer.de>
Co-authored-by: Jan-Otto Kröpke <github@jkroepke.de>
  • Loading branch information
3 people authored Sep 26, 2024
1 parent efa9ef7 commit 25f32d6
Show file tree
Hide file tree
Showing 17 changed files with 495 additions and 156 deletions.
2 changes: 1 addition & 1 deletion charts/kube-prometheus-stack/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ name: kube-prometheus-stack
sources:
- https://github.com/prometheus-community/helm-charts
- https://github.com/prometheus-operator/kube-prometheus
version: 62.7.0
version: 63.0.0
appVersion: v0.76.1
kubeVersion: ">=1.19.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
35 changes: 34 additions & 1 deletion charts/kube-prometheus-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ _See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documen

A major chart version change (like v1.2.3 -> v2.0.0) indicates that there is an incompatible breaking change needing manual actions.

### From 62.x to 63.x

Simplify setting empty selectors, by deprecating `*SelectorNilUsesHelmValues` properties.
Instead, setting `*Selector.matchLabels=null` will create an empty selector.

If you set one of the following properties to `false`, you will have to convert them:

- `prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues`
- `prometheus.prometheusSpec.probeSelectorNilUsesHelmValues`
- `prometheus.prometheusSpec.ruleSelectorNilUsesHelmValues`
- `prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues`
- `prometheus.prometheusSpec.scrapeConfigSelectorNilUsesHelmValues`
- `thanosRuler.thanosRulerSpec.ruleSelectorNilUsesHelmValues`

For example:

```yaml
prometheus:
prometheusSpec:
scrapeConfigSelectorNilUsesHelmValues: false
```
Becomes:
```yaml
prometheus:
prometheusSpec:
scrapeConfigSelector:
matchLabels: null
```
Note that `externalPrefixNilUsesHelmValues` remains as is.

### From 61.x to 62.x

This version upgrades Prometheus-Operator to v0.76.0
Expand Down Expand Up @@ -941,7 +974,7 @@ For information on how to use PodMonitors/ServiceMonitors, please see the docume
By default, Prometheus discovers PodMonitors and ServiceMonitors within its namespace, that are labeled with the same release tag as the prometheus-operator release.
Sometimes, you may need to discover custom PodMonitors/ServiceMonitors, for example used to scrape data from third-party applications.
An easy way of doing this, without compromising the default PodMonitors/ServiceMonitors discovery, is allowing Prometheus to discover all PodMonitors/ServiceMonitors within its namespace, without applying label filtering.
To do so, you can set `prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues` and `prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues` to `false`.
To do so, you can set `prometheus.prometheusSpec.podMonitorSelector` and `prometheus.prometheusSpec.serviceMonitorSelector` to `matchLabels=null`.

## Migrating from stable/prometheus-operator chart

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,11 @@ spec:
configMaps:
{{ toYaml .Values.alertmanager.alertmanagerSpec.configMaps | indent 4 }}
{{- end }}
{{- if .Values.alertmanager.alertmanagerSpec.alertmanagerConfigSelector }}
alertmanagerConfigSelector:
{{ tpl (toYaml .Values.alertmanager.alertmanagerSpec.alertmanagerConfigSelector | indent 4) . }}
{{ else }}
alertmanagerConfigSelector: {}
{{- end }}
{{- if .Values.alertmanager.alertmanagerSpec.alertmanagerConfigNamespaceSelector }}
alertmanagerConfigNamespaceSelector:
{{ tpl (toYaml .Values.alertmanager.alertmanagerSpec.alertmanagerConfigNamespaceSelector | indent 4) . }}
{{ else }}
alertmanagerConfigNamespaceSelector: {}
{{- if not (kindIs "invalid" .Values.alertmanager.alertmanagerSpec.alertmanagerConfigSelector) }}
alertmanagerConfigSelector: {{ tpl (toYaml .Values.alertmanager.alertmanagerSpec.alertmanagerConfigSelector) . | nindent 4 }}
{{- end }}
{{- if not (kindIs "invalid" .Values.alertmanager.alertmanagerSpec.alertmanagerConfigNamespaceSelector) }}
alertmanagerConfigNamespaceSelector: {{ tpl (toYaml .Values.alertmanager.alertmanagerSpec.alertmanagerConfigNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.alertmanager.alertmanagerSpec.web }}
web:
Expand Down
18 changes: 18 additions & 0 deletions charts/kube-prometheus-stack/templates/deprecation.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- if .Values.checkDeprecation }}
# The *NilUsesHelmValues can be removed 09/25, about a year after deprecation
{{- if .Values.prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues }}
{{ fail "`podMonitorSelectorNilUsesHelmValues` no longer exists. See https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack#from-62x-to-63x" }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.probeSelectorNilUsesHelmValues }}
{{ fail "`probeSelectorNilUsesHelmValues` no longer exists. See https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack#from-62x-to-63x" }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.ruleSelectorNilUsesHelmValues }}
{{ fail "`ruleSelectorNilUsesHelmValues` no longer exists. See https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack#from-62x-to-63x" }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues }}
{{ fail "`serviceMonitorSelectorNilUsesHelmValues` no longer exists. See https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack#from-62x-to-63x" }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.scrapeConfigSelectorNilUsesHelmValues }}
{{ fail "`scrapeConfigSelectorNilUsesHelmValues` no longer exists. See https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack#from-62x-to-63x" }}
{{- end }}
{{- end }}
96 changes: 23 additions & 73 deletions charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,53 +158,23 @@ spec:
{{ toYaml .Values.prometheus.prometheusSpec.configMaps | indent 4 }}
{{- end }}
serviceAccountName: {{ template "kube-prometheus-stack.prometheus.serviceAccountName" . }}
{{- if .Values.prometheus.prometheusSpec.serviceMonitorSelector }}
serviceMonitorSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.serviceMonitorSelector | indent 4) . }}
{{ else if .Values.prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues }}
serviceMonitorSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
serviceMonitorSelector: {}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.serviceMonitorSelector) }}
serviceMonitorSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.serviceMonitorSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.serviceMonitorNamespaceSelector }}
serviceMonitorNamespaceSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.serviceMonitorNamespaceSelector | indent 4) . }}
{{ else }}
serviceMonitorNamespaceSelector: {}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.podMonitorSelector }}
podMonitorSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.podMonitorSelector | indent 4) . }}
{{ else if .Values.prometheus.prometheusSpec.podMonitorSelectorNilUsesHelmValues }}
podMonitorSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
podMonitorSelector: {}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.serviceMonitorNamespaceSelector) }}
serviceMonitorNamespaceSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.serviceMonitorNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.podMonitorNamespaceSelector }}
podMonitorNamespaceSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.podMonitorNamespaceSelector | indent 4) . }}
{{ else }}
podMonitorNamespaceSelector: {}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.probeSelector }}
probeSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.probeSelector | indent 4) . }}
{{ else if .Values.prometheus.prometheusSpec.probeSelectorNilUsesHelmValues }}
probeSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
probeSelector: {}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.podMonitorSelector) }}
podMonitorSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.podMonitorSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.probeNamespaceSelector }}
probeNamespaceSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.probeNamespaceSelector | indent 4) . }}
{{ else }}
probeNamespaceSelector: {}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.podMonitorNamespaceSelector) }}
podMonitorNamespaceSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.podMonitorNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.probeSelector) }}
probeSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.probeSelector) . | nindent 4 }}
{{- end }}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.probeNamespaceSelector) }}
probeNamespaceSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.probeNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if and (not .Values.prometheus.agentMode) (or .Values.prometheus.prometheusSpec.remoteRead .Values.prometheus.prometheusSpec.additionalRemoteRead) }}
remoteRead:
Expand All @@ -229,38 +199,18 @@ spec:
{{ toYaml .Values.prometheus.prometheusSpec.securityContext | indent 4 }}
{{- end }}
{{- if not .Values.prometheus.agentMode }}
{{- if .Values.prometheus.prometheusSpec.ruleNamespaceSelector }}
ruleNamespaceSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.ruleNamespaceSelector | indent 4) . }}
{{ else }}
ruleNamespaceSelector: {}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.ruleSelector }}
ruleSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.ruleSelector | indent 4) . }}
{{- else if .Values.prometheus.prometheusSpec.ruleSelectorNilUsesHelmValues }}
ruleSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
ruleSelector: {}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.ruleNamespaceSelector) }}
ruleNamespaceSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.ruleNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.ruleSelector) }}
ruleSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.ruleSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.scrapeConfigSelector }}
scrapeConfigSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.scrapeConfigSelector | indent 4) . }}
{{ else if .Values.prometheus.prometheusSpec.scrapeConfigSelectorNilUsesHelmValues }}
scrapeConfigSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
scrapeConfigSelector: {}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector }}
scrapeConfigNamespaceSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector | indent 4) . }}
{{ else }}
scrapeConfigNamespaceSelector: {}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.scrapeConfigSelector) }}
scrapeConfigSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.scrapeConfigSelector) . | nindent 4 }}
{{- end }}
{{- if not (kindIs "invalid" .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector) }}
scrapeConfigNamespaceSelector: {{ tpl (toYaml .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.storageSpec }}
storage:
Expand Down
20 changes: 5 additions & 15 deletions charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,11 @@ spec:
{{- if .Values.thanosRuler.thanosRulerSpec.evaluationInterval }}
evaluationInterval: {{ .Values.thanosRuler.thanosRulerSpec.evaluationInterval }}
{{- end }}
{{- if .Values.thanosRuler.thanosRulerSpec.ruleNamespaceSelector }}
ruleNamespaceSelector:
{{ tpl (toYaml .Values.thanosRuler.thanosRulerSpec.ruleNamespaceSelector | indent 4) . }}
{{ else }}
ruleNamespaceSelector: {}
{{- end }}
{{- if .Values.thanosRuler.thanosRulerSpec.ruleSelector }}
ruleSelector:
{{ tpl (toYaml .Values.thanosRuler.thanosRulerSpec.ruleSelector | indent 4) .}}
{{- else if .Values.thanosRuler.thanosRulerSpec.ruleSelectorNilUsesHelmValues }}
ruleSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
ruleSelector: {}
{{- if not (kindIs "invalid" .Values.thanosRuler.thanosRulerSpec.ruleNamespaceSelector) }}
ruleNamespaceSelector: {{ tpl (toYaml .Values.thanosRuler.thanosRulerSpec.ruleNamespaceSelector) . | nindent 4 }}
{{- end }}
{{- if not (kindIs "invalid" .Values.thanosRuler.thanosRulerSpec.ruleSelector) }}
ruleSelector: {{ tpl (toYaml .Values.thanosRuler.thanosRulerSpec.ruleSelector) . | nindent 4 }}
{{- end }}
{{- if .Values.thanosRuler.thanosRulerSpec.alertQueryUrl }}
alertQueryUrl: "{{ .Values.thanosRuler.thanosRulerSpec.alertQueryUrl }}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: test podMonitorNamespaceSelector
templates:
- prometheus/prometheus.yaml
tests:
- it: should be empty by default
asserts:
- equal:
path: spec.podMonitorNamespaceSelector
value: {}
- it: should be set to a specific label
set:
prometheus:
prometheusSpec:
podMonitorNamespaceSelector:
matchLabels:
abc: def
asserts:
- equal:
path: spec.podMonitorNamespaceSelector.matchLabels.abc
value: def
- it: should be ignored, if set to null
set:
prometheus:
prometheusSpec:
podMonitorNamespaceSelector: null
asserts:
- notExists:
path: spec.podMonitorNamespaceSelector
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: test podMonitorSelector
templates:
- prometheus/prometheus.yaml
tests:
- it: should match the release name by default
asserts:
- equal:
path: spec.podMonitorSelector.matchLabels.release
value: RELEASE-NAME
- it: should be empty, when matchLabels is null
set:
prometheus:
prometheusSpec:
podMonitorSelector:
matchLabels: null
asserts:
- equal:
path: spec.podMonitorSelector
value: {}
- it: should be set to a specific label
set:
prometheus:
prometheusSpec:
podMonitorSelector:
matchLabels:
abc: def
asserts:
- equal:
path: spec.podMonitorSelector.matchLabels.abc
value: def
- it: should be ignored, if set to null
set:
prometheus:
prometheusSpec:
podMonitorSelector: null
asserts:
- notExists:
path: spec.podMonitorSelector
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: test probeNamespaceSelector
templates:
- prometheus/prometheus.yaml
tests:
- it: should be empty by default
asserts:
- equal:
path: spec.probeNamespaceSelector
value: {}
- it: should be set to a specific label
set:
prometheus:
prometheusSpec:
probeNamespaceSelector:
matchLabels:
abc: def
asserts:
- equal:
path: spec.probeNamespaceSelector.matchLabels.abc
value: def
- it: should be ignored, if set to null
set:
prometheus:
prometheusSpec:
probeNamespaceSelector: null
asserts:
- notExists:
path: spec.probeNamespaceSelector
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: test probeSelector
templates:
- prometheus/prometheus.yaml
tests:
- it: should match the release name by default
asserts:
- equal:
path: spec.probeSelector.matchLabels.release
value: RELEASE-NAME
- it: should be empty, when matchLabels is null
set:
prometheus:
prometheusSpec:
probeSelector:
matchLabels: null
asserts:
- equal:
path: spec.probeSelector
value: {}
- it: should be set to a specific label
set:
prometheus:
prometheusSpec:
probeSelector:
matchLabels:
abc: def
asserts:
- equal:
path: spec.probeSelector.matchLabels.abc
value: def
- it: should be ignored, if set to null
set:
prometheus:
prometheusSpec:
probeSelector: null
asserts:
- notExists:
path: spec.probeSelector
Loading

0 comments on commit 25f32d6

Please sign in to comment.