From 2865d86d42c3fc64f60fbc1dc80112e8860143f0 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Fri, 29 Jan 2021 15:37:44 +0500 Subject: [PATCH] Add helper to retrieve all volumes configuration --- .../templates/lib/storage/_ixvolumes.tpl | 14 ++----- .../common/templates/lib/storage/_volume.tpl | 40 +++++++++++++++++-- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/library/common/templates/lib/storage/_ixvolumes.tpl b/library/common/templates/lib/storage/_ixvolumes.tpl index b43bfbb0b4..bbac51a067 100644 --- a/library/common/templates/lib/storage/_ixvolumes.tpl +++ b/library/common/templates/lib/storage/_ixvolumes.tpl @@ -15,19 +15,11 @@ Retrieve host path from ix volumes based on a key */}} {{- define "common.configuredHostPath" -}} {{- $values := . -}} -{{- if and (hasKey $values "hostPathEnabled") (hasKey $values "pathField") -}} -{{- end -}} {{- if $values.hostPathEnabled -}} -{{- if hasKey $values "pathField" -}} +{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "pathField")) -}} {{- $values.pathField -}} {{- else -}} -{{- fail "Path must be specified when host path is enabled" -}} -{{- end -}} -{{- else if and (hasKey $values "datasetName") (hasKey $values "ixVolumes") -}} -{{- $volDict := dict "datasetName" $values.datasetName "ixVolumes" $values.ixVolumes -}} -{{- include "common.retrieveHostPathFromiXVolume" $volDict -}} -{{- else -}} -{{- fail "Dataset name and ix volumes must be specified" -}} +{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "datasetName" "ixVolumes")) -}} +{{- include "common.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 2e15fa98d4..0cf4e74d8e 100644 --- a/library/common/templates/lib/storage/_volume.tpl +++ b/library/common/templates/lib/storage/_volume.tpl @@ -1,9 +1,19 @@ {{/* Retrieve volume configuration + +This expects a dictionary in the following format: +{ + "name": string, + "emptyDirVolumes": boolean, + "ixVolumes": list, + "hostPathEnabled": boolean, + "pathField": string, + "datasetName": string, +} */}} {{- define "common.volumeConfig" -}} {{- $values := . -}} -{{- if hasKey $values "name" }} +{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "name")) -}} - name: {{ $values.name }} {{- if $values.emptyDirVolumes -}} emptyDir: {} @@ -11,7 +21,31 @@ Retrieve volume configuration hostPath: path: {{ template "common.configuredHostPath" $values }} {{- end -}} -{{- else -}} -{{- fail "Name must be specified for Volume Configuration" -}} +{{- end -}} + + +{{/* +Retrieve configuration for volumes + +This expects a dictionary to be provided in the following format: +{ + "ixVolumes": list, + "volumes": [ + { + "name": string, + "emptyDirVolumes": boolean, + "hostPathEnabled": boolean, + "pathField": string, + "datasetName": string, + } + ] ( list of dicts ) +} +*/}} +{{- define "common.volumesConfiguration" -}} +{{- $values := . -}} +{{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "ixVolumes" "volumes")) -}} +{{- range $vol := $values.volumes -}} +{{- $_ := set $vol "ixVolumes" $values.ixVolumes -}} +{{- include "common.volumeConfig" $vol -}} {{- end -}} {{- end -}}