From fe8069a22df0dcefbe1860a2686c88ca514a3ae8 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Fri, 29 Jan 2021 16:14:05 +0500 Subject: [PATCH] Add method to retrieve image/annotations and secrets configuration --- library/common/templates/lib/chart/_annotations.tpl | 6 ++++++ .../common/templates/lib/containers/_environment.tpl | 11 ++++++++++- library/common/templates/lib/containers/_image.tpl | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 library/common/templates/lib/chart/_annotations.tpl create mode 100644 library/common/templates/lib/containers/_image.tpl diff --git a/library/common/templates/lib/chart/_annotations.tpl b/library/common/templates/lib/chart/_annotations.tpl new file mode 100644 index 0000000000..ad80be1e90 --- /dev/null +++ b/library/common/templates/lib/chart/_annotations.tpl @@ -0,0 +1,6 @@ +{{/* +Common workload annotations +*/}} +{{- define "common.annotations" -}} +rollme: {{ randAlphaNum 5 | quote }} +{{- end -}} diff --git a/library/common/templates/lib/containers/_environment.tpl b/library/common/templates/lib/containers/_environment.tpl index df1533527e..7bf6ccef56 100644 --- a/library/common/templates/lib/containers/_environment.tpl +++ b/library/common/templates/lib/containers/_environment.tpl @@ -5,8 +5,17 @@ Render environment variables {{- $values := . -}} {{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "environmentVariables")) -}} {{- range $envVariable := $values.environmentVariables -}} -{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "name" "value")) -}} +{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "name")) -}} - name: {{ $envVariable.name }} +{{- if $envVariable.valueFromSecret -}} +{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "secretName" "secretKey")) -}} + valueFrom: + secretKeyRef: + name: {{ $envVariable.secretName }} + key: {{ $envVariable.secretKey }} +{{- else -}} +{{- include "common.schema.validateKeys" (dict "values" $envVariable "checkKeys" (list "value")) -}} value: {{ $envVariable.value }} {{- end -}} {{- end -}} +{{- end -}} diff --git a/library/common/templates/lib/containers/_image.tpl b/library/common/templates/lib/containers/_image.tpl new file mode 100644 index 0000000000..4a5a368008 --- /dev/null +++ b/library/common/templates/lib/containers/_image.tpl @@ -0,0 +1,9 @@ +{{/* +Retrieve image configuration for container +*/}} +{{- define "common.containers.imageConfig" -}} +{{- $values := . -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "repository" "tag" "pullPolicy")) -}} +image: "{{ $values.repository }}:{{ $values.tag }}" +imagePullPolicy: {{ $values.pullPolicy }} +{{- end -}}