diff --git a/charts/base/Chart.yaml b/charts/base/Chart.yaml index ab60896..02c6e77 100644 --- a/charts/base/Chart.yaml +++ b/charts/base/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: base description: Base Helm chart for Kubernetes - fully values-driven. type: application -version: 0.6.0 +version: 0.6.1 maintainers: - name: bonddim sources: diff --git a/charts/base/README.md b/charts/base/README.md index ef19a23..964decf 100644 --- a/charts/base/README.md +++ b/charts/base/README.md @@ -1,6 +1,6 @@ # base -![Version: 0.6.0](https://img.shields.io/badge/Version-0.6.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 0.6.1](https://img.shields.io/badge/Version-0.6.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) Base Helm chart for Kubernetes - fully values-driven. @@ -251,7 +251,7 @@ Base Helm chart for Kubernetes - fully values-driven. | configMap.enabled | bool | `false` | Whether to create a ConfigMap resource. | | configMap.annotations | object | `{}` | Annotations for the ConfigMap. | | configMap.labels | object | `{}` | Labels for the ConfigMap. | -| configMap.data | object | `{}` | Key/value data for the ConfigMap. | +| configMap.data | object | `{}` | Key/value data for the ConfigMap (tpl-rendered). A map or list value is rendered as a YAML document, e.g. `{ config.yaml: { log: { level: info } } }`, so it can be deep-merged across values files. | ### Secret parameters @@ -268,7 +268,7 @@ Base Helm chart for Kubernetes - fully values-driven. | Key | Type | Default | Description | |-----|------|---------|-------------| -| extraObjects | object/list | `[]` | Render additional Kubernetes manifests. Each entry may be a string (with Go template expressions) or a YAML object. | +| extraObjects | object/list | `{}` | Render additional Kubernetes manifests. Each entry may be a string (with Go template expressions) or a YAML object. | ---------------------------------------------- Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2) diff --git a/charts/base/templates/config/configmap.yaml b/charts/base/templates/config/configmap.yaml index 811cf18..bcc9354 100644 --- a/charts/base/templates/config/configmap.yaml +++ b/charts/base/templates/config/configmap.yaml @@ -9,6 +9,12 @@ metadata: name: {{ include "base.fullname" . }} data: {{- range $key, $value := .Values.configMap.data }} - {{ $key }}: {{ $value | quote }} + {{- $rendered := include "base.render.value" (dict "value" $value "context" $) }} + {{- if or (kindIs "map" $value) (kindIs "slice" $value) (contains "\n" $rendered) }} + {{ $key }}: | + {{- $rendered | nindent 4 }} + {{- else }} + {{ $key }}: {{ $rendered | quote }} + {{- end }} {{- end }} {{- end }} diff --git a/charts/base/tests/configmap_test.yaml b/charts/base/tests/configmap_test.yaml new file mode 100644 index 0000000..f06ae5e --- /dev/null +++ b/charts/base/tests/configmap_test.yaml @@ -0,0 +1,71 @@ +suite: configmap +templates: + - config/configmap.yaml +tests: + - it: renders plain string values as-is + set: + configMap.enabled: true + configMap.data: + LOG_LEVEL: info + asserts: + - equal: + path: data.LOG_LEVEL + value: info + + - it: quotes scalar values that are not strings + set: + configMap.enabled: true + configMap.data: + WORKERS: 4 + DEBUG: true + asserts: + - equal: + path: data.WORKERS + value: "4" + - equal: + path: data.DEBUG + value: "true" + + - it: templates string values + release: + name: myapp + set: + configMap.enabled: true + configMap.data: + SERVICE_HOST: "{{ .Release.Name }}-api" + asserts: + - equal: + path: data.SERVICE_HOST + value: myapp-api + + - it: renders map values as a YAML document + set: + configMap.enabled: true + configMap.data: + config.yaml: + Log: + Level: Debug + Database: + Host: db + asserts: + - equal: + path: data["config.yaml"] + value: | + Database: + Host: db + Log: + Level: Debug + + - it: templates inside map values + release: + namespace: dev + set: + configMap.enabled: true + configMap.data: + config.yaml: + VaultUrl: "https://kv-{{ .Release.Namespace }}.vault.azure.net" + asserts: + - equal: + path: data["config.yaml"] + value: | + VaultUrl: https://kv-dev.vault.azure.net diff --git a/charts/base/values.yaml b/charts/base/values.yaml index f54a283..49b5a65 100644 --- a/charts/base/values.yaml +++ b/charts/base/values.yaml @@ -619,7 +619,8 @@ configMap: # -- Labels for the ConfigMap. # @section -- ConfigMap parameters labels: {} - # -- Key/value data for the ConfigMap. + # -- Key/value data for the ConfigMap (tpl-rendered). A map or list value is rendered as a YAML document, + # e.g. `{ config.yaml: { log: { level: info } } }`, so it can be deep-merged across values files. # @section -- ConfigMap parameters data: {} @@ -648,4 +649,4 @@ secret: ######################################################################## # -- (object/list) Render additional Kubernetes manifests. Each entry may be a string (with Go template expressions) or a YAML object. # @section -- Extras -extraObjects: [] +extraObjects: {}