From b35df2b58409002b669cbb1f47f8dd88ccdc7368 Mon Sep 17 00:00:00 2001 From: Andrii Chubatiuk Date: Thu, 5 Sep 2024 14:20:15 +0300 Subject: [PATCH] fail chart rendering in case of rule name collision --- charts/victoria-metrics-k8s-stack/CHANGELOG.md | 2 +- .../victoria-metrics-k8s-stack/templates/rules/rule.yaml | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/charts/victoria-metrics-k8s-stack/CHANGELOG.md b/charts/victoria-metrics-k8s-stack/CHANGELOG.md index ba5be39b6..6b4251b3b 100644 --- a/charts/victoria-metrics-k8s-stack/CHANGELOG.md +++ b/charts/victoria-metrics-k8s-stack/CHANGELOG.md @@ -2,7 +2,7 @@ ## Next release -- TODO +- Fail chart in case of rule name collision ## 0.25.15 diff --git a/charts/victoria-metrics-k8s-stack/templates/rules/rule.yaml b/charts/victoria-metrics-k8s-stack/templates/rules/rule.yaml index 22aece154..7a8a01e9c 100644 --- a/charts/victoria-metrics-k8s-stack/templates/rules/rule.yaml +++ b/charts/victoria-metrics-k8s-stack/templates/rules/rule.yaml @@ -1,4 +1,5 @@ {{- if .Values.defaultRules.create }} +{{- $existingRules := default list }} {{- /* Default rules alias @@ -98,12 +99,18 @@ Filter out ignore rules Check if group is enabled */}} {{- if (and $rulesSpec (dig "create" true $group) $groupCondition) }} +{{- $ruleName := (include "victoria-metrics-k8s-stack.rulegroup.name" $ctx) }} +{{- if has $ruleName $existingRules }} + {{- fail ($existingRules | join ",") }} + {{- fail "Rule name collision was met most likely due to truncated up to 63 symbols resource name. Please consider using `fullnameOverride` or `global.fullnameOverride` to set a shorter name prefix"}} +{{- end }} +{{- $existingRules = append $existingRules $ruleName }} --- apiVersion: operator.victoriametrics.com/v1beta1 kind: VMRule metadata: namespace: {{ include "vm.namespace" $ }} - name: {{ include "victoria-metrics-k8s-stack.rulegroup.name" $ctx }} + name: {{ $ruleName }} {{- with (include "victoria-metrics-k8s-stack.rulegroup.labels" $ctx) }} labels: {{ . | nindent 4 }} {{- end }}