Skip to content

Commit

Permalink
wip: refactor common.environment.render [pack]
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Feb 2, 2022
1 parent 971d964 commit e10a19a
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 29 deletions.
20 changes: 1 addition & 19 deletions charts/common/templates/_.environment.tpl
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
{{/*
Renders an object that contains a list of key/value properties that can be transformed into environement variables
Usage:
{{ include "common.environment.render" . }}
{{ include "common.environment.render" (dict "env" .Values.path.to.the.env "context" $) }}
*/}}
{{- define "common.environment.render" -}}
{{- $defaultSecret := include "common.names.secret" . }}
{{- range $key, $value := .Values.env }}
- name: {{ $key | snakecase | upper}}
{{- if kindIs "map" $value }}
valueFrom:
secretKeyRef:
name: {{ $value.secret | default $defaultSecret }}
key: {{ $value.key | default (kebabcase $key) }}
{{- else }}
value: {{ include "common.tplvalues.render" (dict "value" $value "context" $) | quote }}
{{- end }}
{{- end }}
{{- end -}}


{{/*
*/}}
{{- define "common.environment.renderImpl" -}}
{{- $defaultSecret := include "common.names.secret" .context }}
{{- range $key, $value := .env }}
- name: {{ $key | snakecase | upper}}
Expand Down
6 changes: 3 additions & 3 deletions charts/common/templates/_envsubstConfig.tpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Renders an object that contains a list of key/value properties that can be transformed into environement variables
Usage:
{{ include "common.environment.render" . }}
{{ include "common.envsubstConfig.renderInitContainer" . }}
*/}}
{{- define "common.envsubstConfig.renderInitContainer" -}}
- name: envsubst-config
Expand All @@ -28,7 +28,7 @@ Usage:
- '{}'
- ';'
env:
{{- include "common.environment.renderImpl" (dict "env" .args.env "context" .context) | indent 4 }}
{{- include "common.environment.render" (dict "env" .args.env "context" .context) | indent 4 }}
volumeMounts:
- mountPath: /templated
name: envsubst-template-config
Expand All @@ -40,7 +40,7 @@ Usage:
{{/*
Renders an object that contains a list of key/value properties that can be transformed into environement variables
Usage:
{{ include "common.environment.render" . }}
{{ include "common.envsubstConfig.renderVolume" . }}
*/}}
{{- define "common.envsubstConfig.renderVolume" -}}
- name: envsubst-template-config
Expand Down
2 changes: 1 addition & 1 deletion charts/common/templates/_kdk-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
name: {{ .Values.distribution.redisUrl.secret | default (include "common.names.secret" .) }}
key: {{ .Values.distribution.redisUrl.key | default "redis-url" }}
{{- end }}
{{- include "common.environment.render" . | indent 12 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 12 }}
ports:
- name: {{ include "common.names.name" . }}
containerPort: 8081
Expand Down
2 changes: 1 addition & 1 deletion charts/common/templates/_krawler-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
env:
- name: CRON
value: ""
{{- include "common.environment.render" . | indent 16 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 16 }}
{{- if .Values.volumeMounts }}
volumeMounts:
{{- include "common.tplvalues.render" ( dict "value" .Values.volumeMounts "context" $ ) | nindent 14 }}
Expand Down
2 changes: 1 addition & 1 deletion charts/express-gateway/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
- name: HTTP_PROXY
- name: HTTPS_PROXY
- name: NO_PROXY
{{- include "common.environment.render" . | indent 12 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 12 }}
ports:
- name: {{ include "common.names.name" . }}
containerPort: 8080
Expand Down
2 changes: 1 addition & 1 deletion charts/k2/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- include "common.environment.render" . | indent 12 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 12 }}
ports:
- name: {{ include "common.names.name" . }}
containerPort: 8080
Expand Down
2 changes: 1 addition & 1 deletion charts/kapture/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- include "common.environment.render" . | indent 12 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 12 }}
ports:
- name: {{ include "common.names.name" . }}
containerPort: 3000
Expand Down
2 changes: 1 addition & 1 deletion charts/mongo-express/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- include "common.environment.render" . | indent 12 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 12 }}
ports:
- name: {{ include "common.names.name" . }}
containerPort: 8081
Expand Down
2 changes: 1 addition & 1 deletion charts/redis-commander/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
{{- include "common.environment.render" . | indent 12 }}
{{- include "common.environment.render" (dict "env" .Values.env "context" $) | indent 12 }}
ports:
- name: {{ include "common.names.name" . }}
containerPort: 8081
Expand Down

0 comments on commit e10a19a

Please sign in to comment.