From 7a48fdb51fbe2f303f47b6fff080d2c1f5365901 Mon Sep 17 00:00:00 2001 From: Hitesh Nayak Date: Sat, 30 Nov 2024 17:32:41 +0530 Subject: [PATCH] fix(service-monitor): if metrics disabled but token provided then ignore token --- templates/_helpers.tpl | 2 +- unittests/config/metrics-section_metrics-token.yaml | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index b2dfaff..1fddd5d 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -278,7 +278,7 @@ https {{- if not (hasKey .Values.gitea.config.metrics "ENABLED") -}} {{- $_ := set .Values.gitea.config.metrics "ENABLED" .Values.gitea.metrics.enabled -}} {{- end -}} - {{- if and (not (hasKey .Values.gitea.config.metrics "TOKEN")) (.Values.gitea.metrics.token) -}} + {{- if and (not (hasKey .Values.gitea.config.metrics "TOKEN")) (.Values.gitea.metrics.token) (.Values.gitea.metrics.enabled) -}} {{- $_ := set .Values.gitea.config.metrics "TOKEN" .Values.gitea.metrics.token -}} {{- end -}} {{- /* redis queue */ -}} diff --git a/unittests/config/metrics-section_metrics-token.yaml b/unittests/config/metrics-section_metrics-token.yaml index dc07537..b8115a1 100644 --- a/unittests/config/metrics-section_metrics-token.yaml +++ b/unittests/config/metrics-section_metrics-token.yaml @@ -43,3 +43,16 @@ tests: path: stringData.metrics value: |- ENABLED=true + - it: does not configures a token if metrics are disabled + template: templates/gitea/config.yaml + set: + gitea: + metrics: + enabled: false + token: "somepassword" + asserts: + - documentIndex: 0 + equal: + path: stringData.metrics + value: |- + ENABLED=false