deployments.yaml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 eq $val.type "deployment" }}
  11. apiVersion: apps/v1
  12. kind: Deployment
  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: {{ $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.autoscaling }}
  31. {{- if $val.autoscaling.enabled }}
  32. {{- end }}
  33. {{- else }}
  34. replicas: {{ $val.replicas| default 0 }}
  35. {{- end }}
  36. {{- if $val.strategy }}
  37. strategy:
  38. {{- toYaml $val.strategy | nindent 4 }}
  39. {{- else }}
  40. strategy:
  41. type: {{ print "RollingUpdate" }}
  42. {{- end }}
  43. selector:
  44. matchLabels:
  45. app: {{ $name }}
  46. tier: {{ $val.name | default (print $name "-" $val.type "-" $index) }}
  47. template:
  48. metadata:
  49. labels:
  50. app: {{ $name }}
  51. tier: {{ $val.name | default (print $name "-" $val.type "-" $index) }}
  52. spec:
  53. {{- if and $val.imagePullSecrets $val.imagePullSecrets.enabled }}
  54. imagePullSecrets:
  55. - name: {{ $val.imagePullSecrets.name | default (print $name "-dockerconfig") }}
  56. {{- end }}
  57. restartPolicy: {{ $val.restartPolicy | default (print "Always") }}
  58. {{- with $val.volumes }}
  59. volumes:
  60. {{- toYaml . | nindent 8 }}
  61. {{- end }}
  62. {{- if $val.initContainers }}
  63. initContainers:
  64. {{- range $indexInitContainers, $valInitContainers := $val.initContainers }}
  65. - name: {{ $valInitContainers.name | default (print $name "-init-" $indexInitContainers) }}
  66. {{- if not $globalInitRegistry }}
  67. image: {{ print (default "registry.hub.docker.com" $valInitContainers.registry) "/"
  68. $valInitContainers.image ":" (default "latest" $valInitContainers.imageTag ) }}
  69. {{- else }}
  70. image: {{ print $globalInitRegistry "/"
  71. $valInitContainers.image ":" (default "latest" $valInitContainers.imageTag ) }}
  72. {{- end }}
  73. {{- with $valInitContainers.command }}
  74. command:
  75. {{- toYaml . | nindent 12 }}
  76. {{- end }}
  77. {{- with $valInitContainers.args }}
  78. args:
  79. {{- toYaml . | nindent 12 }}
  80. {{- end }}
  81. {{- with $valInitContainers.volumeMounts }}
  82. volumeMounts:
  83. {{- toYaml . | nindent 12 }}
  84. {{- end }}
  85. {{- with $valInitContainers.resources }}
  86. resources:
  87. {{- toYaml . | nindent 12 }}
  88. {{- end }}
  89. {{- if $valInitContainers.imagePullPolicy }}
  90. imagePullPolicy: {{ $valInitContainers.imagePullPolicy }}
  91. {{- end }}
  92. {{- if not (or $valInitContainers.envs $globalInitEnvsCheck) }}
  93. {{- if or $valInitContainers.configMap $valInitContainers.secret $valInitContainers.extraEnvs $globalInitExtraCheck }}
  94. {{- if or $valInitContainers.configMap $valInitContainers.secret }}
  95. {{- if or $valInitContainers.configMap.enabled $valInitContainers.secret.enabled }}
  96. envFrom:
  97. {{- if $valInitContainers.configMap.enabled }}
  98. - configMapRef:
  99. name: {{ $valInitContainers.configMap.name | default (print $name "-config") }}
  100. {{- end }}
  101. {{- if $valInitContainers.secret.enabled }}
  102. - secretRef:
  103. name: {{ $valInitContainers.secret.name | default (print $name "-secret") }}
  104. {{- end }}
  105. {{- end }}{{- end }}
  106. {{- if or $valInitContainers.extraEnvs $globalInitExtraCheck }}
  107. env:
  108. {{- if $valInitContainers.extraEnvs }}
  109. {{- range $valInitContainers.extraEnvs }}{{- if .value }}
  110. - name: {{ .name }}
  111. value: {{ .value | quote }}
  112. {{- end }}{{- end }}{{- end }}
  113. {{- range $Ind, $Val := $.Values.items }}
  114. {{- if eq $Val.type "global" }}
  115. {{- range $_, $containers := $Val.containers }}
  116. {{- range $__, $containersExtraEnvs := $containers.extraEnvs }}{{- if $containersExtraEnvs.value }}
  117. - name: {{ $containersExtraEnvs.name }}
  118. value: {{ $containersExtraEnvs.value | quote }}
  119. {{- end }}{{- end }}{{- end }}
  120. {{- end }}{{- end }}
  121. {{- end }}
  122. {{- end }}
  123. {{- else }}
  124. env:
  125. {{- if and (not $globalInitEnvsCheck) $valInitContainers.envs }}
  126. {{- range $valInitContainers.envs }}{{- if .value }}
  127. - name: {{ .name }}
  128. value: {{ .value | quote }}
  129. {{- end }}{{- end }}{{- end }}
  130. {{- if $globalInitEnvsCheck }}
  131. {{- range $Ind, $Val := $.Values.items }}
  132. {{- if eq $Val.type "global" }}
  133. {{- range $_, $containers := $Val.containers }}
  134. {{- range $__, $containersEnvs := $containers.envs }}{{- if $containersEnvs.value }}
  135. - name: {{ $containersEnvs.name }}
  136. value: {{ $containersEnvs.value | quote }}
  137. {{- end }}{{- end }}{{- end }}
  138. {{- end }}{{- end }}
  139. {{- end }}
  140. {{- end }}
  141. {{- end }}
  142. {{- end }}
  143. {{- if $val.containers }}
  144. containers:
  145. {{- range $indexContainers, $valContainers := $val.containers }}
  146. - name: {{ $valContainers.name | default (print $name "-cont-" $indexContainers) }}
  147. {{- if not $globalContRegistry }}
  148. image: {{ print (default "registry.hub.docker.com" $valContainers.registry) "/"
  149. $valContainers.image ":" (default "latest" $valContainers.imageTag ) }}
  150. {{- else }}
  151. image: {{ print $globalContRegistry "/"
  152. $valContainers.image ":" (default "latest" $valContainers.imageTag ) }}
  153. {{- end }}
  154. {{- with $valContainers.command }}
  155. command:
  156. {{- toYaml . | nindent 12 }}
  157. {{- end }}
  158. {{- with $valContainers.args }}
  159. args:
  160. {{- toYaml . | nindent 12 }}
  161. {{- end }}
  162. {{- with $valContainers.volumeMounts }}
  163. volumeMounts:
  164. {{- toYaml . | nindent 12 }}
  165. {{- end }}
  166. {{- with $valContainers.livenessProbe }}
  167. livenessProbe:
  168. {{- toYaml . | nindent 12 }}
  169. {{- end }}
  170. {{- with $valContainers.readinessProbe }}
  171. readinessProbe:
  172. {{- toYaml . | nindent 12 }}
  173. {{- end }}
  174. {{- with $valContainers.resources }}
  175. resources:
  176. {{- toYaml . | nindent 12 }}
  177. {{- end }}
  178. {{- if $valContainers.ports }}
  179. ports:
  180. {{- range $_, $ports := $valContainers.ports }}
  181. {{- if .containerPort }}
  182. - containerPort: {{ .containerPort }}
  183. {{- if .name }}
  184. name: {{ .name }}
  185. {{- end }}
  186. {{- if .hostIP }}
  187. hostIP: {{ .hostIP }}
  188. {{- end }}
  189. {{- if .hostPort }}
  190. hostPort: {{ .hostPort }}
  191. {{- end }}
  192. {{- if .protocol }}
  193. protocol: {{ .protocol }}
  194. {{- end }}
  195. {{- end }}
  196. {{- end }}
  197. {{- end }}
  198. {{- if $valContainers.imagePullPolicy }}
  199. imagePullPolicy: {{ $valContainers.imagePullPolicy }}
  200. {{- end }}
  201. {{- if not (or $valContainers.envs $globalContEnvsCheck) }}
  202. {{- if or $valContainers.configMap $valContainers.secret $valContainers.extraEnvs $globalContExtraCheck }}
  203. {{- if or $valContainers.configMap $valContainers.secret }}
  204. {{- if or $valContainers.configMap.enabled $valContainers.secret.enabled }}
  205. envFrom:
  206. {{- if $valContainers.configMap.enabled }}
  207. - configMapRef:
  208. name: {{ $valContainers.configMap.name | default (print $name "-config") }}
  209. {{- end }}
  210. {{- if $valContainers.secret.enabled }}
  211. - secretRef:
  212. name: {{ $valContainers.secret.name | default (print $name "-secret") }}
  213. {{- end }}
  214. {{- end }}{{- end }}
  215. {{- if or $valContainers.extraEnvs $globalContExtraCheck }}
  216. env:
  217. {{- if $valContainers.extraEnvs }}
  218. {{- range $valContainers.extraEnvs }}{{- if .value }}
  219. - name: {{ .name }}
  220. value: {{ .value | quote }}
  221. {{- end }}{{- end }}{{- end }}
  222. {{- range $Ind, $Val := $.Values.items }}
  223. {{- if eq $Val.type "global" }}
  224. {{- range $_, $containers := $Val.containers }}
  225. {{- range $__, $containersExtraEnvs := $containers.extraEnvs }}{{- if $containersExtraEnvs.value }}
  226. - name: {{ $containersExtraEnvs.name }}
  227. value: {{ $containersExtraEnvs.value | quote }}
  228. {{- end }}{{- end }}{{- end }}
  229. {{- end }}{{- end }}
  230. {{- end }}
  231. {{- end }}
  232. {{- else }}
  233. env:
  234. {{- if and (not $globalContEnvsCheck) $valContainers.envs }}
  235. {{- range $valContainers.envs }}{{- if .value }}
  236. - name: {{ .name }}
  237. value: {{ .value | quote }}
  238. {{- end }}{{- end }}{{- end }}
  239. {{- if $globalContEnvsCheck }}
  240. {{- range $Ind, $Val := $.Values.items }}
  241. {{- if eq $Val.type "global" }}
  242. {{- range $_, $containers := $Val.containers }}
  243. {{- range $__, $containersEnvs := $containers.envs }}{{- if $containersEnvs.value }}
  244. - name: {{ $containersEnvs.name }}
  245. value: {{ $containersEnvs.value | quote }}
  246. {{- end }}{{- end }}{{- end }}
  247. {{- end }}{{- end }}
  248. {{- end }}
  249. {{- end }}
  250. {{- end }}
  251. {{- end }}
  252. {{ print "---" }}
  253. {{- end }}{{- end }}