From 9f527e21ea6b10c0517fbeeb467ec76f1356cbc9 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Fri, 29 Jan 2021 15:53:58 +0500 Subject: [PATCH] Add method to render environment variables --- .../common/templates/lib/containers/_environment.tpl | 12 ++++++++++++ library/common/templates/lib/networking/_dns.tpl | 2 +- library/common/templates/lib/schema/_utils.tpl | 2 +- library/common/templates/lib/storage/_ixvolumes.tpl | 10 +++++----- library/common/templates/lib/storage/_volume.tpl | 12 ++++++------ 5 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 library/common/templates/lib/containers/_environment.tpl diff --git a/library/common/templates/lib/containers/_environment.tpl b/library/common/templates/lib/containers/_environment.tpl new file mode 100644 index 0000000000..df1533527e --- /dev/null +++ b/library/common/templates/lib/containers/_environment.tpl @@ -0,0 +1,12 @@ +{{/* +Render environment variables +*/}} +{{- define "common.containers.environmentVariables" -}} +{{- $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")) -}} +- name: {{ $envVariable.name }} + value: {{ $envVariable.value }} +{{- end -}} +{{- end -}} diff --git a/library/common/templates/lib/networking/_dns.tpl b/library/common/templates/lib/networking/_dns.tpl index 79a1a325d1..c95d374616 100644 --- a/library/common/templates/lib/networking/_dns.tpl +++ b/library/common/templates/lib/networking/_dns.tpl @@ -1,7 +1,7 @@ {{/* DNS Configuration */}} -{{- define "dnsConfiguration" }} +{{- define "common.networking.dnsConfiguration" }} dnsPolicy: {{ .Values.dnsPolicy }} {{- if .Values.dnsConfig }} dnsConfig: diff --git a/library/common/templates/lib/schema/_utils.tpl b/library/common/templates/lib/schema/_utils.tpl index b3a4cd0549..8577a0b615 100644 --- a/library/common/templates/lib/schema/_utils.tpl +++ b/library/common/templates/lib/schema/_utils.tpl @@ -1,7 +1,7 @@ {{/* Checks if a list of keys are present in a dictionary */}} -{{- define "common.validateKeys" -}} +{{- define "common.schema.validateKeys" -}} {{- $values := . -}} {{- if and (hasKey $values "values") (hasKey $values "checkKeys") -}} {{- $missingKeys := list -}} diff --git a/library/common/templates/lib/storage/_ixvolumes.tpl b/library/common/templates/lib/storage/_ixvolumes.tpl index bbac51a067..4827d12b4d 100644 --- a/library/common/templates/lib/storage/_ixvolumes.tpl +++ b/library/common/templates/lib/storage/_ixvolumes.tpl @@ -1,7 +1,7 @@ {{/* Retrieve host path from ix volumes based on dataset name */}} -{{- define "common.retrieveHostPathFromiXVolume" -}} +{{- define "common.storage.retrieveHostPathFromiXVolume" -}} {{- range $index, $hostPathConfiguration := $.ixVolumes }} {{- $dsName := base $hostPathConfiguration.hostPath -}} {{- if eq $.datasetName $dsName -}} @@ -13,13 +13,13 @@ Retrieve host path from ix volumes based on dataset name {{/* Retrieve host path from ix volumes based on a key */}} -{{- define "common.configuredHostPath" -}} +{{- define "common.storage.configuredHostPath" -}} {{- $values := . -}} {{- if $values.hostPathEnabled -}} -{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "pathField")) -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "pathField")) -}} {{- $values.pathField -}} {{- else -}} -{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "datasetName" "ixVolumes")) -}} -{{- include "common.retrieveHostPathFromiXVolume" (dict "datasetName" $values.datasetName "ixVolumes" $values.ixVolumes) -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "datasetName" "ixVolumes")) -}} +{{- include "common.storage.retrieveHostPathFromiXVolume" (dict "datasetName" $values.datasetName "ixVolumes" $values.ixVolumes) -}} {{- end -}} {{- end -}} diff --git a/library/common/templates/lib/storage/_volume.tpl b/library/common/templates/lib/storage/_volume.tpl index 0cf4e74d8e..b828bb26a3 100644 --- a/library/common/templates/lib/storage/_volume.tpl +++ b/library/common/templates/lib/storage/_volume.tpl @@ -11,15 +11,15 @@ This expects a dictionary in the following format: "datasetName": string, } */}} -{{- define "common.volumeConfig" -}} +{{- define "common.storage.volumeConfig" -}} {{- $values := . -}} -{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "name")) -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "name")) -}} - name: {{ $values.name }} {{- if $values.emptyDirVolumes -}} emptyDir: {} {{- else -}} hostPath: - path: {{ template "common.configuredHostPath" $values }} + path: {{ template "common.storage.configuredHostPath" $values }} {{- end -}} {{- end -}} @@ -41,11 +41,11 @@ This expects a dictionary to be provided in the following format: ] ( list of dicts ) } */}} -{{- define "common.volumesConfiguration" -}} +{{- define "common.storage.volumesConfiguration" -}} {{- $values := . -}} -{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "ixVolumes" "volumes")) -}} +{{- include "common.schema.validateKeys" (dict "values" $values "checkKeys" (list "ixVolumes" "volumes")) -}} {{- range $vol := $values.volumes -}} {{- $_ := set $vol "ixVolumes" $values.ixVolumes -}} -{{- include "common.volumeConfig" $vol -}} +{{- include "common.storage.volumeConfig" $vol -}} {{- end -}} {{- end -}}