_imageSelector.tpl 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. {{/* Returns the image dictionary */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.container.imageSelector" (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.imageSelector" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $imageObj := dict -}}
  11. {{- $selector := "image" -}}
  12. {{- with $objectData.imageSelector -}}
  13. {{- $selector = tpl . $rootCtx -}}
  14. {{- end -}}
  15. {{- if hasKey $rootCtx.Values $selector -}}
  16. {{- $imageObj = get $rootCtx.Values $selector -}}
  17. {{- else -}}
  18. {{- fail (printf "Container - Expected <.Values.%s> to exist" $selector) -}}
  19. {{- end -}}
  20. {{- if not $imageObj.repository -}}
  21. {{- fail (printf "Container - Expected non-empty <.Values.%s.repository>" $selector) -}}
  22. {{- end -}}
  23. {{- if not $imageObj.tag -}}
  24. {{- fail (printf "Container - Expected non-empty <.Values.%s.tag>" $selector) -}}
  25. {{- end -}}
  26. {{- if not (kindIs "string" $imageObj.tag) -}}
  27. {{- fail (printf "Container - Expected <.Values.%s.tag> to be string, but got [%s]" $selector (kindOf $imageObj.tag)) -}}
  28. {{- end -}}
  29. {{- if not $imageObj.pullPolicy -}}
  30. {{- $_ := set $imageObj "pullPolicy" "IfNotPresent" -}}
  31. {{- end -}}
  32. {{- $policies := (list "IfNotPresent" "Always" "Never") -}}
  33. {{- if not (mustHas $imageObj.pullPolicy $policies) -}}
  34. {{- fail (printf "Container - Expected <.Values.%s.pullPolicy> to be one of [%s], but got [%s]" $selector (join ", " $policies) $imageObj.pullPolicy) -}}
  35. {{- end -}}
  36. {{- $imageObj | toJson -}}
  37. {{- end -}}