_volumeMounts.tpl 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. {{/* Returns volumeMount list */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.container.volumeMount" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the container.
  6. */}}
  7. {{- define "ix.v1.common.lib.container.volumeMount" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $volMounts := list -}}
  11. {{- $keys := (list "persistence") -}}
  12. {{- range $key := $keys -}}
  13. {{- range $persistenceName, $persistenceValues := (get $rootCtx.Values $key) -}}
  14. {{/* Initialize from the default values */}}
  15. {{- $volMount := dict -}}
  16. {{- $_ := set $volMount "name" $persistenceName -}}
  17. {{- $_ := set $volMount "key" $key -}}
  18. {{- $_ := set $volMount "mountPath" ($persistenceValues.mountPath | default "") -}}
  19. {{- $_ := set $volMount "subPath" ($persistenceValues.subPath | default "") -}}
  20. {{- $_ := set $volMount "readOnly" ($persistenceValues.readOnly | default false) -}}
  21. {{- $_ := set $volMount "mountPropagation" ($persistenceValues.mountPropagation | default "") -}}
  22. {{/* If persistence is enabled... */}}
  23. {{- if $persistenceValues.enabled -}}
  24. {{/* If targetSelectAll is set, means all pods/containers */}} {{/* targetSelectAll does not make sense for vct */}}
  25. {{- if and $persistenceValues.targetSelectAll -}}
  26. {{- $volMounts = mustAppend $volMounts $volMount -}}
  27. {{/* Else if selector is defined */}}
  28. {{- else if $persistenceValues.targetSelector -}}
  29. {{/* If pod is selected */}}
  30. {{- if mustHas $objectData.podShortName ($persistenceValues.targetSelector | keys) -}}
  31. {{- $selectorValues := (get $persistenceValues.targetSelector $objectData.podShortName) -}}
  32. {{- if not (kindIs "map" $selectorValues) -}}
  33. {{- fail (printf "%s - Expected <targetSelector.%s> to be a [dict], but got [%s]" (camelcase $key) $objectData.podShortName (kindOf $selectorValues)) -}}
  34. {{- end -}}
  35. {{- if not $selectorValues -}}
  36. {{- fail (printf "%s - Expected non-empty <targetSelector.%s>" (camelcase $key) $objectData.podShortName) -}}
  37. {{- end -}}
  38. {{/* If container is selected */}}
  39. {{- if mustHas $objectData.shortName ($selectorValues | keys) -}}
  40. {{/* Merge with values that might be set for the specific container */}}
  41. {{- $volMount = mustMergeOverwrite $volMount (get $selectorValues $objectData.shortName) -}}
  42. {{- $volMounts = mustAppend $volMounts $volMount -}}
  43. {{- end -}}
  44. {{- end -}}
  45. {{/* Else if not selector, but pod and container is primary */}}
  46. {{- else if and $objectData.podPrimary $objectData.primary -}}
  47. {{- $volMounts = mustAppend $volMounts $volMount -}}
  48. {{- end -}}
  49. {{- end -}}
  50. {{- end -}}
  51. {{- end -}}
  52. {{- range $volMount := $volMounts -}}
  53. {{/* Expand values */}}
  54. {{- $_ := set $volMount "mountPath" (tpl $volMount.mountPath $rootCtx) -}}
  55. {{- $_ := set $volMount "subPath" (tpl $volMount.subPath $rootCtx) -}}
  56. {{- $_ := set $volMount "mountPropagation" (tpl $volMount.mountPropagation $rootCtx) -}}
  57. {{- if not $volMount.mountPath -}}
  58. {{- fail (printf "%s - Expected non-empty <mountPath>" (camelcase $volMount.key)) -}}
  59. {{- end -}}
  60. {{- if not (hasPrefix "/" $volMount.mountPath) -}}
  61. {{- fail (printf "%s - Expected <mountPath> to start with a forward slash [/]" (camelcase $volMount.key)) -}}
  62. {{- end -}}
  63. {{- $propagationTypes := (list "None" "HostToContainer" "Bidirectional") -}}
  64. {{- if and $volMount.mountPropagation (not (mustHas $volMount.mountPropagation $propagationTypes)) -}}
  65. {{- fail (printf "%s - Expected <mountPropagation> to be one of [%s], but got [%s]" (camelcase $volMount.key) (join ", " $propagationTypes) $volMount.mountPropagation) -}}
  66. {{- end -}}
  67. {{- if not (kindIs "bool" $volMount.readOnly) -}}
  68. {{- fail (printf "%s - Expected <readOnly> to be [boolean], but got [%s]" (camelcase $volMount.key) (kindOf $volMount.readOnly)) -}}
  69. {{- end }}
  70. - name: {{ $volMount.name }}
  71. mountPath: {{ $volMount.mountPath }}
  72. readOnly: {{ $volMount.readOnly }}
  73. {{- with $volMount.subPath }}
  74. subPath: {{ . }}
  75. {{- end -}}
  76. {{- with $volMount.mountPropagation }}
  77. mountPropagation: {{ . }}
  78. {{- end -}}
  79. {{- end -}}
  80. {{- end -}}