_ixVolume.tpl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. {{/* Returns ixVolume Volume */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.volume.ixVolume" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the volume.
  6. */}}
  7. {{- define "ix.v1.common.lib.pod.volume.ixVolume" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $hostPathType := "" -}}
  11. {{- if $objectData.hostPathType -}}
  12. {{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
  13. {{- end -}}
  14. {{- if not $objectData.datasetName -}}
  15. {{- fail "Persistence - Expected non-empty <datasetName> on <ixVolume> type" -}}
  16. {{- end -}}
  17. {{- $datasetName := tpl $objectData.datasetName $rootCtx -}}
  18. {{- if not $rootCtx.Values.ixVolumes -}}
  19. {{- fail "Persistence - Expected non-empty <ixVolumes> in values on <ixVolume> type" -}}
  20. {{- end -}}
  21. {{- $hostPath := "" -}}
  22. {{- $found := false -}}
  23. {{- range $idx, $normalizedHostPath := $rootCtx.Values.ixVolumes -}}
  24. {{- if eq $datasetName (base $normalizedHostPath.hostPath) -}}
  25. {{- $found = true -}}
  26. {{- $hostPath = $normalizedHostPath.hostPath -}}
  27. {{- end -}}
  28. {{- end -}}
  29. {{- if not $found -}} {{/* If we go over the ixVolumes and we dont find a match, fail */}}
  30. {{- $datasets := list -}}
  31. {{- range $rootCtx.Values.ixVolumes -}}
  32. {{- $datasets = mustAppend $datasets (base .hostPath) -}}
  33. {{- end -}}
  34. {{- fail (printf "Persistence - Expected <datasetName> [%s] to exist on <ixVolumes> list, but list contained [%s] on <ixVolume> type" $datasetName (join ", " $datasets)) -}}
  35. {{- end -}}
  36. {{- if not (hasPrefix "/" $hostPath) -}}
  37. {{- fail "Persistence - Expected normalized path from <ixVolumes> to start with a forward slash [/] on <ixVolume> type" -}}
  38. {{- end -}}
  39. {{- $types := (list "DirectoryOrCreate" "Directory" "FileOrCreate" "File" "Socket" "CharDevice" "BlockDevice") -}}
  40. {{- if and $hostPathType (not (mustHas $hostPathType $types)) -}}
  41. {{- fail (printf "Persistence - Expected <hostPathType> to be one of [%s], but got [%s]" (join ", " $types) $hostPathType) -}}
  42. {{- end }}
  43. - name: {{ $objectData.shortName }}
  44. hostPath:
  45. path: {{ $hostPath }}
  46. {{- with $hostPathType }}
  47. type: {{ $hostPathType }}
  48. {{- end -}}
  49. {{- end -}}