From ec561f6512f6e8d511a1b90b976e087460750c2d Mon Sep 17 00:00:00 2001 From: kjeld Schouten-Lebbing Date: Mon, 8 Feb 2021 16:10:14 +0100 Subject: [PATCH] Update and clean common chart Signed-off-by: Kjeld Schouten-Lebbing --- .test/charts/common-test_spec.rb | 16 ++++++++++- library/common/CHANGELOG.md | 10 +++++++ library/common/Chart.yaml | 4 +-- library/common/_ingress.tpl | 27 ------------------- .../templates/lib/controller/_container.tpl | 7 ++++- library/common/values.yaml | 10 ++++++- 6 files changed, 42 insertions(+), 32 deletions(-) delete mode 100644 library/common/_ingress.tpl diff --git a/.test/charts/common-test_spec.rb b/.test/charts/common-test_spec.rb index 144dcfbdbc4..8c4a97e01b2 100644 --- a/.test/charts/common-test_spec.rb +++ b/.test/charts/common-test_spec.rb @@ -55,7 +55,21 @@ class Test < ChartTest jq('.spec.template.spec.containers[0].env[0].name', resource('Deployment')).must_equal values[:env].keys[0].to_s jq('.spec.template.spec.containers[0].env[0].value', resource('Deployment')).must_equal values[:env].values[0].to_s end - + + it 'set "valueFrom" environment variables' do + values = { + envValueFrom: { + NODE_NAME: { + fieldRef: { + fieldPath: "spec.nodeName" + } + } + } + } + chart.value values + jq('.spec.template.spec.containers[0].env[0].name', resource('Deployment')).must_equal values[:envValueFrom].keys[0].to_s + jq('.spec.template.spec.containers[0].env[0].valueFrom | keys[0]', resource('Deployment')).must_equal values[:envValueFrom].values[0].keys[0].to_s + end it 'set "static" and "Dynamic/Tpl" environment variables' do values = { diff --git a/library/common/CHANGELOG.md b/library/common/CHANGELOG.md index 80fd089a220..cdb4339d857 100644 --- a/library/common/CHANGELOG.md +++ b/library/common/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.4.0] + +### Added + +- Allow setting environment variables from Downward API via `envValueFrom`. See [the Kubernetes docs](https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/) for more information. + ## [2.3.0] ### Added @@ -78,6 +84,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 This is the last version before starting this changelog. All sorts of cool stuff was changed, but only `git log` remembers what that was :slightly_frowning_face: +[2.4.0]: https://github.com/k8s-at-home/charts/tree/common-2.4.0/charts/common + +[2.3.0]: https://github.com/k8s-at-home/charts/tree/common-2.3.0/charts/common + [2.2.1]: https://github.com/k8s-at-home/charts/tree/common-2.2.1/charts/common [2.2.0]: https://github.com/k8s-at-home/charts/tree/common-2.2.0/charts/common diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 15aa7ea5506..0796106d720 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -2,8 +2,8 @@ apiVersion: v2 name: common description: Function library for TrueCharts type: library -version: 0.10.1 -# upstream_version: 2.3.0 +version: 0.11.1 +# upstream_version: 2.4.0 keywords: - truecharts - library-chart diff --git a/library/common/_ingress.tpl b/library/common/_ingress.tpl deleted file mode 100644 index d6ad879a26c..00000000000 --- a/library/common/_ingress.tpl +++ /dev/null @@ -1,27 +0,0 @@ -{{/* -Renders the Ingress objects required by the chart by returning a concatinated list -of the main Ingress and any additionalIngresses. -*/}} -{{- define "common.ingress" -}} - {{- if .Values.ingress.enabled -}} - {{- $svcPort := .Values.service.port.port -}} - - {{- /* Generate primary ingress */ -}} - {{- $ingressValues := .Values.ingress -}} - {{- $_ := set . "ObjectValues" (dict "ingress" $ingressValues) -}} - {{- include "common.classes.ingress" . }} - - {{- /* Generate additional ingresses as required */ -}} - {{- range $index, $extraIngress := .Values.ingress.additionalIngresses }} - {{- if $extraIngress.enabled -}} - {{- print ("---") | nindent 0 -}} - {{- $ingressValues := $extraIngress -}} - {{- if not $ingressValues.nameSuffix -}} - {{- $_ := set $ingressValues "nameSuffix" $index -}} - {{ end -}} - {{- $_ := set $ "ObjectValues" (dict "ingress" $ingressValues) -}} - {{- include "common.classes.ingress" $ -}} - {{- end }} - {{- end }} - {{- end }} -{{- end }} diff --git a/library/common/templates/lib/controller/_container.tpl b/library/common/templates/lib/controller/_container.tpl index 9c7bd8012b3..a9c389ea6a2 100644 --- a/library/common/templates/lib/controller/_container.tpl +++ b/library/common/templates/lib/controller/_container.tpl @@ -15,7 +15,7 @@ The main container included in the controller. securityContext: {{- toYaml . | nindent 4 }} {{- end }} - {{- if or .Values.env .Values.envTpl }} + {{- if or .Values.env .Values.envTpl .Values.envValueFrom }} env: {{- range $envVariable := .Values.environmentVariables }} {{- if and $envVariable.name $envVariable.value }} @@ -33,6 +33,11 @@ The main container included in the controller. - name: {{ $key }} value: {{ tpl $value $ | quote }} {{- end }} + {{- range $key, $value := .Values.envValueFrom }} + - name: {{ $key }} + valueFrom: + {{- $value | toYaml | nindent 6 }} + {{- end }} {{- end }} {{- with .Values.envFrom }} envFrom: diff --git a/library/common/values.yaml b/library/common/values.yaml index 1a91bacbadf..1ba695c6133 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -38,7 +38,15 @@ env: {} ## Variables with values set from templates, example ## With a release name of: demo, the example env value will be: demo-admin envTpl: {} -# TEMPLATE_VALUE: "{{ .Release.Name }}-admin" + # TEMPLATE_VALUE: "{{ .Release.Name }}-admin" + +## Variables with values from (for example) the Downward API +## See https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/ +envValueFrom: {} + # NODE_NAME: + # fieldRef: + # fieldPath: spec.nodeName + envFrom: [] # - configMapRef: # name: config-map-name