jobs.yaml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. {{- $name := .Chart.Name }}
  2. {{- $globalAnnotationsCheck := include "global.annotations.check" . }}
  3. {{- $globalContEnvsCheck := include "global.containers.envs.check" . }}
  4. {{- $globalContExtraCheck := include "global.containers.extraEnvs.check" . }}
  5. {{- $globalContRegistry := include "global.containers.registry" . }}
  6. {{- $globalInitEnvsCheck := include "global.initContainers.envs.check" . }}
  7. {{- $globalInitExtraCheck := include "global.initContainers.extraEnvs.check" . }}
  8. {{- $globalInitRegistry := include "global.initContainers.registry" . }}
  9. {{- range $index, $val := .Values.items }}
  10. {{- if and (eq $val.type "job") (not $val.schedule) }}
  11. apiVersion: batch/v1
  12. kind: Job
  13. metadata:
  14. {{- if or $val.annotations $globalAnnotationsCheck }}
  15. annotations:
  16. {{- if $val.annotations }}
  17. {{- toYaml $val.annotations | nindent 4 }}
  18. {{- end }}
  19. {{- if $globalAnnotationsCheck }}
  20. {{- range $Index, $Val := $.Values.items }}
  21. {{- if eq $Val.type "global" }}
  22. {{- toYaml $Val.annotations | nindent 4 }}
  23. {{- end }}{{- end }}{{- end }}
  24. {{- end }}
  25. name: {{ print $val.name | default (print $name "-" $val.type "-" $index) }}
  26. labels:
  27. app: {{ $name }}
  28. tier: {{ $val.name | default (print $name "-" $val.type) }}
  29. spec:
  30. {{- if $val.backoffLimit }}
  31. backoffLimit: {{ $val.backoffLimit }}
  32. {{- end }}
  33. {{- if $val.activeDeadlineSeconds }}
  34. activeDeadlineSeconds: {{ $val.activeDeadlineSeconds }}
  35. {{- end }}
  36. template:
  37. spec:
  38. {{- if $val.volumes }}
  39. volumes:
  40. {{- toYaml .volumes | nindent 8 }}
  41. {{- end }}
  42. restartPolicy: {{ $val.restartPolicy | default (print "OnFailure") }}
  43. {{- if $val.imagePullSecrets.enabled }}
  44. imagePullSecrets:
  45. - name: {{ $val.imagePullSecrets.name | default (print $name "-dockerconfig") }}
  46. {{- end }}
  47. {{- if $val.initContainers }}
  48. initContainers:
  49. {{- range $indexInitContainers, $valInitContainers := $val.initContainers }}
  50. - name: {{ $valInitContainers.name | default (print $name "-init-" $indexInitContainers) }}
  51. {{- if not $globalInitRegistry }}
  52. image: {{ print (default "registry.hub.docker.com" $valInitContainers.registry) "/"
  53. $valInitContainers.image ":" (default "latest" $valInitContainers.imageTag ) }}
  54. {{- else }}
  55. image: {{ print $globalInitRegistry "/"
  56. $valInitContainers.image ":" (default "latest" $valInitContainers.imageTag ) }}
  57. {{- end }}
  58. {{- with $valInitContainers.command }}
  59. command:
  60. {{- toYaml . | nindent 12 }}
  61. {{- end }}
  62. {{- with $valInitContainers.args }}
  63. args:
  64. {{- toYaml . | nindent 12 }}
  65. {{- end }}
  66. {{- with $valInitContainers.volumeMounts }}
  67. volumeMounts:
  68. {{- toYaml . | nindent 12 }}
  69. {{- end }}
  70. {{- with $valInitContainers.resources }}
  71. resources:
  72. {{- toYaml . | nindent 12 }}
  73. {{- end }}
  74. {{- with $valInitContainers.ports }}
  75. ports:
  76. {{- toYaml . | nindent 12 }}
  77. {{- end }}
  78. {{- if $valInitContainers.imagePullPolicy }}
  79. imagePullPolicy: {{ $valInitContainers.imagePullPolicy }}
  80. {{- end }}
  81. {{- if not (or $valInitContainers.envs $globalInitEnvsCheck) }}
  82. {{- if or $valInitContainers.configMap $valInitContainers.secret $valInitContainers.extraEnvs $globalInitExtraCheck }}
  83. {{- if or $valInitContainers.configMap $valInitContainers.secret }}
  84. {{- if or $valInitContainers.configMap.enabled $valInitContainers.secret.enabled }}
  85. envFrom:
  86. {{- if $valInitContainers.configMap.enabled }}
  87. - configMapRef:
  88. name: {{ $valInitContainers.configMap.name | default (print $name "-config") }}
  89. {{- end }}
  90. {{- if $valInitContainers.secret.enabled }}
  91. - secretRef:
  92. name: {{ $valInitContainers.secret.name | default (print $name "-secret") }}
  93. {{- end }}
  94. {{- end }}{{- end }}
  95. {{- if or $valInitContainers.extraEnvs $globalInitExtraCheck }}
  96. env:
  97. {{- if $valInitContainers.extraEnvs }}
  98. {{- range $valInitContainers.extraEnvs }}{{- if .value }}
  99. - name: {{ .name }}
  100. value: {{ .value | quote }}
  101. {{- end }}{{- end }}{{- end }}
  102. {{- range $Ind, $Val := $.Values.items }}
  103. {{- if eq $Val.type "global" }}
  104. {{- range $_, $containers := $Val.containers }}
  105. {{- range $__, $containersExtraEnvs := $containers.extraEnvs }}{{- if $containersExtraEnvs.value }}
  106. - name: {{ $containersExtraEnvs.name }}
  107. value: {{ $containersExtraEnvs.value | quote }}
  108. {{- end }}{{- end }}{{- end }}
  109. {{- end }}{{- end }}
  110. {{- end }}
  111. {{- end }}
  112. {{- else }}
  113. env:
  114. {{- if and (not $globalInitEnvsCheck) $valInitContainers.envs }}
  115. {{- range $valInitContainers.envs }}{{- if .value }}
  116. - name: {{ .name }}
  117. value: {{ .value | quote }}
  118. {{- end }}{{- end }}{{- end }}
  119. {{- if $globalInitEnvsCheck }}
  120. {{- range $Ind, $Val := $.Values.items }}
  121. {{- if eq $Val.type "global" }}
  122. {{- range $_, $containers := $Val.containers }}
  123. {{- range $__, $containersEnvs := $containers.envs }}{{- if $containersEnvs.value }}
  124. - name: {{ $containersEnvs.name }}
  125. value: {{ $containersEnvs.value | quote }}
  126. {{- end }}{{- end }}{{- end }}
  127. {{- end }}{{- end }}
  128. {{- end }}
  129. {{- end }}
  130. {{- end }}
  131. {{- end }}
  132. {{- if $val.containers }}
  133. containers:
  134. {{- range $indexContainers, $valContainers := $val.containers }}
  135. - name: {{ $valContainers.name | default (print $name "-cont-" $indexContainers) }}
  136. {{- if not $globalContRegistry }}
  137. image: {{ print (default "registry.hub.docker.com" $valContainers.registry) "/"
  138. $valContainers.image ":" (default "latest" $valContainers.imageTag ) }}
  139. {{- else }}
  140. image: {{ print $globalContRegistry "/"
  141. $valContainers.image ":" (default "latest" $valContainers.imageTag ) }}
  142. {{- end }}
  143. {{- with $valContainers.command }}
  144. command:
  145. {{- toYaml . | nindent 12 }}
  146. {{- end }}
  147. {{- with $valContainers.args }}
  148. args:
  149. {{- toYaml . | nindent 12 }}
  150. {{- end }}
  151. {{- with $valContainers.volumeMounts }}
  152. volumeMounts:
  153. {{- toYaml . | nindent 12 }}
  154. {{- end }}
  155. {{- with $valContainers.livenessProbe }}
  156. livenessProbe:
  157. {{- toYaml . | nindent 12 }}
  158. {{- end }}
  159. {{- with $valContainers.readinessProbe }}
  160. readinessProbe:
  161. {{- toYaml . | nindent 12 }}
  162. {{- end }}
  163. {{- with $valContainers.resources }}
  164. resources:
  165. {{- toYaml . | nindent 12 }}
  166. {{- end }}
  167. {{- with $valContainers.ports }}
  168. ports:
  169. {{- toYaml . | nindent 12 }}
  170. {{- end }}
  171. {{- if $valContainers.imagePullPolicy }}
  172. imagePullPolicy: {{ $valContainers.imagePullPolicy }}
  173. {{- end }}
  174. {{- if not (or $valContainers.envs $globalContEnvsCheck) }}
  175. {{- if or $valContainers.configMap $valContainers.secret $valContainers.extraEnvs $globalContExtraCheck }}
  176. {{- if or $valContainers.configMap $valContainers.secret }}
  177. {{- if or $valContainers.configMap.enabled $valContainers.secret.enabled }}
  178. envFrom:
  179. {{- if $valContainers.configMap.enabled }}
  180. - configMapRef:
  181. name: {{ $valContainers.configMap.name | default (print $name "-config") }}
  182. {{- end }}
  183. {{- if $valContainers.secret.enabled }}
  184. - secretRef:
  185. name: {{ $valContainers.secret.name | default (print $name "-secret") }}
  186. {{- end }}
  187. {{- end }}{{- end }}
  188. {{- if or $valContainers.extraEnvs $globalContExtraCheck }}
  189. env:
  190. {{- if $valContainers.extraEnvs }}
  191. {{- range $valContainers.extraEnvs }}{{- if .value }}
  192. - name: {{ .name }}
  193. value: {{ .value | quote }}
  194. {{- end }}{{- end }}{{- end }}
  195. {{- range $Ind, $Val := $.Values.items }}
  196. {{- if eq $Val.type "global" }}
  197. {{- range $_, $containers := $Val.containers }}
  198. {{- range $__, $containersExtraEnvs := $containers.extraEnvs }}{{- if $containersExtraEnvs.value }}
  199. - name: {{ $containersExtraEnvs.name }}
  200. value: {{ $containersExtraEnvs.value | quote }}
  201. {{- end }}{{- end }}{{- end }}
  202. {{- end }}{{- end }}
  203. {{- end }}
  204. {{- end }}
  205. {{- else }}
  206. env:
  207. {{- if and (not $globalContEnvsCheck) $valContainers.envs }}
  208. {{- range $valContainers.envs }}{{- if .value }}
  209. - name: {{ .name }}
  210. value: {{ .value | quote }}
  211. {{- end }}{{- end }}{{- end }}
  212. {{- if $globalContEnvsCheck }}
  213. {{- range $Ind, $Val := $.Values.items }}
  214. {{- if eq $Val.type "global" }}
  215. {{- range $_, $containers := $Val.containers }}
  216. {{- range $__, $containersEnvs := $containers.envs }}{{- if $containersEnvs.value }}
  217. - name: {{ $containersEnvs.name }}
  218. value: {{ $containersEnvs.value | quote }}
  219. {{- end }}{{- end }}{{- end }}
  220. {{- end }}{{- end }}
  221. {{- end }}
  222. {{- end }}
  223. {{- end }}
  224. {{- end }}
  225. {{ print "---" }}
  226. {{- end }}{{- end }}