Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/helm_lib/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
type: library
name: deckhouse_lib_helm
version: 1.64.6
version: 1.64.7
description: "Helm utils template definitions for Deckhouse modules."
22 changes: 20 additions & 2 deletions charts/helm_lib/templates/_monitoring_prometheus_rules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,29 @@

{{- end }}

{{ $definition = $definitionStruct.Rules | toYaml }}

{{- $resourceName := (regexReplaceAllLiteral "\\.(yaml|tpl)$" $path "") }}
{{- $resourceName = ($resourceName | replace " " "-" | replace "." "-" | replace "_" "-") }}
{{- $resourceName = (slice ($resourceName | splitList "/") $folderNamesIndex | join "-") }}
{{- $resourceName = (printf "%s-%s" $context.Chart.Name $resourceName) }}
{{- $propagated := contains "propagated-" $resourceName }}
{{- $hasObservabilityModule := has "observability" $context.Values.global.enabledModules }}
{{- $useObservabilityRules := has "observability.deckhouse.io/v1alpha1/ClusterObservabilityMetricsRulesGroup" $context.Values.global.discovery.apiVersions }}
{{- if and $hasObservabilityModule $useObservabilityRules }}
{{- range $idx, $group := $definitionStruct.Rules }}
{{- $_ := unset $group "name" }}
{{- $resourceName = $resourceName | replace "propagated-" "" }}
{{- $groupResourceName := printf "%s-%d" $resourceName $idx }}
---
apiVersion: observability.deckhouse.io/v1alpha1
kind: {{ $propagated | ternary "ClusterObservabilityPropagatedMetricsRulesGroup" "ClusterObservabilityMetricsRulesGroup" }}
metadata:
name: {{ $groupResourceName }}
{{- include "helm_lib_module_labels" (list $context (dict "app" "prometheus" "prometheus" "main" "component" "rules")) | nindent 2 }}
spec:
{{- $group | toYaml | nindent 2 }}
{{- end }}
{{- else }}
{{- $definition := $definitionStruct.Rules | toYaml }}
---
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
Expand All @@ -58,6 +75,7 @@ metadata:
spec:
groups:
{{- $definition | nindent 4 }}
{{- end }}
{{- end }}

{{- $subDirs := list }}
Expand Down
1 change: 1 addition & 0 deletions tests/templates/helm_lib_prometheus_rules_recursion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{- include "helm_lib_prometheus_rules_recursion" (list . "d8-observability" "testdata/monitoring") }}
13 changes: 13 additions & 0 deletions tests/testdata/monitoring/deadbeef/propagated-ingress-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- name: kubernetes.ingress-nginx.group-one
rules:
- alert: NginxIngressSslWillExpire
expr: vector(1)
- alert: NginxIngressSslExpired
expr: vector(1)
- name: kubernetes.ingress-nginx.group-two
rules:
- alert: NginxIngress5xxErrors
expr: vector(1)
- alert: NginxIngress5xxErrors
expr: vector(1)

37 changes: 37 additions & 0 deletions tests/tests/helm_lib_prometheus_rules_recursion_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
suite: test helm_lib_prometheus_rules_recursion
templates:
- helm_lib_prometheus_rules_recursion.yaml
tests:
- it: should generate PrometheusRule
set:
global.enabledModules: ["observability"]
global.discovery.prometheusScrapeInterval: 30s
global.discovery.apiVersions: []
asserts:
- equal:
path: kind
value: PrometheusRule
- equal:
path: metadata.name
value: test-module-deadbeef-propagated-ingress-nginx
- hasDocuments:
count: 1
- it: should generate ClusterObservabilityPropagatedMetricsRulesGroup
set:
global.enabledModules: ["observability"]
global.discovery.prometheusScrapeInterval: 30s
global.discovery.apiVersions: ["observability.deckhouse.io/v1alpha1/ClusterObservabilityMetricsRulesGroup"]
asserts:
- equal:
path: kind
value: ClusterObservabilityPropagatedMetricsRulesGroup
- equal:
path: metadata.name
value: test-module-deadbeef-ingress-nginx-0
documentIndex: 0
- equal:
path: metadata.name
value: test-module-deadbeef-ingress-nginx-1
documentIndex: 1
- hasDocuments:
count: 2