_envFrom.tpl 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. {{/* Returns Env From */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.container.envFrom" (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.envFrom" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $refs := (list "configMapRef" "secretRef") -}}
  11. {{- range $envFrom := $objectData.envFrom -}}
  12. {{- if and (not $envFrom.secretRef) (not $envFrom.configMapRef) -}}
  13. {{- fail (printf "Container - Expected <envFrom> entry to have one of [%s]" (join ", " $refs)) -}}
  14. {{- end -}}
  15. {{- if and $envFrom.secretRef $envFrom.configMapRef -}}
  16. {{- fail (printf "Container - Expected <envFrom> entry to have only one of [%s], but got both" (join ", " $refs)) -}}
  17. {{- end -}}
  18. {{- range $ref := $refs -}}
  19. {{- with (get $envFrom $ref) -}}
  20. {{- if not .name -}}
  21. {{- fail (printf "Container - Expected non-empty <envFrom.%s.name>" $ref) -}}
  22. {{- end -}}
  23. {{- $objectName := tpl .name $rootCtx -}}
  24. {{- $expandName := true -}}
  25. {{- if kindIs "bool" .expandObjectName -}}
  26. {{- $expandName = .expandObjectName -}}
  27. {{- end -}}
  28. {{- if $expandName -}}
  29. {{- $object := dict -}}
  30. {{- $source := "" -}}
  31. {{- if eq $ref "configMapRef" -}}
  32. {{- $object = (get $rootCtx.Values.configmap $objectName) -}}
  33. {{- $source = "ConfigMap" -}}
  34. {{- else if eq $ref "secretRef" -}}
  35. {{- $object = (get $rootCtx.Values.secret $objectName) -}}
  36. {{- $source = "Secret" -}}
  37. {{- end -}}
  38. {{- if not $object -}}
  39. {{- fail (printf "Container - Expected %s [%s] defined in <envFrom> to exist" $source $objectName) -}}
  40. {{- end -}}
  41. {{- range $k, $v := $object.data -}}
  42. {{- include "ix.v1.common.helper.container.envDupeCheck" (dict "rootCtx" $rootCtx "objectData" $objectData "source" (printf "%s - %s" $source $objectName) "key" $k) -}}
  43. {{- end -}}
  44. {{- $objectName = (printf "%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $rootCtx) $objectName) -}}
  45. {{- end }}
  46. - {{ $ref }}:
  47. name: {{ $objectName | quote }}
  48. {{- end -}}
  49. {{- end -}}
  50. {{- end -}}
  51. {{- end -}}