Skip to content

Commit

Permalink
feat: envVars as array or as dict (#24)
Browse files Browse the repository at this point in the history
* feat: envVars as array or as dict

* refactor: simplify toEnvArray slice case

Co-authored-by: Mohammad Abdolirad <[email protected]>

* refactor: simplify toEnvArray map case

* docs: remove example of map envVar with value property

Co-authored-by: Mohammad Abdolirad <[email protected]>

---------

Co-authored-by: Mohammad Abdolirad <[email protected]>
  • Loading branch information
zevisert and atkrad authored Oct 11, 2023
1 parent 8dce241 commit 78803f2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions charts/helmet/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: helmet
description: Helmet is a library Helm Chart for grouping common logics. This chart is not deployable by itself.
home: https://github.com/companyinfo/helm-charts/blob/main/charts/helmet
type: library
version: "0.9.1"
appVersion: "0.9.1"
version: "0.10.0"
appVersion: "0.10.0"
keywords:
- common
- helper
Expand Down
2 changes: 1 addition & 1 deletion charts/helmet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ $ helm install nginx .
| `initContainers` | Add additional init containers to the APP pod(s) | `[]` |
| `command` | Override main container's command | `[]` |
| `args` | Override main container's args | `[]` |
| `envVars` | Environment variables to be set on APP container | `[]` |
| `envVars` | Environment variables to be set on APP container | `{} or []` |
| `envVarsConfigMap` | ConfigMap with environment variables | `""` |
| `envVarsSecret` | Secret with environment variables | `""` |

Expand Down
10 changes: 5 additions & 5 deletions charts/helmet/examples/simple/Chart.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies:
- name: helmet
repository: https://nexus.ci.fdmg.org/repository/helm-repo
version: 0.4.5
digest: sha256:53133e3ee01ee1612bfc649c43a7e0086794a8c509f070b1fe572d748f44a25c
generated: "2022-09-05T16:44:32.831090129+02:00"
- name: helmet
repository: https://companyinfo.github.io/helm-charts
version: 0.10.0
digest: sha256:91533ef53882c22edf53d0c80fe48cccfc4dba0a0fbc536383d44fc914b1c8c8
generated: "2023-09-27T17:51:06.480705091-07:00"
5 changes: 3 additions & 2 deletions charts/helmet/examples/simple/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ appVersion: "0.1.0"
maintainers:
- name: Company.info Developers
url: https://company.info

dependencies:
- name: helmet
version: 0.4.5
repository: https://nexus.ci.fdmg.org/repository/helm-repo
version: ^0
repository: https://companyinfo.github.io/helm-charts
import-values:
- defaults
2 changes: 1 addition & 1 deletion charts/helmet/templates/_deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
args: {{- include "common.tplvalues.render" (dict "value" .Values.args "context" $) | nindent 12 }}
{{- end }}
{{- if .Values.envVars }}
env: {{- include "common.tplvalues.render" (dict "value" .Values.envVars "context" $) | nindent 12 }}
env: {{- include "helmet.toEnvArray" (dict "envVars" .Values.envVars "context" $) | indent 12 }}
{{- end }}
{{- if or .Values.envVarsConfigMap .Values.envVarsSecret }}
envFrom:
Expand Down
22 changes: 22 additions & 0 deletions charts/helmet/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,25 @@ Create the name of the service account to use
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}


{{/*
Render an array of env variables. The input can be a map or a slice.
Values can be templates using the "common.tplvalues.render" helper, but changes to scope are not processed.
Usage:
{{ include "helmet.toEnvArray" ( dict "envVars" .Values.envVars "context" $ ) }}
*/}}
{{- define "helmet.toEnvArray" -}}
{{- if kindIs "map" .envVars }}
{{- range $key, $val := .envVars }}
- name: {{ $key }}
{{- if kindIs "string" $val }}
value: {{ include "common.tplvalues.render" (dict "value" $val "context" $.context) }}
{{- else if kindIs "map" $val }}
{{ include "common.tplvalues.render" (dict "value" (omit $val "name") "context" $.context) | indent 2 }}
{{- end -}}
{{- end -}}
{{- else if kindIs "slice" .envVars }}
{{ include "common.tplvalues.render" (dict "value" .envVars "context" $.context) }}
{{- end }}
{{- end -}}
8 changes: 5 additions & 3 deletions charts/helmet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,12 @@ exports:
## @param envVars Environment variables to be set on APP container
## Example:
## envVars:
## - name: FOO
## value: "bar"
## FOO: "foo"
## BAZ:
## valueFrom:
## configMapRef: ...
##
envVars: []
envVars: null

## @param envVarsConfigMap ConfigMap with environment variables
##
Expand Down

0 comments on commit 78803f2

Please sign in to comment.