_emptyDir.tpl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. {{/* Returns emptyDir Volume */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.volume.emptyDir" (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.emptyDir" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $medium := "" -}}
  11. {{- $size := "" -}}
  12. {{- with $objectData.medium -}}
  13. {{- $medium = tpl . $rootCtx -}}
  14. {{- end -}}
  15. {{- with $objectData.size -}}
  16. {{- $size = tpl . $rootCtx -}}
  17. {{- end -}}
  18. {{- if $size -}}
  19. {{/* Size: https://regex101.com/r/NNPV2D/1 */}}
  20. {{- if not (mustRegexMatch "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$" (toString $size)) -}}
  21. {{- $formats := "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)" -}}
  22. {{- fail (printf "Persistence Expected <size> to have one of the following formats [%s], but got [%s]" $formats $size) -}}
  23. {{- end -}}
  24. {{- end -}}
  25. {{- if and $medium (ne $medium "Memory") -}}
  26. {{- fail (printf "Persistence - Expected [medium] to be one of [\"\", Memory], but got [%s] on <emptyDir> type" $medium) -}}
  27. {{- end }}
  28. - name: {{ $objectData.shortName }}
  29. {{- if or $medium $size }}
  30. emptyDir:
  31. {{- if $medium }}
  32. medium: {{ $medium }}
  33. {{- end -}}
  34. {{- if $size }}
  35. sizeLimit: {{ $size }}
  36. {{- end -}}
  37. {{- else }}
  38. emptyDir: {}
  39. {{- end -}}
  40. {{- end -}}