From 3d64b1c07ac6e729f0e1a90af4974438f1b448b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=E1=B4=87=CA=80=C9=B4=E1=B4=85=20S=E1=B4=84=CA=9C?= =?UTF-8?q?=E1=B4=8F=CA=80=C9=A2=E1=B4=87=CA=80s?= <6213398+bjw-s@users.noreply.github.com> Date: Fri, 5 Feb 2021 13:44:48 +0100 Subject: [PATCH] [common] Update to 2.4.0 (#550) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [common] Add envValueFrom * Add unit tests Co-authored-by: ᗪєνιη ᗷυнʟ --- charts/common/CHANGELOG.md | 10 ++++++++++ charts/common/Chart.yaml | 2 +- .../templates/lib/controller/_container.tpl | 7 ++++++- charts/common/values.yaml | 12 ++++++++++-- test/charts/common-test_spec.rb | 16 +++++++++++++++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/charts/common/CHANGELOG.md b/charts/common/CHANGELOG.md index 80fd089a..cdb4339d 100644 --- a/charts/common/CHANGELOG.md +++ b/charts/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/charts/common/Chart.yaml b/charts/common/Chart.yaml index 7a7cb96d..48b9015d 100644 --- a/charts/common/Chart.yaml +++ b/charts/common/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: common description: Function library for k8s-at-home charts type: library -version: 2.3.0 +version: 2.4.0 keywords: - k8s-at-home - common diff --git a/charts/common/templates/lib/controller/_container.tpl b/charts/common/templates/lib/controller/_container.tpl index c8393d74..b8d77fae 100644 --- a/charts/common/templates/lib/controller/_container.tpl +++ b/charts/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 $key, $value := .Values.env }} - name: {{ $key }} @@ -25,6 +25,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/charts/common/values.yaml b/charts/common/values.yaml index 19ccccfd..ceb206e2 100644 --- a/charts/common/values.yaml +++ b/charts/common/values.yaml @@ -33,12 +33,20 @@ serviceAccount: name: "" env: {} -# TZ: UTC + # TZ: UTC ## 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 diff --git a/test/charts/common-test_spec.rb b/test/charts/common-test_spec.rb index 3227c544..1afebff5 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 = {