[common] Update to 2.4.0 (#550)

* [common] Add envValueFrom

* Add unit tests

Co-authored-by: ᗪєνιη ᗷυнʟ <onedr0p@users.noreply.github.com>
This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2021-02-05 13:44:48 +01:00 committed by GitHub
parent a5cd196a7f
commit 3d64b1c07a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 42 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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

View File

@ -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 = {