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.65.0
version: 1.65.2
description: "Helm utils template definitions for Deckhouse modules."
13 changes: 13 additions & 0 deletions charts/helm_lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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** |
Expand Down Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions charts/helm_lib/templates/_dns_policy.tpl
Original file line number Diff line number Diff line change
@@ -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 }}
10 changes: 7 additions & 3 deletions charts/helm_lib/templates/_monitoring_prometheus_rules.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
Expand All @@ -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
Expand All @@ -75,6 +78,7 @@ metadata:
spec:
groups:
{{- $definition | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}

Expand Down
1 change: 1 addition & 0 deletions tests/templates/helm_lib_dns_policy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dnsPolicy: {{ include "helm_lib_dns_policy_bootstraping_state" (list . "Default" "ClusterFirstWithHostNet") }}
25 changes: 25 additions & 0 deletions tests/tests/helm_lib_dns_policy_test.yaml
Original file line number Diff line number Diff line change
@@ -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"