Add injector.extraEnvironmentVars (#232)

Allows user-specified environment variables to be set in the injector
deployment.
This commit is contained in:
Theron Voran 2020-03-18 21:30:22 -07:00 committed by GitHub
parent 9e0030d70a
commit fa13c47858
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 2 deletions

View file

@ -288,9 +288,9 @@ Inject extra environment vars in the format key:value, if populated
{{- define "vault.extraEnvironmentVars" -}} {{- define "vault.extraEnvironmentVars" -}}
{{- if .extraEnvironmentVars -}} {{- if .extraEnvironmentVars -}}
{{- range $key, $value := .extraEnvironmentVars }} {{- range $key, $value := .extraEnvironmentVars }}
- name: {{ $key }} - name: {{ printf "%s" $key | replace "." "_" | upper | quote }}
value: {{ $value | quote }} value: {{ $value | quote }}
{{- end -}} {{- end }}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View file

@ -64,6 +64,7 @@ spec:
value: {{ .Values.injector.logFormat | default "standard" }} value: {{ .Values.injector.logFormat | default "standard" }}
- name: AGENT_INJECT_REVOKE_ON_SHUTDOWN - name: AGENT_INJECT_REVOKE_ON_SHUTDOWN
value: "{{ .Values.injector.revokeOnShutdown | default false }}" value: "{{ .Values.injector.revokeOnShutdown | default false }}"
{{- include "vault.extraEnvironmentVars" .Values.injector | nindent 12 }}
args: args:
- agent-inject - agent-inject
- 2>&1 - 2>&1

View file

@ -321,3 +321,41 @@ load _helpers
yq -r '.[8].value' | tee /dev/stderr) yq -r '.[8].value' | tee /dev/stderr)
[ "${actual}" = "true" ] [ "${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" ]
}

View file

@ -81,6 +81,11 @@ injector:
# memory: 256Mi # memory: 256Mi
# cpu: 250m # cpu: 250m
# extraEnvironmentVars is a list of extra enviroment variables to set in the
# injector deployment.
extraEnvironmentVars: {}
# KUBERNETES_SERVICE_HOST: kubernetes.default.svc
server: server:
# Resource requests, limits, etc. for the server cluster placement. This # Resource requests, limits, etc. for the server cluster placement. This
# should map directly to the value of the resources field for a PodSpec. # should map directly to the value of the resources field for a PodSpec.