Browse Source

Add method to retrieve host path from user input or ix volumes

Waqar Ahmed 4 years ago
parent
commit
cea74cc63f
1 changed files with 23 additions and 1 deletions
  1. 23 1
      library/common/templates/lib/storage/_ixvolumes.tpl

+ 23 - 1
library/common/templates/lib/storage/_ixvolumes.tpl

@@ -1,7 +1,7 @@
 {{/*
 Retrieve host path from ix volumes based on dataset name
 */}}
-{{- define "retrieveHostPathFromiXVolume" -}}
+{{- define "common.retrieveHostPathFromiXVolume" -}}
 {{- range $index, $hostPathConfiguration := $.ixVolumes }}
 {{- $dsName := base $hostPathConfiguration.hostPath -}}
 {{- if eq $.datasetName $dsName -}}
@@ -9,3 +9,25 @@ Retrieve host path from ix volumes based on dataset name
 {{- end -}}
 {{- end }}
 {{- end -}}
+
+{{/*
+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" -}}
+{{- $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" -}}
+{{- end -}}
+{{- end -}}
+