_workload.tpl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. {{- if hasKey .Values "global" }}
  50. {{- if hasKey .Values.global "ixChartContext" }}
  51. {{- if .Values.global.ixChartContext.addNvidiaRuntimeClass }}
  52. runtimeClassName: {{ .Values.global.ixChartContext.nvidiaRuntimeClassName }}
  53. {{- end }}
  54. {{- end }}
  55. {{- end }}
  56. containers:
  57. - name: {{ .Chart.Name }}
  58. {{ include "common.resources.limitation" . | nindent 2 }}
  59. {{- include "volumeMountsConfiguration" . | indent 2}}
  60. tty: {{ .Values.tty }}
  61. stdin: {{ .Values.stdin }}
  62. securityContext:
  63. privileged: {{ .Values.securityContext.privileged }}
  64. {{ if .Values.securityContext.enableRunAsUser }}
  65. runAsUser: {{ .Values.securityContext.runAsUser }}
  66. runAsGroup: {{ .Values.securityContext.runAsGroup }}
  67. {{ end }}
  68. {{ if .Values.securityContext.capabilities }}
  69. capabilities:
  70. add: {{ toYaml .Values.securityContext.capabilities | nindent 8 }}
  71. {{ end }}
  72. {{ if .Values.ci }}
  73. livenessProbe:
  74. httpGet:
  75. path: /
  76. port: 80
  77. initialDelaySeconds: 10
  78. periodSeconds: 10
  79. timeoutSeconds: 5
  80. failureThreshold: 5
  81. successThreshold: 1
  82. readinessProbe:
  83. httpGet:
  84. path: /
  85. port: 80
  86. initialDelaySeconds: 10
  87. periodSeconds: 10
  88. timeoutSeconds: 5
  89. failureThreshold: 5
  90. successThreshold: 2
  91. startupProbe:
  92. httpGet:
  93. path: /
  94. port: 80
  95. initialDelaySeconds: 10
  96. periodSeconds: 5
  97. timeoutSeconds: 2
  98. failureThreshold: 60
  99. successThreshold: 1
  100. {{ end }}
  101. image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default "latest" }}"
  102. imagePullPolicy: {{ .Values.image.pullPolicy }}
  103. {{- include "containerCommand" . | indent 2 }}
  104. {{- include "containerArgs" . | indent 2 }}
  105. {{- include "containerEnvVariables" . | indent 2 }}
  106. {{- include "containerLivenssProbe" . | indent 2 }}
  107. {{- include "containerPorts" . | indent 2 }}
  108. {{- include "containerResourceConfiguration" . | indent 2 }}
  109. {{- include "volumeConfiguration" . }}
  110. {{- include "dnsConfiguration" . }}
  111. {{- end }}
  112. {{/*
  113. Annotations for workload
  114. */}}
  115. {{- define "workloadAnnotations" }}
  116. rollme: {{ randAlphaNum 5 | quote }}
  117. {{- if .Values.ixExternalInterfacesConfigurationNames }}
  118. k8s.v1.cni.cncf.io/networks: {{ join ", " .Values.ixExternalInterfacesConfigurationNames }}
  119. {{- end }}
  120. {{- end }}
  121. {{/*
  122. Metadata for workload
  123. */}}
  124. {{- define "commonMetadataWorkload" }}
  125. labels:
  126. {{- include "ix-chart.selectorLabels" . | nindent 2 }}
  127. annotations:
  128. {{- include "workloadAnnotations" . | nindent 2 }}
  129. {{- end }}
  130. {{/*
  131. Deployment Spec
  132. */}}
  133. {{- define "deploymentSpec" }}
  134. strategy:
  135. {{- if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostPortsList }}
  136. {{- fail "RollingUpdate is not allowed when host ports are specified" }}
  137. {{- else if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostNetwork }}
  138. {{- fail "RollingUpdate is not allowed when host network is enabled" }}
  139. {{- end }}
  140. type: {{ .Values.updateStrategy }}
  141. selector:
  142. matchLabels:
  143. {{- include "ix-chart.selectorLabels" . | nindent 4 }}
  144. template:
  145. metadata:
  146. {{ include "commonMetadataWorkload" . | nindent 4 }}
  147. spec:
  148. {{- include "podSepc" . | indent 4 }}
  149. {{- end }}
  150. {{/*
  151. Job Spec Common
  152. */}}
  153. {{- define "jobSpecCommon" }}
  154. metadata:
  155. {{ include "commonMetadataWorkload" . | nindent 4 }}
  156. spec:
  157. {{- include "podSepc" . | indent 2 }}
  158. {{- end }}
  159. {{/*
  160. Job Spec
  161. */}}
  162. {{- define "jobSpec" }}
  163. template:
  164. {{ include "jobSpecCommon" . | nindent 2 }}
  165. {{- end }}
  166. {{/*
  167. CronJob Spec
  168. */}}
  169. {{- define "cronJobSpec" }}
  170. schedule: {{ include "cronExpression" .Values.cronSchedule | quote }}
  171. jobTemplate:
  172. spec:
  173. {{ include "jobSpec" . | nindent 4 }}
  174. {{- end }}