From a8984b9a986c5d4ce5f0169584d41a5e9db65f79 Mon Sep 17 00:00:00 2001 From: Hitesh Nayak Date: Thu, 24 Oct 2024 02:42:06 +0530 Subject: [PATCH] fix(service-monitor): invalid config.metrics.TOKEN for nil and empty gitea.metrics.token --- templates/_helpers.tpl | 2 +- .../config/metrics-section_metrics-token.yaml | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index 1a38084..b2dfaff 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 not (hasKey .Values.gitea.config.metrics "TOKEN") -}} + {{- if and (not (hasKey .Values.gitea.config.metrics "TOKEN")) (.Values.gitea.metrics.token) -}} {{- $_ := 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 3cac92a..dc07537 100644 --- a/unittests/config/metrics-section_metrics-token.yaml +++ b/unittests/config/metrics-section_metrics-token.yaml @@ -17,3 +17,29 @@ tests: value: |- ENABLED=true TOKEN=somepassword + - it: metrics token is empty + template: templates/gitea/config.yaml + set: + gitea: + metrics: + enabled: true + token: "" + asserts: + - documentIndex: 0 + equal: + path: stringData.metrics + value: |- + ENABLED=true + - it: metrics token is nil + template: templates/gitea/config.yaml + set: + gitea: + metrics: + enabled: true + token: + asserts: + - documentIndex: 0 + equal: + path: stringData.metrics + value: |- + ENABLED=true