From 4fbf122ddefc5c5ac826ea80157c89d8e92423c5 Mon Sep 17 00:00:00 2001 From: Alexey Voronov Date: Tue, 9 Dec 2025 20:27:36 +0700 Subject: [PATCH 1/2] Add dnsPolicy template (#162) --------- Signed-off-by: Alexey Voronov --- charts/helm_lib/Chart.yaml | 2 +- charts/helm_lib/README.md | 13 ++++++++++++ charts/helm_lib/templates/_dns_policy.tpl | 12 +++++++++++ tests/templates/helm_lib_dns_policy.yaml | 1 + tests/tests/helm_lib_dns_policy_test.yaml | 25 +++++++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 charts/helm_lib/templates/_dns_policy.tpl create mode 100644 tests/templates/helm_lib_dns_policy.yaml create mode 100644 tests/tests/helm_lib_dns_policy_test.yaml diff --git a/charts/helm_lib/Chart.yaml b/charts/helm_lib/Chart.yaml index c745be0..fd9cca7 100644 --- a/charts/helm_lib/Chart.yaml +++ b/charts/helm_lib/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 type: library name: deckhouse_lib_helm -version: 1.65.0 +version: 1.65.1 description: "Helm utils template definitions for Deckhouse modules." diff --git a/charts/helm_lib/README.md b/charts/helm_lib/README.md index 60d3b68..7564dbb 100644 --- a/charts/helm_lib/README.md +++ b/charts/helm_lib/README.md @@ -11,6 +11,8 @@ | [helm_lib_get_api_version_by_kind](#helm_lib_get_api_version_by_kind) | | **Csi Controller** | | [helm_lib_csi_image_with_common_fallback](#helm_lib_csi_image_with_common_fallback) | +| **Dns Policy** | +| [helm_lib_dns_policy_bootstraping_state](#helm_lib_dns_policy_bootstraping_state) | | **Enable Ds Eviction** | | [helm_lib_prevent_ds_eviction_annotation](#helm_lib_prevent_ds_eviction_annotation) | | **Envs For Proxy** | @@ -182,6 +184,17 @@ list: - Container raw name - Kubernetes semantic version +## Dns Policy + +### helm_lib_dns_policy_bootstraping_state + + returns the proper dnsPolicy value depending on the cluster bootstrap phase + +#### Usage + +`{{ include "helm_lib_dns_policy_bootstraping_state" (list . "Default" "ClusterFirstWithHostNet") }} ` + + ## Enable Ds Eviction ### helm_lib_prevent_ds_eviction_annotation diff --git a/charts/helm_lib/templates/_dns_policy.tpl b/charts/helm_lib/templates/_dns_policy.tpl new file mode 100644 index 0000000..31d3e73 --- /dev/null +++ b/charts/helm_lib/templates/_dns_policy.tpl @@ -0,0 +1,12 @@ +{{- /* Usage: {{ include "helm_lib_dns_policy_bootstraping_state" (list . "Default" "ClusterFirstWithHostNet") }} */ -}} +{{- /* returns the proper dnsPolicy value depending on the cluster bootstrap phase */ -}} +{{- define "helm_lib_dns_policy_bootstraping_state" }} +{{- $context := index . 0 }} +{{- $valueDuringBootstrap := index . 1 }} +{{- $valueAfterBootstrap := index . 2 }} +{{- if $context.Values.global.clusterIsBootstrapped }} +{{- printf $valueAfterBootstrap }} +{{- else }} +{{- printf $valueDuringBootstrap }} +{{- end }} +{{- end }} diff --git a/tests/templates/helm_lib_dns_policy.yaml b/tests/templates/helm_lib_dns_policy.yaml new file mode 100644 index 0000000..ca81395 --- /dev/null +++ b/tests/templates/helm_lib_dns_policy.yaml @@ -0,0 +1 @@ +dnsPolicy: {{ include "helm_lib_dns_policy_bootstraping_state" (list . "Default" "ClusterFirstWithHostNet") }} diff --git a/tests/tests/helm_lib_dns_policy_test.yaml b/tests/tests/helm_lib_dns_policy_test.yaml new file mode 100644 index 0000000..5bb6150 --- /dev/null +++ b/tests/tests/helm_lib_dns_policy_test.yaml @@ -0,0 +1,25 @@ +suite: helm_lib_dns_policy definition +templates: + - helm_lib_dns_policy.yaml +tests: + - it: renders one value with bootstraped cluster + + set: + global: + clusterIsBootstrapped: true + + asserts: + - equal: + path: "dnsPolicy" + value: "ClusterFirstWithHostNet" + + - it: renders another value with bootstraped cluster + + set: + global: + clusterIsBootstrapped: false + + asserts: + - equal: + path: "dnsPolicy" + value: "Default" From 1adf6d3bbdbacf499fa16073221921a99666259e Mon Sep 17 00:00:00 2001 From: Sergey Kurkin Date: Fri, 19 Dec 2025 16:25:07 +0300 Subject: [PATCH 2/2] check definitionStruct not null in prometheus rules Signed-off-by: Sergey Kurkin --- charts/helm_lib/Chart.yaml | 2 +- .../templates/_monitoring_prometheus_rules.tpl | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/charts/helm_lib/Chart.yaml b/charts/helm_lib/Chart.yaml index fd9cca7..620cf27 100644 --- a/charts/helm_lib/Chart.yaml +++ b/charts/helm_lib/Chart.yaml @@ -1,5 +1,5 @@ apiVersion: v2 type: library name: deckhouse_lib_helm -version: 1.65.1 +version: 1.65.2 description: "Helm utils template definitions for Deckhouse modules." diff --git a/charts/helm_lib/templates/_monitoring_prometheus_rules.tpl b/charts/helm_lib/templates/_monitoring_prometheus_rules.tpl index 7aed8f9..20cabef 100644 --- a/charts/helm_lib/templates/_monitoring_prometheus_rules.tpl +++ b/charts/helm_lib/templates/_monitoring_prometheus_rules.tpl @@ -51,9 +51,10 @@ {{- $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 }} + {{- if $group.rules }} + {{- $_ := unset $group "name" }} + {{- $resourceName = $resourceName | replace "propagated-" "" }} + {{- $groupResourceName := printf "%s-%d" $resourceName $idx }} --- apiVersion: observability.deckhouse.io/v1alpha1 kind: {{ $propagated | ternary "ClusterObservabilityPropagatedMetricsRulesGroup" "ClusterObservabilityMetricsRulesGroup" }} @@ -62,8 +63,10 @@ metadata: {{- include "helm_lib_module_labels" (list $context (dict "app" "prometheus" "prometheus" "main" "component" "rules")) | nindent 2 }} spec: {{- $group | toYaml | nindent 2 }} + {{- end }} {{- end }} {{- else }} + {{- if $definitionStruct.Rules }} {{- $definition := $definitionStruct.Rules | toYaml }} --- apiVersion: monitoring.coreos.com/v1 @@ -75,6 +78,7 @@ metadata: spec: groups: {{- $definition | nindent 4 }} + {{- end }} {{- end }} {{- end }}