Skip to content

Commit

Permalink
Add injector.extraEnvironmentVars (hashicorp#232)
Browse files Browse the repository at this point in the history
Allows user-specified environment variables to be set in the injector
deployment.
  • Loading branch information
tvoran authored and hadielaham88 committed May 19, 2021
1 parent 4bd6a0f commit 1ddf675
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
4 changes: 2 additions & 2 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ Inject extra environment vars in the format key:value, if populated
{{- define "vault.extraEnvironmentVars" -}}
{{- if .extraEnvironmentVars -}}
{{- range $key, $value := .extraEnvironmentVars }}
- name: {{ $key }}
- name: {{ printf "%s" $key | replace "." "_" | upper | quote }}
value: {{ $value | quote }}
{{- end -}}
{{- end }}
{{- end -}}
{{- end -}}
Expand Down
1 change: 1 addition & 0 deletions templates/injector-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ spec:
value: {{ .Values.injector.logFormat | default "standard" }}
- name: AGENT_INJECT_REVOKE_ON_SHUTDOWN
value: "{{ .Values.injector.revokeOnShutdown | default false }}"
{{- include "vault.extraEnvironmentVars" .Values.injector | nindent 12 }}
args:
- agent-inject
- 2>&1
Expand Down
38 changes: 38 additions & 0 deletions test/unit/injector-deployment.bats
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,41 @@ load _helpers
yq -r '.[8].value' | tee /dev/stderr)
[ "${actual}" = "true" ]
}

#--------------------------------------------------------------------
# extraEnvironmentVars

@test "injector/deployment: set extraEnvironmentVars" {
cd `chart_dir`
local object=$(helm template \
--show-only templates/injector-deployment.yaml \
--set 'injector.extraEnvironmentVars.FOO=bar' \
--set 'injector.extraEnvironmentVars.FOOBAR=foobar' \
--set 'injector.extraEnvironmentVars.lower\.case=sanitized' \
. | tee /dev/stderr |
yq -r '.spec.template.spec.containers[0].env' | tee /dev/stderr)

local actual=$(echo $object |
yq -r '.[9].name' | tee /dev/stderr)
[ "${actual}" = "FOO" ]

local actual=$(echo $object |
yq -r '.[9].value' | tee /dev/stderr)
[ "${actual}" = "bar" ]

local actual=$(echo $object |
yq -r '.[10].name' | tee /dev/stderr)
[ "${actual}" = "FOOBAR" ]

local actual=$(echo $object |
yq -r '.[10].value' | tee /dev/stderr)
[ "${actual}" = "foobar" ]

local actual=$(echo $object |
yq -r '.[11].name' | tee /dev/stderr)
[ "${actual}" = "LOWER_CASE" ]

local actual=$(echo $object |
yq -r '.[11].value' | tee /dev/stderr)
[ "${actual}" = "sanitized" ]
}
5 changes: 5 additions & 0 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ injector:
# memory: 256Mi
# cpu: 250m

# extraEnvironmentVars is a list of extra enviroment variables to set in the
# injector deployment.
extraEnvironmentVars: {}
# KUBERNETES_SERVICE_HOST: kubernetes.default.svc

server:
# Resource requests, limits, etc. for the server cluster placement. This
# should map directly to the value of the resources field for a PodSpec.
Expand Down

0 comments on commit 1ddf675

Please sign in to comment.