_workload.tpl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 "volumeConfiguration" . }}
  109. {{- include "dnsConfiguration" . }}
  110. {{- end }}
  111. {{/*
  112. Annotations for workload
  113. */}}
  114. {{- define "workloadAnnotations" }}
  115. rollme: {{ randAlphaNum 5 | quote }}
  116. {{- if .Values.ixExternalInterfacesConfigurationNames }}
  117. k8s.v1.cni.cncf.io/networks: {{ join ", " .Values.ixExternalInterfacesConfigurationNames }}
  118. {{- end }}
  119. {{- end }}
  120. {{/*
  121. Metadata for workload
  122. */}}
  123. {{- define "commonMetadataWorkload" }}
  124. labels:
  125. {{- include "ix-chart.selectorLabels" . | nindent 2 }}
  126. annotations:
  127. {{- include "workloadAnnotations" . | nindent 2 }}
  128. {{- end }}
  129. {{/*
  130. Deployment Spec
  131. */}}
  132. {{- define "deploymentSpec" }}
  133. strategy:
  134. {{- if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostPortsList }}
  135. {{- fail "RollingUpdate is not allowed when host ports are specified" }}
  136. {{- else if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostNetwork }}
  137. {{- fail "RollingUpdate is not allowed when host network is enabled" }}
  138. {{- end }}
  139. type: {{ .Values.updateStrategy }}
  140. selector:
  141. matchLabels:
  142. {{- include "ix-chart.selectorLabels" . | nindent 4 }}
  143. template:
  144. metadata:
  145. {{ include "commonMetadataWorkload" . | nindent 4 }}
  146. spec:
  147. {{- include "podSepc" . | indent 4 }}
  148. {{- end }}
  149. {{/*
  150. Job Spec Common
  151. */}}
  152. {{- define "jobSpecCommon" }}
  153. metadata:
  154. {{ include "commonMetadataWorkload" . | nindent 4 }}
  155. spec:
  156. {{- include "podSepc" . | indent 2 }}
  157. {{- end }}
  158. {{/*
  159. Job Spec
  160. */}}
  161. {{- define "jobSpec" }}
  162. template:
  163. {{ include "jobSpecCommon" . | nindent 2 }}
  164. {{- end }}
  165. {{/*
  166. CronJob Spec
  167. */}}
  168. {{- define "cronJobSpec" }}
  169. schedule: {{ include "cronExpression" .Values.cronSchedule | quote }}
  170. jobTemplate:
  171. spec:
  172. {{ include "jobSpec" . | nindent 4 }}
  173. {{- end }}