_initContainerSpawner.tpl 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. {{/* Init Containers */}}
  2. {{/* Call this template:
  3. {{ include "ix.v1.common.lib.pod.initContainerSpawner" (dict "rootCtx" $ "objectData" $objectData) }}
  4. rootCtx: The root context of the chart.
  5. objectData: The object data to be used to render the Pod.
  6. */}}
  7. {{- define "ix.v1.common.lib.pod.initContainerSpawner" -}}
  8. {{- $rootCtx := .rootCtx -}}
  9. {{- $objectData := .objectData -}}
  10. {{- $initContainers := (dict "init" list
  11. "install" list
  12. "upgrade" list) -}}
  13. {{- $types := (list "init" "install" "upgrade") -}}
  14. {{- range $containerName, $containerValues := $objectData.podSpec.initContainers -}}
  15. {{- $enabled := $containerValues.enabled -}}
  16. {{- if kindIs "string" $enabled -}}
  17. {{- $enabled = tpl $enabled $rootCtx -}}
  18. {{/* After tpl it becomes a string, not a bool */}}
  19. {{- if eq $enabled "true" -}}
  20. {{- $enabled = true -}}
  21. {{- else -}}
  22. {{- $enabled = false -}}
  23. {{- end -}}
  24. {{- end -}}
  25. {{- if $enabled -}}
  26. {{- if not ($containerValues.type) -}}
  27. {{- fail "InitContainer - Expected non-empty <type>" -}}
  28. {{- end -}}
  29. {{- $containerType := tpl $containerValues.type $rootCtx -}}
  30. {{- if not (mustHas $containerType $types) -}}
  31. {{- fail (printf "InitContainer - Expected <type> to be one of [%s], but got [%s]" (join ", " $types) $containerType) -}}
  32. {{- end -}}
  33. {{- $container := (mustDeepCopy $containerValues) -}}
  34. {{- $name := printf "%s-%s-%s" (include "ix.v1.common.lib.chart.names.fullname" $rootCtx) $containerType $containerName -}}
  35. {{- $_ := set $container "name" $name -}}
  36. {{- $_ := set $container "shortName" $containerName -}}
  37. {{- $_ := set $container "podShortName" $objectData.shortName -}}
  38. {{- $_ := set $container "podPrimary" $objectData.primary -}}
  39. {{- $_ := set $container "podType" $objectData.type -}}
  40. {{/* Remove keys that do not apply on init containers */}}
  41. {{- $_ := set $container "lifecycle" dict -}}
  42. {{- $_ := set $container "probes" dict -}}
  43. {{/* Template expects probes dict defined even if enabled */}}
  44. {{- $_ := set $container.probes "liveness" (dict "enabled" false) -}}
  45. {{- $_ := set $container.probes "readiness" (dict "enabled" false) -}}
  46. {{- $_ := set $container.probes "startup" (dict "enabled" false) -}}
  47. {{/* Created from the pod.securityContext, used by fixedEnv */}}
  48. {{- $_ := set $container "calculatedFSGroup" $objectData.podSpec.calculatedFSGroup -}}
  49. {{/* Append to list of containers based on type */}}
  50. {{- $tempContainers := (get $initContainers $containerType) -}}
  51. {{- $_ := set $initContainers $containerType (mustAppend $tempContainers $container) -}}
  52. {{- end -}}
  53. {{- end -}}
  54. {{- if $rootCtx.Release.IsInstall -}}
  55. {{- range $container := (get $initContainers "install") -}}
  56. {{- include "ix.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
  57. {{- end -}}
  58. {{- end -}}
  59. {{- if $rootCtx.Release.IsUpgrade -}}
  60. {{- range $container := (get $initContainers "upgrade") -}}
  61. {{- include "ix.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
  62. {{- end -}}
  63. {{- end -}}
  64. {{- range $container := (get $initContainers "init") -}}
  65. {{- include "ix.v1.common.lib.pod.container" (dict "rootCtx" $rootCtx "objectData" $container) -}}
  66. {{- end -}}
  67. {{- end -}}