From 6b2268f43fdb4c5bc003bd46c80ea5c9cd904861 Mon Sep 17 00:00:00 2001 From: SebPlv <53788114+SebPlv@users.noreply.github.com> Date: Tue, 17 Oct 2023 11:36:06 +0200 Subject: [PATCH] fix: add Prometheus scraping annotations only if serviceMonitor not created --- traefik/templates/_podtemplate.tpl | 2 +- traefik/tests/pod-config_test.yaml | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index 8b1f81c05..d168f8d41 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -5,7 +5,7 @@ {{- toYaml . | nindent 8 }} {{- end }} {{- if .Values.metrics }} - {{- if .Values.metrics.prometheus }} + {{- if and (.Values.metrics.prometheus) (not .Values.metrics.prometheus.serviceMonitor) }} prometheus.io/scrape: "true" prometheus.io/path: "/metrics" prometheus.io/port: {{ quote (index .Values.ports .Values.metrics.prometheus.entryPoint).port }} diff --git a/traefik/tests/pod-config_test.yaml b/traefik/tests/pod-config_test.yaml index 430fd0765..495de8bb9 100644 --- a/traefik/tests/pod-config_test.yaml +++ b/traefik/tests/pod-config_test.yaml @@ -613,3 +613,12 @@ tests: - equal: path: spec.template.spec.dnsConfig.options[1].name value: "edns0" + - it: should not have prometheus annotations + set: + metrics: + prometheus: + serviceMonitor: + jobLabel: traefik + asserts: + - isNull: + path: spec.template.metadata.annotations.prometheus.io/scrape