_workload.tpl 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. {{/*
  2. Check if workload type is a deployment
  3. */}}
  4. {{- define "workloadIsDeployment" }}
  5. {{- if eq .Values.workloadType "Deployment" }}
  6. {{- true -}}
  7. {{- else }}
  8. {{- false -}}
  9. {{- end }}
  10. {{- end }}
  11. {{/*
  12. Check if workload type is a cronjob
  13. */}}
  14. {{- define "workloadIsCronJob" }}
  15. {{- if eq .Values.workloadType "CronJob" }}
  16. {{- true -}}
  17. {{- else }}
  18. {{- false -}}
  19. {{- end }}
  20. {{- end }}
  21. {{/*
  22. Get API Version based on workload type
  23. */}}
  24. {{- define "apiVersion" -}}
  25. {{- if eq (include "workloadIsDeployment" .) "true" }}
  26. {{- printf "apps/v1" }}
  27. {{- else if eq (include "workloadIsCronJob" .) "true" }}
  28. {{- printf "batch/v1beta1" }}
  29. {{- else }}
  30. {{- printf "batch/v1" }}
  31. {{- end }}
  32. {{- end }}
  33. {{/*
  34. Get Restart policy based on workload type
  35. */}}
  36. {{- define "restartPolicy" -}}
  37. {{- if eq (include "workloadIsDeployment" .) "true" }}
  38. {{- print "Always" }}
  39. {{- else }}
  40. {{- printf "%s" .Values.jobRestartPolicy }}
  41. {{- end }}
  42. {{- end }}
  43. {{/*
  44. Pod specification
  45. */}}
  46. {{- define "podSepc" }}
  47. restartPolicy: {{ template "restartPolicy" . }}
  48. hostNetwork: {{ template "hostNetworkingConfiguration" . }}
  49. containers:
  50. - name: {{ .Chart.Name }}
  51. {{ include "common.resources.limitation" . | nindent 2 }}
  52. {{- include "volumeMountsConfiguration" . | indent 2}}
  53. tty: {{ .Values.tty }}
  54. stdin: {{ .Values.stdin }}
  55. securityContext:
  56. privileged: {{ .Values.securityContext.privileged }}
  57. {{ if .Values.securityContext.enableRunAsUser }}
  58. runAsUser: {{ .Values.securityContext.runAsUser }}
  59. runAsGroup: {{ .Values.securityContext.runAsGroup }}
  60. {{ end }}
  61. {{ if .Values.securityContext.capabilities }}
  62. capabilities:
  63. add: {{ toYaml .Values.securityContext.capabilities | nindent 8 }}
  64. {{ end }}
  65. {{ if .Values.ci }}
  66. livenessProbe:
  67. httpGet:
  68. path: /
  69. port: 80
  70. initialDelaySeconds: 10
  71. periodSeconds: 10
  72. timeoutSeconds: 5
  73. failureThreshold: 5
  74. successThreshold: 1
  75. readinessProbe:
  76. httpGet:
  77. path: /
  78. port: 80
  79. initialDelaySeconds: 10
  80. periodSeconds: 10
  81. timeoutSeconds: 5
  82. failureThreshold: 5
  83. successThreshold: 2
  84. startupProbe:
  85. httpGet:
  86. path: /
  87. port: 80
  88. initialDelaySeconds: 10
  89. periodSeconds: 5
  90. timeoutSeconds: 2
  91. failureThreshold: 60
  92. successThreshold: 1
  93. {{ end }}
  94. image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default "latest" }}"
  95. imagePullPolicy: {{ .Values.image.pullPolicy }}
  96. {{- include "containerCommand" . | indent 2 }}
  97. {{- include "containerArgs" . | indent 2 }}
  98. {{- include "containerEnvVariables" . | indent 2 }}
  99. {{- include "containerLivenssProbe" . | indent 2 }}
  100. {{- include "containerPorts" . | indent 2 }}
  101. {{- include "containerResourceConfiguration" . | indent 2 }}
  102. {{- include "volumeConfiguration" . }}
  103. {{- include "dnsConfiguration" . }}
  104. {{- end }}
  105. {{/*
  106. Annotations for workload
  107. */}}
  108. {{- define "workloadAnnotations" }}
  109. rollme: {{ randAlphaNum 5 | quote }}
  110. {{- if .Values.ixExternalInterfacesConfigurationNames }}
  111. k8s.v1.cni.cncf.io/networks: {{ join ", " .Values.ixExternalInterfacesConfigurationNames }}
  112. {{- end }}
  113. {{- end }}
  114. {{/*
  115. Metadata for workload
  116. */}}
  117. {{- define "commonMetadataWorkload" }}
  118. labels:
  119. {{- include "ix-chart.selectorLabels" . | nindent 2 }}
  120. annotations:
  121. {{- include "workloadAnnotations" . | nindent 2 }}
  122. {{- end }}
  123. {{/*
  124. Deployment Spec
  125. */}}
  126. {{- define "deploymentSpec" }}
  127. strategy:
  128. {{- if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostPortsList }}
  129. {{- fail "RollingUpdate is not allowed when host ports are specified" }}
  130. {{- else if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostNetwork }}
  131. {{- fail "RollingUpdate is not allowed when host network is enabled" }}
  132. {{- end }}
  133. type: {{ .Values.updateStrategy }}
  134. selector:
  135. matchLabels:
  136. {{- include "ix-chart.selectorLabels" . | nindent 4 }}
  137. template:
  138. metadata:
  139. {{ include "commonMetadataWorkload" . | nindent 4 }}
  140. spec:
  141. {{- include "podSepc" . | indent 4 }}
  142. {{- end }}
  143. {{/*
  144. Job Spec Common
  145. */}}
  146. {{- define "jobSpecCommon" }}
  147. metadata:
  148. {{ include "commonMetadataWorkload" . | nindent 4 }}
  149. spec:
  150. {{- include "podSepc" . | indent 2 }}
  151. {{- end }}
  152. {{/*
  153. Job Spec
  154. */}}
  155. {{- define "jobSpec" }}
  156. template:
  157. {{ include "jobSpecCommon" . | nindent 2 }}
  158. {{- end }}
  159. {{/*
  160. CronJob Spec
  161. */}}
  162. {{- define "cronJobSpec" }}
  163. schedule: {{ include "cronExpression" .Values.cronSchedule | quote }}
  164. jobTemplate:
  165. spec:
  166. {{ include "jobSpec" . | nindent 4 }}
  167. {{- end }}