Add helper to retrieve all volumes configuration

This commit is contained in:
Waqar Ahmed committed 2021-01-30 00:21:50 +05:00
1 parent 4a895d6b63
commit 2865d86d42
2 files changed
+40 -14

No files matched your search

@@ -15,19 +15,11 @@ Retrieve host path from ix volumes based on a key
*/}} */}}
{{- define "common.configuredHostPath" -}} {{- define "common.configuredHostPath" -}}
{{- $values := . -}} {{- $values := . -}}
{{- if and (hasKey $values "hostPathEnabled") (hasKey $values "pathField") -}}
{{- end -}}
{{- if $values.hostPathEnabled -}} {{- if $values.hostPathEnabled -}}
{{- if hasKey $values "pathField" -}} {{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "pathField")) -}}
{{- $values.pathField -}} {{- $values.pathField -}}
{{- else -}} {{- else -}}
{{- fail "Path must be specified when host path is enabled" -}} {{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "datasetName" "ixVolumes")) -}}
{{- end -}} {{- include "common.retrieveHostPathFromiXVolume" (dict "datasetName" $values.datasetName "ixVolumes" $values.ixVolumes) -}}
{{- 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" -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
@@ -1,9 +1,19 @@
{{/* {{/*
Retrieve volume configuration 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" -}} {{- define "common.volumeConfig" -}}
{{- $values := . -}} {{- $values := . -}}
{{- if hasKey $values "name" }} {{- include "common.validateKeys" (dict "values" $values "checkKeys" (list "name")) -}}
- name: {{ $values.name }} - name: {{ $values.name }}
{{- if $values.emptyDirVolumes -}} {{- if $values.emptyDirVolumes -}}
emptyDir: {} emptyDir: {}
@@ -11,7 +21,31 @@ Retrieve volume configuration
hostPath: hostPath:
path: {{ template "common.configuredHostPath" $values }} path: {{ template "common.configuredHostPath" $values }}
{{- end -}} {{- end -}}
{{- else -}} {{- end -}}
{{- fail "Name must be specified for Volume Configuration" -}}
{{/*
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 -}}
{{- end -}} {{- end -}}