Açıklama Yok

shuffle-apps.yaml 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. {{- if .Values.apps.enabled }}
  2. {{- range $key, $app := .Values.apps }}
  3. {{- $ignoredKeys := list "enabled" -}}
  4. {{- if and (not ($ignoredKeys | has $key)) $app.enabled }}
  5. {{/* Merge .Values.app into $app, giving precedence to the values defined on the app. */}}
  6. {{- $appValues := mustDeepCopy (mustMerge $app $.Values.app) -}}
  7. {{/* use shuffle.appRegistry as default image registry */}}
  8. {{- $_ := set $appValues.image "registry" ($appValues.image.registry | default $.Values.shuffle.appRegistry) -}}
  9. {{/* use shuffle.appBaseImageName as default image repository */}}
  10. {{- $_ := set $appValues.image "repository" ($appValues.image.repository | default (printf "%s/%s" $.Values.shuffle.appBaseImageName $appValues.name)) -}}
  11. {{/* use app version as default tag */}}
  12. {{- $_ := set $appValues.image "tag" ($appValues.image.tag | default $appValues.version) -}}
  13. {{/* Only create a service account if create is explicitly enabled on that specific app ($app not $appValues). Otherwise the shared shuffle-app service account is used. */}}
  14. {{- $shouldCreateDedicatedServiceAccount := and $app.serviceAccount.create $app.serviceAccount.name -}}
  15. {{- if $shouldCreateDedicatedServiceAccount }}
  16. ---
  17. apiVersion: v1
  18. kind: ServiceAccount
  19. metadata:
  20. name: {{ $app.serviceAccount.name | trunc 63 | trimSuffix "-" }}
  21. namespace: {{ include "common.names.namespace" $ | quote }}
  22. labels: {{- include "shuffle.app.labels" ( dict "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  23. {{- if or $appValues.serviceAccount.annotations $.Values.commonAnnotations }}
  24. {{- $annotations := include "common.tplvalues.merge" (dict "values" (list $appValues.serviceAccount.annotations $.Values.commonAnnotations) "context" $) }}
  25. annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
  26. {{- end }}
  27. automountServiceAccountToken: {{ $appValues.serviceAccount.automountServiceAccountToken }}
  28. {{- include "shuffle.app.serviceAccount.imagePullSecrets" $ | nindent 0 }}
  29. {{- if $appValues.rbac.create }}
  30. ---
  31. kind: RoleBinding
  32. apiVersion: {{ include "common.capabilities.rbac.apiVersion" $ }}
  33. metadata:
  34. name: {{ $app.serviceAccount.name | trunc 63 | trimSuffix "-" }}
  35. namespace: {{ include "common.names.namespace" $ | quote }}
  36. labels: {{- include "shuffle.app.labels" ( dict "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  37. {{- if $.Values.commonAnnotations }}
  38. annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  39. {{- end }}
  40. subjects:
  41. - kind: ServiceAccount
  42. name: {{ $app.serviceAccount.name | trunc 63 | trimSuffix "-" }}
  43. roleRef:
  44. apiGroup: rbac.authorization.k8s.io
  45. kind: Role
  46. name: {{ template "shuffle.app.name" $ }}
  47. {{- end }}
  48. {{- end }}
  49. ---
  50. apiVersion: v1
  51. kind: Service
  52. metadata:
  53. name: {{ include "shuffle.appInstance.fullname" $app }}
  54. namespace: {{ include "common.names.namespace" $ | quote }}
  55. {{- $serviceLabels := include "common.tplvalues.merge" (dict "values" (list $appValues.service.labels $.Values.commonLabels) "context" $) }}
  56. labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $serviceLabels "context" $ ) | nindent 4 }}
  57. {{- if $.Values.commonAnnotations }}
  58. annotations: {{- include "common.tplvalues.render" (dict "value" $.Values.commonAnnotations "context" $) | nindent 4 }}
  59. {{- end }}
  60. spec:
  61. type: ClusterIP
  62. ports:
  63. - name: http
  64. port: 80
  65. targetPort: {{ $appValues.exposedContainerPort }}
  66. protocol: TCP
  67. appProtocol: http
  68. {{- $podLabels := include "common.tplvalues.merge" (dict "values" (list $appValues.podLabels $.Values.commonLabels) "context" $) }}
  69. selector: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }}
  70. ---
  71. apiVersion: {{ include "common.capabilities.deployment.apiVersion" $ }}
  72. kind: Deployment
  73. metadata:
  74. name: {{ include "shuffle.appInstance.fullname" $app }}
  75. namespace: {{ include "common.names.namespace" $ | quote }}
  76. labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  77. {{- if or $appValues.deploymentAnnotations $.Values.commonAnnotations }}
  78. {{- $annotations := include "common.tplvalues.merge" (dict "values" (list $appValues.deploymentAnnotations $.Values.commonAnnotations) "context" $) }}
  79. annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
  80. {{- end }}
  81. spec:
  82. {{- if not $appValues.autoscaling.hpa.enabled }}
  83. replicas: {{ $appValues.replicaCount }}
  84. {{- end }}
  85. {{- if $appValues.updateStrategy }}
  86. strategy: {{- toYaml $appValues.updateStrategy | nindent 4 }}
  87. {{- end }}
  88. selector:
  89. matchLabels: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }}
  90. template:
  91. metadata:
  92. {{- if $appValues.podAnnotations }}
  93. annotations: {{- include "common.tplvalues.render" (dict "value" $appValues.podAnnotations "context" $) | nindent 8 }}
  94. {{- end }}
  95. labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 8 }}
  96. spec:
  97. {{- include "common.images.renderPullSecrets" (dict "images" (list $appValues.image) "context" $) | nindent 6 }}
  98. {{- if $appValues.serviceAccount.create }}
  99. serviceAccountName: {{ default (include "shuffle.app.name" $) $appValues.serviceAccount.name | trunc 63 | trimSuffix "-" }}
  100. {{- else }}
  101. serviceAccountName: {{ default "default" $appValues.serviceAccount.name }}
  102. {{- end }}
  103. automountServiceAccountToken: {{ $appValues.automountServiceAccountToken }}
  104. {{- if $appValues.hostAliases }}
  105. hostAliases: {{- include "common.tplvalues.render" (dict "value" $appValues.hostAliases "context" $) | nindent 8 }}
  106. {{- end }}
  107. {{- if $appValues.affinity }}
  108. affinity: {{- include "common.tplvalues.render" ( dict "value" $appValues.affinity "context" $) | nindent 8 }}
  109. {{- else }}
  110. affinity:
  111. podAffinity: {{- include "shuffle.appInstance.affinities.pods" (dict "app" $app "type" $appValues.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
  112. podAntiAffinity: {{- include "shuffle.appInstance.affinities.pods" (dict "app" $app "type" $appValues.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
  113. nodeAffinity: {{- include "common.affinities.nodes" (dict "type" $appValues.nodeAffinityPreset.type "key" $appValues.nodeAffinityPreset.key "values" $appValues.nodeAffinityPreset.values) | nindent 10 }}
  114. {{- end }}
  115. {{- if $appValues.nodeSelector }}
  116. nodeSelector: {{- include "common.tplvalues.render" ( dict "value" $appValues.nodeSelector "context" $) | nindent 8 }}
  117. {{- end }}
  118. {{- if $appValues.tolerations }}
  119. tolerations: {{- include "common.tplvalues.render" (dict "value" $appValues.tolerations "context" $) | nindent 8 }}
  120. {{- end }}
  121. {{- if $appValues.priorityClassName }}
  122. priorityClassName: {{ $appValues.priorityClassName | quote }}
  123. {{- end }}
  124. {{- if $appValues.schedulerName }}
  125. schedulerName: {{ $appValues.schedulerName | quote }}
  126. {{- end }}
  127. {{- if $appValues.topologySpreadConstraints }}
  128. topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" $appValues.topologySpreadConstraints "context" $) | nindent 8 }}
  129. {{- end }}
  130. {{- if $appValues.podSecurityContext.enabled }}
  131. securityContext: {{- omit $appValues.podSecurityContext "enabled" | toYaml | nindent 8 }}
  132. {{- end }}
  133. {{- if $appValues.terminationGracePeriodSeconds }}
  134. terminationGracePeriodSeconds: {{ $appValues.terminationGracePeriodSeconds }}
  135. {{- end }}
  136. initContainers:
  137. {{- if $appValues.initContainers }}
  138. {{- include "common.tplvalues.render" (dict "value" $appValues.initContainers "context" $) | nindent 8 }}
  139. {{- end }}
  140. containers:
  141. - name: {{ include "shuffle.appInstance.fullname" $app }}
  142. image: {{ include "common.images.image" ( dict "imageRoot" $appValues.image "global" $.Values.global "chart" $.Chart ) }}
  143. imagePullPolicy: {{ $appValues.image.pullPolicy }}
  144. {{- if $appValues.containerSecurityContext.enabled }}
  145. securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" $appValues.containerSecurityContext "context" $) | nindent 12 }}
  146. {{- end }}
  147. {{- if $.Values.diagnosticMode.enabled }}
  148. command: {{- include "common.tplvalues.render" (dict "value" $.Values.diagnosticMode.command "context" $) | nindent 12 }}
  149. {{- else if $appValues.command }}
  150. command: {{- include "common.tplvalues.render" (dict "value" $appValues.command "context" $) | nindent 12 }}
  151. {{- end }}
  152. {{- if $.Values.diagnosticMode.enabled }}
  153. args: {{- include "common.tplvalues.render" (dict "value" $.Values.diagnosticMode.args "context" $) | nindent 12 }}
  154. {{- else if $appValues.args }}
  155. args: {{- include "common.tplvalues.render" (dict "value" $appValues.args "context" $) | nindent 12 }}
  156. {{- end }}
  157. env:
  158. - name: AUTHORIZATION
  159. value: ""
  160. - name: EXECUTIONID
  161. value: ""
  162. - name: BASE_URL
  163. value: {{ include "shuffle.worker.baseUrl" $ | quote }}
  164. - name: CALLBACK_URL
  165. value: {{ include "shuffle.backend.baseUrl" $ | quote }}
  166. - name: SHUFFLE_SWARM_CONFIG
  167. value: run # Shuffle Worker requires this to be set even when using K8s instead of swarm
  168. {{- $env := include "shuffle.appInstance.env" $ | fromYaml }}
  169. {{- range $key, $val := $env }}
  170. - name: {{ $key | quote }}
  171. value: {{ $val | quote }}
  172. {{- end }}
  173. {{- if $appValues.extraEnvVars }}
  174. {{- include "common.tplvalues.render" (dict "value" $appValues.extraEnvVars "context" $) | nindent 12 }}
  175. {{- end }}
  176. envFrom:
  177. {{- if $appValues.extraEnvVarsCM }}
  178. - configMapRef:
  179. name: {{ include "common.tplvalues.render" (dict "value" $appValues.extraEnvVarsCM "context" $) }}
  180. {{- end }}
  181. {{- if $appValues.extraEnvVarsSecret }}
  182. - secretRef:
  183. name: {{ include "common.tplvalues.render" (dict "value" $appValues.extraEnvVarsSecret "context" $) }}
  184. {{- end }}
  185. {{- if $appValues.resources }}
  186. resources: {{- toYaml $appValues.resources | nindent 12 }}
  187. {{- else if ne $appValues.resourcesPreset "none" }}
  188. resources: {{- include "common.resources.preset" (dict "type" $appValues.resourcesPreset) | nindent 12 }}
  189. {{- end }}
  190. ports:
  191. - name: http
  192. containerPort: {{ $appValues.exposedContainerPort }}
  193. {{- if $appValues.extraContainerPorts }}
  194. {{- include "common.tplvalues.render" (dict "value" $appValues.extraContainerPorts "context" $) | nindent 12 }}
  195. {{- end }}
  196. {{- if not $.Values.diagnosticMode.enabled }}
  197. {{- if $appValues.customLivenessProbe }}
  198. livenessProbe: {{- include "common.tplvalues.render" (dict "value" $appValues.customLivenessProbe "context" $) | nindent 12 }}
  199. {{- else if $appValues.livenessProbe.enabled }}
  200. livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit $appValues.livenessProbe "enabled") "context" $) | nindent 12 }}
  201. httpGet:
  202. path: /api/v1/health
  203. port: {{ $appValues.containerPorts.http }}
  204. {{- end }}
  205. {{- if $appValues.customReadinessProbe }}
  206. readinessProbe: {{- include "common.tplvalues.render" (dict "value" $appValues.customReadinessProbe "context" $) | nindent 12 }}
  207. {{- else if $appValues.readinessProbe.enabled }}
  208. readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit $appValues.readinessProbe "enabled") "context" $) | nindent 12 }}
  209. httpGet:
  210. path: /api/v1/health
  211. port: {{ $appValues.containerPorts.http }}
  212. {{- end }}
  213. {{- if $appValues.customStartupProbe }}
  214. startupProbe: {{- include "common.tplvalues.render" (dict "value" $appValues.customStartupProbe "context" $) | nindent 12 }}
  215. {{- else if $appValues.startupProbe.enabled }}
  216. startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit $appValues.startupProbe "enabled") "context" $) | nindent 12 }}
  217. httpGet:
  218. path: /api/v1/health
  219. port: {{ $appValues.containerPorts.http }}
  220. {{- end }}
  221. {{- end }}
  222. {{- if $appValues.lifecycleHooks }}
  223. lifecycle: {{- include "common.tplvalues.render" (dict "value" $appValues.lifecycleHooks "context" $) | nindent 12 }}
  224. {{- end }}
  225. volumeMounts:
  226. {{- if $appValues.mountTmpVolume }}
  227. - name: empty-dir
  228. mountPath: /tmp
  229. subPath: tmp-dir
  230. {{- end }}
  231. {{- if $appValues.extraVolumeMounts }}
  232. {{- include "common.tplvalues.render" (dict "value" $appValues.extraVolumeMounts "context" $) | nindent 12 }}
  233. {{- end }}
  234. {{- if $appValues.sidecars }}
  235. {{- include "common.tplvalues.render" ( dict "value" $appValues.sidecars "context" $) | nindent 8 }}
  236. {{- end }}
  237. volumes:
  238. - name: empty-dir
  239. emptyDir: {}
  240. {{- if $appValues.extraVolumes }}
  241. {{- include "common.tplvalues.render" (dict "value" $appValues.extraVolumes "context" $) | nindent 8 }}
  242. {{- end }}
  243. ---
  244. {{- if $appValues.pdb.create }}
  245. apiVersion: {{ include "common.capabilities.policy.apiVersion" $ }}
  246. kind: PodDisruptionBudget
  247. metadata:
  248. name: {{ include "shuffle.appInstance.fullname" $app }}
  249. namespace: {{ include "common.names.namespace" $ | quote }}
  250. labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  251. {{- if $.Values.commonAnnotations }}
  252. annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  253. {{- end }}
  254. spec:
  255. {{- if $appValues.pdb.minAvailable }}
  256. minAvailable: {{ $appValues.pdb.minAvailable }}
  257. {{- end }}
  258. {{- if or $appValues.pdb.maxUnavailable ( not $appValues.pdb.minAvailable ) }}
  259. maxUnavailable: {{ $appValues.pdb.maxUnavailable | default 1 }}
  260. {{- end }}
  261. selector:
  262. matchLabels: {{- include "shuffle.appInstance.matchLabels" ( dict "app" $app "customLabels" $podLabels "context" $ ) | nindent 6 }}
  263. {{- end }}
  264. ---
  265. {{- if $appValues.autoscaling.hpa.enabled }}
  266. apiVersion: {{ include "common.capabilities.hpa.apiVersion" $ }}
  267. kind: HorizontalPodAutoscaler
  268. metadata:
  269. name: {{ include "shuffle.appInstance.fullname" $app }}
  270. namespace: {{ include "common.names.namespace" $ | quote }}
  271. labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  272. {{- if $.Values.commonAnnotations }}
  273. annotations: {{- include "common.tplvalues.render" ( dict "value" $.Values.commonAnnotations "context" $ ) | nindent 4 }}
  274. {{- end }}
  275. spec:
  276. scaleTargetRef:
  277. apiVersion: {{ include "common.capabilities.deployment.apiVersion" $ }}
  278. kind: Deployment
  279. name: {{ include "shuffle.appInstance.fullname" $app }}
  280. minReplicas: {{ $appValues.autoscaling.hpa.minReplicas }}
  281. maxReplicas: {{ $appValues.autoscaling.hpa.maxReplicas }}
  282. metrics:
  283. {{- if $appValues.autoscaling.hpa.targetMemory }}
  284. - type: Resource
  285. resource:
  286. name: memory
  287. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" $) }}
  288. targetAverageUtilization: {{ $appValues.autoscaling.hpa.targetMemory }}
  289. {{- else }}
  290. target:
  291. type: Utilization
  292. averageUtilization: {{ $appValues.autoscaling.hpa.targetMemory }}
  293. {{- end }}
  294. {{- end }}
  295. {{- if $appValues.autoscaling.hpa.targetCPU }}
  296. - type: Resource
  297. resource:
  298. name: cpu
  299. {{- if semverCompare "<1.23-0" (include "common.capabilities.kubeVersion" $) }}
  300. targetAverageUtilization: {{ $appValues.autoscaling.hpa.targetCPU }}
  301. {{- else }}
  302. target:
  303. type: Utilization
  304. averageUtilization: {{ $appValues.autoscaling.hpa.targetCPU }}
  305. {{- end }}
  306. {{- end }}
  307. {{- end }}
  308. ---
  309. {{- if and ($.Capabilities.APIVersions.Has "autoscaling.k8s.io/v1/VerticalPodAutoscaler") $appValues.autoscaling.vpa.enabled }}
  310. apiVersion: autoscaling.k8s.io/v1
  311. kind: VerticalPodAutoscaler
  312. metadata:
  313. name: {{ include "shuffle.appInstance.fullname" $app }}
  314. namespace: {{ include "common.names.namespace" $ | quote }}
  315. labels: {{- include "shuffle.appInstance.labels" ( dict "app" $app "customLabels" $.Values.commonLabels "context" $ ) | nindent 4 }}
  316. {{- if or $appValues.autoscaling.vpa.annotations $.Values.commonAnnotations }}
  317. {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list $appValues.autoscaling.vpa.annotations $.Values.commonAnnotations ) "context" $ ) }}
  318. annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  319. {{- end }}
  320. spec:
  321. resourcePolicy:
  322. containerPolicies:
  323. - containerName: app
  324. {{- with $appValues.autoscaling.vpa.controlledResources }}
  325. controlledResources:
  326. {{- toYaml . | nindent 8 }}
  327. {{- end }}
  328. {{- with $appValues.autoscaling.vpa.maxAllowed }}
  329. maxAllowed:
  330. {{- toYaml . | nindent 8 }}
  331. {{- end }}
  332. {{- with $appValues.autoscaling.vpa.minAllowed }}
  333. minAllowed:
  334. {{- toYaml . | nindent 8 }}
  335. {{- end }}
  336. targetRef:
  337. apiVersion: {{ include "common.capabilities.deployment.apiVersion" $ }}
  338. kind: Deployment
  339. name: {{ include "shuffle.appInstance.fullname" $app }}
  340. {{- if $appValues.autoscaling.vpa.updatePolicy }}
  341. updatePolicy:
  342. {{- with $appValues.autoscaling.vpa.updatePolicy.updateMode }}
  343. updateMode: {{ . }}
  344. {{- end }}
  345. {{- end }}
  346. {{- end }}
  347. {{- end }}
  348. {{- end }}
  349. {{- end }}