Skip to content

Commit

Permalink
[kube-prometheus-stack] Add downward compat for Prom CRD (#4906)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan-Otto Kröpke <github@jkroepke.de>
  • Loading branch information
schnatterer and jkroepke authored Oct 24, 2024
1 parent d3f6d15 commit 30ae44d
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 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: 65.3.2
version: 65.4.0
appVersion: v0.77.1
kubeVersion: ">=1.19.0-0"
home: https://github.com/prometheus-operator/kube-prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ spec:
scrapeConfigSelector:
matchLabels:
release: {{ $.Release.Name | quote }}
{{ else }}
{{ else if ne .Values.prometheus.prometheusSpec.scrapeConfigSelector nil }}
scrapeConfigSelector: {}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector }}
scrapeConfigNamespaceSelector:
{{ tpl (toYaml .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector | indent 4) . }}
{{ else }}
{{ else if ne .Values.prometheus.prometheusSpec.scrapeConfigNamespaceSelector nil }}
scrapeConfigNamespaceSelector: {}
{{- end }}
{{- if .Values.prometheus.prometheusSpec.storageSpec }}
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 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# 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 set to a specific label
set:
prometheus:
prometheusSpec:
scrapeConfigSelector:
abc: def
asserts:
- equal:
path: spec.scrapeConfigSelector
value:
abc: def
- 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
scrapeConfigSelectorNilUsesHelmValues: null
asserts:
- notExists:
path: spec.scrapeConfigSelector
4 changes: 4 additions & 0 deletions charts/kube-prometheus-stack/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,9 @@ prometheus:
## prometheus resource to be created with selectors based on values in the helm deployment,
## which will also match the scrapeConfigs created
##
## If null and scrapeConfigSelector is also null, exclude field from the prometheusSpec
## (keeping downward compatibility with older versions of CRD)
##
scrapeConfigSelectorNilUsesHelmValues: true

## scrapeConfigs to be selected for target discovery.
Expand All @@ -3713,6 +3716,7 @@ prometheus:
# 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:
Expand Down

0 comments on commit 30ae44d

Please sign in to comment.