_workload.tpl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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: {{ .Values.hostNetwork }}
  49. containers:
  50. - name: {{ .Chart.Name }}
  51. {{- include "volumeMountsConfiguration" . | indent 2}}
  52. securityContext:
  53. {{- toYaml .Values.securityContext | nindent 12 }}
  54. image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default "latest" }}"
  55. imagePullPolicy: {{ .Values.image.pullPolicy }}
  56. {{- include "containerCommand" . | indent 2 }}
  57. {{- include "containerArgs" . | indent 2 }}
  58. {{- include "containerEnvVariables" . | indent 2 }}
  59. {{- include "containerLivenssProbe" . | indent 2 }}
  60. {{- include "containerPorts" . | indent 2 }}
  61. {{- include "containerResourceConfiguration" . | indent 2 }}
  62. {{- include "volumeConfiguration" . }}
  63. {{- include "dnsConfiguration" . }}
  64. {{- end }}
  65. {{/*
  66. Annotations for workload
  67. */}}
  68. {{- define "workloadAnnotations" }}
  69. rollme: {{ randAlphaNum 5 | quote }}
  70. {{- if .Values.ixExternalInterfacesConfigurationNames }}
  71. k8s.v1.cni.cncf.io/networks: {{ join ", " .Values.ixExternalInterfacesConfigurationNames }}
  72. {{- end }}
  73. {{- end }}
  74. {{/*
  75. Metadata for workload
  76. */}}
  77. {{- define "commonMetadataWorkload" }}
  78. labels:
  79. {{- include "ix-chart.selectorLabels" . | nindent 2 }}
  80. annotations:
  81. {{- include "workloadAnnotations" . | nindent 2 }}
  82. {{- end }}
  83. {{/*
  84. Deployment Spec
  85. */}}
  86. {{- define "deploymentSpec" }}
  87. strategy:
  88. {{- if and (eq .Values.updateStrategy "RollingUpdate") .Values.hostPortsList }}
  89. {{- fail "RollingUpdate is not allowed when host ports are specified" }}
  90. {{- end }}
  91. type: {{ .Values.updateStrategy }}
  92. selector:
  93. matchLabels:
  94. {{- include "ix-chart.selectorLabels" . | nindent 4 }}
  95. template:
  96. metadata:
  97. {{ include "commonMetadataWorkload" . | nindent 4 }}
  98. spec:
  99. {{- include "podSepc" . | indent 4 }}
  100. {{- end }}
  101. {{/*
  102. Job Spec Common
  103. */}}
  104. {{- define "jobSpecCommon" }}
  105. metadata:
  106. {{ include "commonMetadataWorkload" . | nindent 4 }}
  107. spec:
  108. {{- include "podSepc" . | indent 2 }}
  109. {{- end }}
  110. {{/*
  111. Job Spec
  112. */}}
  113. {{- define "jobSpec" }}
  114. template:
  115. {{ include "jobSpecCommon" . | nindent 2 }}
  116. {{- end }}
  117. {{/*
  118. CronJob Spec
  119. */}}
  120. {{- define "cronJobSpec" }}
  121. schedule: {{ include "cronExpression" .Values.cronSchedule | quote }}
  122. jobTemplate:
  123. spec:
  124. {{ include "jobSpec" . | nindent 4 }}
  125. {{- end }}