From 25f32d65dd42fe49d92b85c6e103272a81590024 Mon Sep 17 00:00:00 2001 From: schnatterer Date: Thu, 26 Sep 2024 19:54:48 +0200 Subject: [PATCH] [kube-prometheus-stack] Add downward compat for Prom CRD (#4818) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jan-Otto Kröpke Co-authored-by: Jan-Otto Kröpke --- charts/kube-prometheus-stack/Chart.yaml | 2 +- charts/kube-prometheus-stack/README.md | 35 ++++- .../templates/alertmanager/alertmanager.yaml | 16 +-- .../templates/deprecation.yaml | 18 +++ .../templates/prometheus/prometheus.yaml | 96 ++++---------- .../templates/thanos-ruler/ruler.yaml | 20 +-- .../pod_monitor_namespace_selector_test.yaml | 29 ++++ .../prometheus/pod_monitor_selector_test.yaml | 39 ++++++ .../probe_namespace_selector_test.yaml | 29 ++++ .../prometheus/probe_selector_test.yaml | 39 ++++++ .../rule_namespace_selector_test.yaml | 29 ++++ .../prometheus/rule_selector_test.yaml | 39 ++++++ ...scrape_config_namespace_selector_test.yaml | 29 ++++ .../scrape_config_selector_test.yaml | 39 ++++++ ...rvice_monitor_namespace_selector_test.yaml | 29 ++++ .../service_monitor_selector_test.yaml | 39 ++++++ charts/kube-prometheus-stack/values.yaml | 124 ++++++++++-------- 17 files changed, 495 insertions(+), 156 deletions(-) create mode 100644 charts/kube-prometheus-stack/templates/deprecation.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_namespace_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/probe_namespace_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/probe_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/rule_namespace_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/rule_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/scrape_config_namespace_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/scrape_config_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/service_monitor_namespace_selector_test.yaml create mode 100644 charts/kube-prometheus-stack/unittests/prometheus/service_monitor_selector_test.yaml diff --git a/charts/kube-prometheus-stack/Chart.yaml b/charts/kube-prometheus-stack/Chart.yaml index 0dabd7219232..4d07d17a8480 100644 --- a/charts/kube-prometheus-stack/Chart.yaml +++ b/charts/kube-prometheus-stack/Chart.yaml @@ -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 diff --git a/charts/kube-prometheus-stack/README.md b/charts/kube-prometheus-stack/README.md index e6c99254dc45..84ab01bb6b8e 100644 --- a/charts/kube-prometheus-stack/README.md +++ b/charts/kube-prometheus-stack/README.md @@ -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 @@ -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 diff --git a/charts/kube-prometheus-stack/templates/alertmanager/alertmanager.yaml b/charts/kube-prometheus-stack/templates/alertmanager/alertmanager.yaml index fa060a32e304..656f0c8c02f9 100644 --- a/charts/kube-prometheus-stack/templates/alertmanager/alertmanager.yaml +++ b/charts/kube-prometheus-stack/templates/alertmanager/alertmanager.yaml @@ -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: diff --git a/charts/kube-prometheus-stack/templates/deprecation.yaml b/charts/kube-prometheus-stack/templates/deprecation.yaml new file mode 100644 index 000000000000..1c5ee4ba2c68 --- /dev/null +++ b/charts/kube-prometheus-stack/templates/deprecation.yaml @@ -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 }} diff --git a/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml b/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml index 3d02aa92ea98..4045b0218c18 100644 --- a/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml +++ b/charts/kube-prometheus-stack/templates/prometheus/prometheus.yaml @@ -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: @@ -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: diff --git a/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml b/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml index 0c6439f3f938..13fe67d49ead 100644 --- a/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml +++ b/charts/kube-prometheus-stack/templates/thanos-ruler/ruler.yaml @@ -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 }}" diff --git a/charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_namespace_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_namespace_selector_test.yaml new file mode 100644 index 000000000000..56ac83ac3c41 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_namespace_selector_test.yaml @@ -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 \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_selector_test.yaml new file mode 100644 index 000000000000..94117a6a867c --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/pod_monitor_selector_test.yaml @@ -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 \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/probe_namespace_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/probe_namespace_selector_test.yaml new file mode 100644 index 000000000000..6f922fa4dac0 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/probe_namespace_selector_test.yaml @@ -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 \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/probe_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/probe_selector_test.yaml new file mode 100644 index 000000000000..66ae655bb395 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/probe_selector_test.yaml @@ -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 \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/rule_namespace_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/rule_namespace_selector_test.yaml new file mode 100644 index 000000000000..e91a686cf025 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/rule_namespace_selector_test.yaml @@ -0,0 +1,29 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test ruleNamespaceSelector +templates: + - prometheus/prometheus.yaml +tests: + - it: should be empty by default + asserts: + - equal: + path: spec.ruleNamespaceSelector + value: {} + - it: should be set to a specific label + set: + prometheus: + prometheusSpec: + ruleNamespaceSelector: + matchLabels: + abc: def + asserts: + - equal: + path: spec.ruleNamespaceSelector.matchLabels.abc + value: def + - it: should be ignored, if set to null + set: + prometheus: + prometheusSpec: + ruleNamespaceSelector: null + asserts: + - notExists: + path: spec.ruleNamespaceSelector \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/rule_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/rule_selector_test.yaml new file mode 100644 index 000000000000..4b70e6e861ff --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/rule_selector_test.yaml @@ -0,0 +1,39 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test ruleSelector +templates: + - prometheus/prometheus.yaml +tests: + - it: should match the release name by default + asserts: + - equal: + path: spec.ruleSelector.matchLabels.release + value: RELEASE-NAME + - it: should be empty, when matchLabels is null + set: + prometheus: + prometheusSpec: + ruleSelector: + matchLabels: null + asserts: + - equal: + path: spec.ruleSelector + value: {} + - it: should be set to a specific label + set: + prometheus: + prometheusSpec: + ruleSelector: + matchLabels: + abc: def + asserts: + - equal: + path: spec.ruleSelector.matchLabels.abc + value: def + - it: should be ignored, if set to null + set: + prometheus: + prometheusSpec: + ruleSelector: null + asserts: + - notExists: + path: spec.ruleSelector \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/scrape_config_namespace_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/scrape_config_namespace_selector_test.yaml new file mode 100644 index 000000000000..848312dfd7a9 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/scrape_config_namespace_selector_test.yaml @@ -0,0 +1,29 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test scrapeConfigNamespaceSelector +templates: + - prometheus/prometheus.yaml +tests: + - it: should be empty by default + asserts: + - equal: + path: spec.scrapeConfigNamespaceSelector + value: {} + - it: should be set to a specific label + set: + prometheus: + prometheusSpec: + scrapeConfigNamespaceSelector: + matchLabels: + abc: def + asserts: + - equal: + path: spec.scrapeConfigNamespaceSelector.matchLabels.abc + value: def + - it: should be ignored, if set to null + set: + prometheus: + prometheusSpec: + scrapeConfigNamespaceSelector: null + asserts: + - notExists: + path: spec.scrapeConfigNamespaceSelector \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/scrape_config_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/scrape_config_selector_test.yaml new file mode 100644 index 000000000000..2fe2080d40d6 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/scrape_config_selector_test.yaml @@ -0,0 +1,39 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test scrapeConfigSelector +templates: + - prometheus/prometheus.yaml +tests: + - it: should match the release name by default + asserts: + - equal: + path: spec.scrapeConfigSelector.matchLabels.release + value: RELEASE-NAME + - it: should be empty, when matchLabels is null + set: + prometheus: + prometheusSpec: + scrapeConfigSelector: + matchLabels: null + asserts: + - equal: + path: spec.scrapeConfigSelector + value: {} + - it: should be set to a specific label + set: + prometheus: + prometheusSpec: + scrapeConfigSelector: + matchLabels: + abc: def + asserts: + - equal: + path: spec.scrapeConfigSelector.matchLabels.abc + value: def + - it: should be ignored, if set to null + set: + prometheus: + prometheusSpec: + scrapeConfigSelector: null + asserts: + - notExists: + path: spec.scrapeConfigSelector \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/service_monitor_namespace_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/service_monitor_namespace_selector_test.yaml new file mode 100644 index 000000000000..79ad53cca17c --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/service_monitor_namespace_selector_test.yaml @@ -0,0 +1,29 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test serviceMonitorNamespaceSelector +templates: + - prometheus/prometheus.yaml +tests: + - it: should be empty by default + asserts: + - equal: + path: spec.serviceMonitorNamespaceSelector + value: {} + - it: should be set to a specific label + set: + prometheus: + prometheusSpec: + serviceMonitorNamespaceSelector: + matchLabels: + abc: def + asserts: + - equal: + path: spec.serviceMonitorNamespaceSelector.matchLabels.abc + value: def + - it: should be ignored, if set to null + set: + prometheus: + prometheusSpec: + serviceMonitorNamespaceSelector: null + asserts: + - notExists: + path: spec.serviceMonitorNamespaceSelector \ No newline at end of file diff --git a/charts/kube-prometheus-stack/unittests/prometheus/service_monitor_selector_test.yaml b/charts/kube-prometheus-stack/unittests/prometheus/service_monitor_selector_test.yaml new file mode 100644 index 000000000000..cc088db43dc0 --- /dev/null +++ b/charts/kube-prometheus-stack/unittests/prometheus/service_monitor_selector_test.yaml @@ -0,0 +1,39 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test serviceMonitorSelector +templates: + - prometheus/prometheus.yaml +tests: + - it: should match the release name by default + asserts: + - equal: + path: spec.serviceMonitorSelector.matchLabels.release + value: RELEASE-NAME + - it: should be empty, when matchLabels is null + set: + prometheus: + prometheusSpec: + serviceMonitorSelector: + matchLabels: null + asserts: + - equal: + path: spec.serviceMonitorSelector + value: {} + - it: should be set to a specific label + set: + prometheus: + prometheusSpec: + serviceMonitorSelector: + matchLabels: + abc: def + asserts: + - equal: + path: spec.serviceMonitorSelector.matchLabels.abc + value: def + - it: should be ignored, if set to null + set: + prometheus: + prometheusSpec: + serviceMonitorSelector: null + asserts: + - notExists: + path: spec.serviceMonitorSelector \ No newline at end of file diff --git a/charts/kube-prometheus-stack/values.yaml b/charts/kube-prometheus-stack/values.yaml index f0619b063fdd..68ea19334c11 100644 --- a/charts/kube-prometheus-stack/values.yaml +++ b/charts/kube-prometheus-stack/values.yaml @@ -28,6 +28,10 @@ commonLabels: {} # scmhash: abc123 # myLabel: aakkmd +## Checks if any deprecated values are used +## +checkDeprecation: true + ## Install Prometheus Operator CRDs ## crds: @@ -3594,16 +3598,17 @@ prometheus: # matchLabels: # prometheus: somelabel - ## If true, a nil or {} value for prometheus.prometheusSpec.ruleSelector will cause the - ## prometheus resource to be created with selectors based on values in the helm deployment, - ## which will also match the PrometheusRule resources created - ## - ruleSelectorNilUsesHelmValues: true - ## PrometheusRules to be selected for target discovery. - ## If {}, select all PrometheusRules - ## - ruleSelector: {} + ## If matchLabels.release: "{{ $.Release.Name }}" the prometheus resource will be created + ## with selectors based on values in the helm deployment, which will also match the scrapeConfigs created + ## To remove matchLabels from the selector condition, explicitly set matchLabels to null. + ## If no other selectors are configured, prometheus-operator will select all scrapeConfigs. + ## To remove the release label from the matchLabels condition, explicit set release to null. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) + ## + ruleSelector: + matchLabels: + release: "{{ $.Release.Name }}" ## Example which select all PrometheusRules resources ## with label "prometheus" with values any of "example-rules" or "example-rules-2" # ruleSelector: @@ -3619,16 +3624,17 @@ prometheus: # matchLabels: # role: example-rules - ## If true, a nil or {} value for prometheus.prometheusSpec.serviceMonitorSelector will cause the - ## prometheus resource to be created with selectors based on values in the helm deployment, - ## which will also match the servicemonitors created - ## - serviceMonitorSelectorNilUsesHelmValues: true - ## ServiceMonitors to be selected for target discovery. - ## If {}, select all ServiceMonitors - ## - serviceMonitorSelector: {} + ## If matchLabels.release: "{{ $.Release.Name }}" the prometheus resource will be created + ## with selectors based on values in the helm deployment, which will also match the scrapeConfigs created + ## To remove matchLabels from the selector condition, explicitly set matchLabels to null. + ## If no other selectors are configured, prometheus-operator will select all scrapeConfigs. + ## To remove the release label from the matchLabels condition, explicit set release to null. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) + ## + serviceMonitorSelector: + matchLabels: + release: "{{ $.Release.Name }}" ## Example which selects ServiceMonitors with label "prometheus" set to "somelabel" # serviceMonitorSelector: # matchLabels: @@ -3642,16 +3648,17 @@ prometheus: # matchLabels: # prometheus: somelabel - ## If true, a nil or {} value for prometheus.prometheusSpec.podMonitorSelector will cause the - ## prometheus resource to be created with selectors based on values in the helm deployment, - ## which will also match the podmonitors created - ## - podMonitorSelectorNilUsesHelmValues: true - ## PodMonitors to be selected for target discovery. - ## If {}, select all PodMonitors - ## - podMonitorSelector: {} + ## If matchLabels.release: "{{ $.Release.Name }}" the prometheus resource will be created + ## with selectors based on values in the helm deployment, which will also match the scrapeConfigs created + ## To remove matchLabels from the selector condition, explicitly set matchLabels to null. + ## If no other selectors are configured, prometheus-operator will select all scrapeConfigs. + ## To remove the release label from the matchLabels condition, explicit set release to null. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) + ## + podMonitorSelector: + matchLabels: + release: "{{ $.Release.Name }}" ## Example which selects PodMonitors with label "prometheus" set to "somelabel" # podMonitorSelector: # matchLabels: @@ -3664,16 +3671,17 @@ prometheus: # matchLabels: # prometheus: somelabel - ## If true, a nil or {} value for prometheus.prometheusSpec.probeSelector will cause the - ## prometheus resource to be created with selectors based on values in the helm deployment, - ## which will also match the probes created - ## - probeSelectorNilUsesHelmValues: true - ## Probes to be selected for target discovery. - ## If {}, select all Probes - ## - probeSelector: {} + ## If matchLabels.release: "{{ $.Release.Name }}" the prometheus resource will be created + ## with selectors based on values in the helm deployment, which will also match the scrapeConfigs created + ## To remove matchLabels from the selector condition, explicitly set matchLabels to null. + ## If no other selectors are configured, prometheus-operator will select all scrapeConfigs. + ## To remove the release label from the matchLabels condition, explicit set release to null. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) + ## + probeSelector: + matchLabels: + release: "{{ $.Release.Name }}" ## Example which selects Probes with label "prometheus" set to "somelabel" # probeSelector: # matchLabels: @@ -3686,22 +3694,25 @@ prometheus: # matchLabels: # prometheus: somelabel - ## If true, a nil or {} value for prometheus.prometheusSpec.scrapeConfigSelector will cause the - ## prometheus resource to be created with selectors based on values in the helm deployment, - ## which will also match the scrapeConfigs created - ## - scrapeConfigSelectorNilUsesHelmValues: true - ## scrapeConfigs to be selected for target discovery. - ## If {}, select all scrapeConfigs - ## - scrapeConfigSelector: {} + ## If matchLabels.release: "{{ $.Release.Name }}" the prometheus resource will be created + ## with selectors based on values in the helm deployment, which will also match the scrapeConfigs created + ## To remove matchLabels from the selector condition, explicitly set matchLabels to null. + ## If no other selectors are configured, prometheus-operator will select all scrapeConfigs. + ## To remove the release label from the matchLabels condition, explicit set release to null. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) + ## + scrapeConfigSelector: + matchLabels: + release: "{{ $.Release.Name }}" ## Example which selects scrapeConfigs with label "prometheus" set to "somelabel" # scrapeConfigSelector: # matchLabels: + # release: ~ # prometheus: somelabel ## If nil, select own namespace. Namespaces to be selected for scrapeConfig discovery. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) scrapeConfigNamespaceSelector: {} ## Example which selects scrapeConfig in namespaces with label "prometheus" set to "somelabel" # scrapeConfigNamespaceSelector: @@ -4500,19 +4511,21 @@ thanosRuler: ## ruleNamespaceSelector: {} - ## If true, a nil or {} value for thanosRuler.thanosRulerSpec.ruleSelector will cause the - ## prometheus resource to be created with selectors based on values in the helm deployment, - ## which will also match the PrometheusRule resources created - ## - ruleSelectorNilUsesHelmValues: true - ## PrometheusRules to be selected for target discovery. - ## If {}, select all PrometheusRules - ## - ruleSelector: {} + ## If matchLabels.release: "{{ $.Release.Name }}" the prometheus resource will be created + ## with selectors based on values in the helm deployment, which will also match the scrapeConfigs created + ## To remove matchLabels from the selector condition, explicitly set matchLabels to null. + ## If no other selectors are configured, prometheus-operator will select all scrapeConfigs. + ## To remove the release label from the matchLabels condition, explicit set release to null. + ## If null, exclude the field from the prometheusSpec (keeping downward compatibility with older versions of CRD) + ## + ruleSelector: + matchLabels: + release: "{{ $.Release.Name }}" ## Example which select all PrometheusRules resources ## with label "prometheus" with values any of "example-rules" or "example-rules-2" # ruleSelector: + # matchLabels: ~ # matchExpressions: # - key: prometheus # operator: In @@ -4523,6 +4536,7 @@ thanosRuler: ## Example which select all PrometheusRules resources with label "role" set to "example-rules" # ruleSelector: # matchLabels: + # release: ~ # role: example-rules ## Define Log Format @@ -4566,7 +4580,7 @@ thanosRuler: existingSecret: {} # name: "" # key: "" - # will render render alertmanagersConfig secret data and configure it to be used by Thanos Ruler custom resource, ignored when alertmanagersConfig.existingSecret is set + # will render alertmanagersConfig secret data and configure it to be used by Thanos Ruler custom resource, ignored when alertmanagersConfig.existingSecret is set # https://thanos.io/tip/components/rule.md/#alertmanager secret: {} # alertmanagers: