_helpers.yaml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. {{/*
  18. Create a default fully qualified app name.
  19. We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
  20. If release name contains chart name it will be used as a full name.
  21. */}}
  22. {{- define "airflow.fullname" -}}
  23. {{- if .Values.fullnameOverride }}
  24. {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
  25. {{- else }}
  26. {{- $name := default .Chart.Name .Values.nameOverride }}
  27. {{- if contains $name .Release.Name }}
  28. {{- .Release.Name | trunc 63 | trimSuffix "-" }}
  29. {{- else }}
  30. {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
  31. {{- end }}
  32. {{- end }}
  33. {{- end }}
  34. {{/* Standard Airflow environment variables */}}
  35. {{- define "standard_airflow_environment" }}
  36. # Hard Coded Airflow Envs
  37. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__CORE__FERNET_KEY }}
  38. - name: AIRFLOW__CORE__FERNET_KEY
  39. valueFrom:
  40. secretKeyRef:
  41. name: {{ template "fernet_key_secret" . }}
  42. key: fernet-key
  43. {{- end }}
  44. # For Airflow <2.3, backward compatibility; moved to [database] in 2.3
  45. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__CORE__SQL_ALCHEMY_CONN }}
  46. - name: AIRFLOW__CORE__SQL_ALCHEMY_CONN
  47. valueFrom:
  48. secretKeyRef:
  49. name: {{ template "airflow_metadata_secret" . }}
  50. key: connection
  51. {{- end }}
  52. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__DATABASE__SQL_ALCHEMY_CONN }}
  53. - name: AIRFLOW__DATABASE__SQL_ALCHEMY_CONN
  54. valueFrom:
  55. secretKeyRef:
  56. name: {{ template "airflow_metadata_secret" . }}
  57. key: connection
  58. {{- end }}
  59. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW_CONN_AIRFLOW_DB }}
  60. - name: AIRFLOW_CONN_AIRFLOW_DB
  61. valueFrom:
  62. secretKeyRef:
  63. name: {{ template "airflow_metadata_secret" . }}
  64. key: connection
  65. {{- end }}
  66. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__WEBSERVER__SECRET_KEY }}
  67. - name: AIRFLOW__WEBSERVER__SECRET_KEY
  68. valueFrom:
  69. secretKeyRef:
  70. name: {{ template "webserver_secret_key_secret" . }}
  71. key: webserver-secret-key
  72. {{- end }}
  73. {{- if or (eq .Values.executor "CeleryExecutor") (eq .Values.executor "CeleryKubernetesExecutor") }}
  74. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__CELERY__CELERY_RESULT_BACKEND }}
  75. # (Airflow 1.10.* variant)
  76. - name: AIRFLOW__CELERY__CELERY_RESULT_BACKEND
  77. valueFrom:
  78. secretKeyRef:
  79. name: {{ template "airflow_result_backend_secret" . }}
  80. key: connection
  81. {{- end }}
  82. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__CELERY__RESULT_BACKEND }}
  83. - name: AIRFLOW__CELERY__RESULT_BACKEND
  84. valueFrom:
  85. secretKeyRef:
  86. name: {{ template "airflow_result_backend_secret" . }}
  87. key: connection
  88. {{- end }}
  89. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__CELERY__BROKER_URL }}
  90. - name: AIRFLOW__CELERY__BROKER_URL
  91. valueFrom:
  92. secretKeyRef:
  93. name: {{ default (printf "%s-broker-url" .Release.Name) .Values.data.brokerUrlSecretName }}
  94. key: connection
  95. {{- end }}
  96. {{- end }}
  97. {{- if .Values.elasticsearch.enabled }}
  98. # The elasticsearch variables were updated to the shorter names in v1.10.4
  99. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__ELASTICSEARCH__HOST }}
  100. - name: AIRFLOW__ELASTICSEARCH__HOST
  101. valueFrom:
  102. secretKeyRef:
  103. name: {{ template "elasticsearch_secret" . }}
  104. key: connection
  105. {{- end }}
  106. {{- if .Values.enableBuiltInSecretEnvVars.AIRFLOW__ELASTICSEARCH__ELASTICSEARCH_HOST }}
  107. # This is the older format for these variable names, kept here for backward compatibility
  108. - name: AIRFLOW__ELASTICSEARCH__ELASTICSEARCH_HOST
  109. valueFrom:
  110. secretKeyRef:
  111. name: {{ template "elasticsearch_secret" . }}
  112. key: connection
  113. {{- end }}
  114. {{- end }}
  115. {{- end }}
  116. {{/* User defined Airflow environment variables */}}
  117. {{- define "custom_airflow_environment" }}
  118. # Dynamically created environment variables
  119. {{- range $i, $config := .Values.env }}
  120. - name: {{ $config.name }}
  121. value: {{ $config.value | quote }}
  122. {{- if or (eq $.Values.executor "KubernetesExecutor") (eq $.Values.executor "LocalKubernetesExecutor") (eq $.Values.executor "CeleryKubernetesExecutor") }}
  123. - name: AIRFLOW__KUBERNETES_ENVIRONMENT_VARIABLES__{{ $config.name }}
  124. value: {{ $config.value | quote }}
  125. {{- end }}
  126. {{- end }}
  127. # Dynamically created secret envs
  128. {{- range $i, $config := .Values.secret }}
  129. - name: {{ $config.envName }}
  130. valueFrom:
  131. secretKeyRef:
  132. name: {{ $config.secretName }}
  133. key: {{ default "value" $config.secretKey }}
  134. {{- end }}
  135. {{- if or (eq $.Values.executor "LocalKubernetesExecutor") (eq $.Values.executor "KubernetesExecutor") (eq $.Values.executor "CeleryKubernetesExecutor") }}
  136. {{- range $i, $config := .Values.secret }}
  137. - name: AIRFLOW__KUBERNETES_SECRETS__{{ $config.envName }}
  138. value: {{ printf "%s=%s" $config.secretName $config.secretKey }}
  139. {{- end }}
  140. {{ end }}
  141. # Extra env
  142. {{- $Global := . }}
  143. {{- with .Values.extraEnv }}
  144. {{- tpl . $Global | nindent 2 }}
  145. {{- end }}
  146. {{- end }}
  147. {{/* User defined Airflow environment from */}}
  148. {{- define "custom_airflow_environment_from" }}
  149. {{- $Global := . }}
  150. {{- with .Values.extraEnvFrom }}
  151. {{- tpl . $Global | nindent 2 }}
  152. {{- end }}
  153. {{- end }}
  154. {{/* Git ssh key volume */}}
  155. {{- define "git_sync_ssh_key_volume"}}
  156. - name: git-sync-ssh-key
  157. secret:
  158. secretName: {{ .Values.dags.gitSync.sshKeySecret }}
  159. defaultMode: 288
  160. {{- end }}
  161. {{/* Git sync container */}}
  162. {{- define "git_sync_container"}}
  163. - name: {{ .Values.dags.gitSync.containerName }}{{ if .is_init }}-init{{ end }}
  164. image: {{ template "git_sync_image" . }}
  165. imagePullPolicy: {{ .Values.images.gitSync.pullPolicy }}
  166. securityContext: {{ include "localSecurityContext" .Values.dags.gitSync | nindent 4 }}
  167. env:
  168. {{- if .Values.dags.gitSync.sshKeySecret }}
  169. - name: GIT_SSH_KEY_FILE
  170. value: "/etc/git-secret/ssh"
  171. - name: GIT_SYNC_SSH
  172. value: "true"
  173. {{- if .Values.dags.gitSync.knownHosts }}
  174. - name: GIT_KNOWN_HOSTS
  175. value: "true"
  176. - name: GIT_SSH_KNOWN_HOSTS_FILE
  177. value: "/etc/git-secret/known_hosts"
  178. {{- else }}
  179. - name: GIT_KNOWN_HOSTS
  180. value: "false"
  181. {{- end }}
  182. {{ else if .Values.dags.gitSync.credentialsSecret }}
  183. - name: GIT_SYNC_USERNAME
  184. valueFrom:
  185. secretKeyRef:
  186. name: {{ .Values.dags.gitSync.credentialsSecret | quote }}
  187. key: GIT_SYNC_USERNAME
  188. - name: GIT_SYNC_PASSWORD
  189. valueFrom:
  190. secretKeyRef:
  191. name: {{ .Values.dags.gitSync.credentialsSecret | quote }}
  192. key: GIT_SYNC_PASSWORD
  193. {{- end }}
  194. - name: GIT_SYNC_REV
  195. value: {{ .Values.dags.gitSync.rev | quote }}
  196. - name: GIT_SYNC_BRANCH
  197. value: {{ .Values.dags.gitSync.branch | quote }}
  198. - name: GIT_SYNC_REPO
  199. value: {{ .Values.dags.gitSync.repo | quote }}
  200. - name: GIT_SYNC_DEPTH
  201. value: {{ .Values.dags.gitSync.depth | quote }}
  202. - name: GIT_SYNC_ROOT
  203. value: "/git"
  204. - name: GIT_SYNC_DEST
  205. value: "repo"
  206. - name: GIT_SYNC_ADD_USER
  207. value: "true"
  208. - name: GIT_SYNC_WAIT
  209. value: {{ .Values.dags.gitSync.wait | quote }}
  210. - name: GIT_SYNC_MAX_SYNC_FAILURES
  211. value: {{ .Values.dags.gitSync.maxFailures | quote }}
  212. {{- if .is_init }}
  213. - name: GIT_SYNC_ONE_TIME
  214. value: "true"
  215. {{- end }}
  216. {{- range $i, $config := .Values.dags.gitSync.env }}
  217. - name: {{ $config.name }}
  218. value: {{ $config.value | quote }}
  219. {{- end }}
  220. resources: {{ toYaml .Values.dags.gitSync.resources | nindent 6 }}
  221. volumeMounts:
  222. - name: dags
  223. mountPath: /git
  224. {{- if .Values.dags.gitSync.sshKeySecret }}
  225. - name: git-sync-ssh-key
  226. mountPath: /etc/git-secret/ssh
  227. readOnly: true
  228. subPath: gitSshKey
  229. {{- if .Values.dags.gitSync.knownHosts }}
  230. - name: config
  231. mountPath: /etc/git-secret/known_hosts
  232. readOnly: true
  233. subPath: known_hosts
  234. {{- end }}
  235. {{- end }}
  236. {{- if .Values.dags.gitSync.extraVolumeMounts }}
  237. {{ toYaml .Values.dags.gitSync.extraVolumeMounts | indent 2 }}
  238. {{- end }}
  239. {{- end }}
  240. # This helper will change when customers deploy a new image.
  241. {{ define "airflow_image" -}}
  242. {{ printf "%s:%s" (.Values.images.airflow.repository | default .Values.defaultAirflowRepository) (.Values.images.airflow.tag | default .Values.defaultAirflowTag) }}
  243. {{- end }}
  244. {{ define "pod_template_image" -}}
  245. {{ printf "%s:%s" (.Values.images.pod_template.repository | default .Values.defaultAirflowRepository) (.Values.images.pod_template.tag | default .Values.defaultAirflowTag) }}
  246. {{- end }}
  247. # This helper is used for airflow containers that do not need the users code.
  248. {{ define "default_airflow_image" -}}
  249. {{ printf "%s:%s" .Values.defaultAirflowRepository .Values.defaultAirflowTag }}
  250. {{- end }}
  251. {{ define "airflow_image_for_migrations" -}}
  252. {{- if .Values.images.useDefaultImageForMigration -}}
  253. {{ template "default_airflow_image" . }}
  254. {{- else -}}
  255. {{ template "airflow_image" . }}
  256. {{- end -}}
  257. {{- end }}
  258. {{ define "flower_image" -}}
  259. {{ printf "%s:%s" (.Values.images.flower.repository | default .Values.defaultAirflowRepository) (.Values.images.flower.tag | default .Values.defaultAirflowTag) }}
  260. {{- end }}
  261. {{ define "statsd_image" -}}
  262. {{ printf "%s:%s" .Values.images.statsd.repository .Values.images.statsd.tag }}
  263. {{- end }}
  264. {{ define "redis_image" -}}
  265. {{ printf "%s:%s" .Values.images.redis.repository .Values.images.redis.tag }}
  266. {{- end }}
  267. {{ define "pgbouncer_image" -}}
  268. {{ printf "%s:%s" .Values.images.pgbouncer.repository .Values.images.pgbouncer.tag }}
  269. {{- end }}
  270. {{ define "pgbouncer_exporter_image" -}}
  271. {{ printf "%s:%s" .Values.images.pgbouncerExporter.repository .Values.images.pgbouncerExporter.tag }}
  272. {{- end }}
  273. {{ define "git_sync_image" -}}
  274. {{ printf "%s:%s" .Values.images.gitSync.repository .Values.images.gitSync.tag }}
  275. {{- end }}
  276. {{ define "fernet_key_secret" -}}
  277. {{ default (printf "%s-fernet-key" .Release.Name) .Values.fernetKeySecretName }}
  278. {{- end }}
  279. {{ define "webserver_secret_key_secret" -}}
  280. {{ default (printf "%s-webserver-secret-key" .Release.Name) .Values.webserverSecretKeySecretName }}
  281. {{- end }}
  282. {{ define "redis_password_secret" -}}
  283. {{ default (printf "%s-redis-password" .Release.Name) .Values.redis.passwordSecretName }}
  284. {{- end }}
  285. {{ define "airflow_metadata_secret" -}}
  286. {{ default (printf "%s-airflow-metadata" .Release.Name) .Values.data.metadataSecretName }}
  287. {{- end }}
  288. {{ define "airflow_result_backend_secret" -}}
  289. {{ default (printf "%s-airflow-result-backend" .Release.Name) .Values.data.resultBackendSecretName }}
  290. {{- end }}
  291. {{ define "airflow_pod_template_file" -}}
  292. {{ (printf "%s/pod_templates" .Values.airflowHome) }}
  293. {{- end }}
  294. {{ define "pgbouncer_config_secret" -}}
  295. {{ default (printf "%s-pgbouncer-config" .Release.Name) .Values.pgbouncer.configSecretName }}
  296. {{- end }}
  297. {{ define "pgbouncer_certificates_secret" -}}
  298. {{ .Release.Name }}-pgbouncer-certificates
  299. {{- end }}
  300. {{ define "pgbouncer_stats_secret" -}}
  301. {{ .Release.Name }}-pgbouncer-stats
  302. {{- end }}
  303. {{ define "registry_secret" -}}
  304. {{ default (printf "%s-registry" .Release.Name) .Values.registry.secretName }}
  305. {{- end }}
  306. {{ define "elasticsearch_secret" -}}
  307. {{ default (printf "%s-elasticsearch" .Release.Name) .Values.elasticsearch.secretName }}
  308. {{- end }}
  309. {{ define "flower_secret" -}}
  310. {{ default (printf "%s-flower" .Release.Name) .Values.flower.secretName }}
  311. {{- end }}
  312. {{ define "kerberos_keytab_secret" -}}
  313. {{ .Release.Name }}-kerberos-keytab
  314. {{- end }}
  315. {{ define "kerberos_ccache_path" -}}
  316. {{ printf "%s/%s" .Values.kerberos.ccacheMountPath .Values.kerberos.ccacheFileName }}
  317. {{- end }}
  318. {{ define "pgbouncer_config" }}
  319. {{- $resultBackendConnection := .Values.data.resultBackendConnection | default .Values.data.metadataConnection }}
  320. {{- $pgMetadataHost := .Values.data.metadataConnection.host | default (printf "%s-%s.%s" .Release.Name "postgresql" .Release.Namespace) }}
  321. {{- $pgResultBackendHost := $resultBackendConnection.host | default (printf "%s-%s.%s" .Release.Name "postgresql" .Release.Namespace) }}
  322. [databases]
  323. {{ .Release.Name }}-metadata = host={{ $pgMetadataHost }} dbname={{ .Values.data.metadataConnection.db }} port={{ .Values.data.metadataConnection.port }} pool_size={{ .Values.pgbouncer.metadataPoolSize }} {{ .Values.pgbouncer.extraIniMetadata | default "" }}
  324. {{ .Release.Name }}-result-backend = host={{ $pgResultBackendHost }} dbname={{ $resultBackendConnection.db }} port={{ $resultBackendConnection.port }} pool_size={{ .Values.pgbouncer.resultBackendPoolSize }} {{ .Values.pgbouncer.extraIniResultBackend | default "" }}
  325. [pgbouncer]
  326. pool_mode = transaction
  327. listen_port = {{ .Values.ports.pgbouncer }}
  328. listen_addr = *
  329. auth_type = {{ .Values.pgbouncer.auth_type }}
  330. auth_file = {{ .Values.pgbouncer.auth_file }}
  331. stats_users = {{ .Values.data.metadataConnection.user }}
  332. ignore_startup_parameters = extra_float_digits
  333. max_client_conn = {{ .Values.pgbouncer.maxClientConn }}
  334. verbose = {{ .Values.pgbouncer.verbose }}
  335. log_disconnections = {{ .Values.pgbouncer.logDisconnections }}
  336. log_connections = {{ .Values.pgbouncer.logConnections }}
  337. server_tls_sslmode = {{ .Values.pgbouncer.sslmode }}
  338. server_tls_ciphers = {{ .Values.pgbouncer.ciphers }}
  339. {{- if .Values.pgbouncer.ssl.ca }}
  340. server_tls_ca_file = /etc/pgbouncer/root.crt
  341. {{- end }}
  342. {{- if .Values.pgbouncer.ssl.cert }}
  343. server_tls_cert_file = /etc/pgbouncer/server.crt
  344. {{- end }}
  345. {{- if .Values.pgbouncer.ssl.key }}
  346. server_tls_key_file = /etc/pgbouncer/server.key
  347. {{- end }}
  348. {{- if .Values.pgbouncer.extraIni }}
  349. {{ .Values.pgbouncer.extraIni }}
  350. {{- end }}
  351. {{- end }}
  352. {{ define "pgbouncer_users" }}
  353. {{- $resultBackendConnection := .Values.data.resultBackendConnection | default .Values.data.metadataConnection }}
  354. {{ .Values.data.metadataConnection.user | quote }} {{ .Values.data.metadataConnection.pass | quote }}
  355. {{ $resultBackendConnection.user | quote }} {{ $resultBackendConnection.pass | quote }}
  356. {{- end }}
  357. {{ define "airflow_logs" -}}
  358. {{ (printf "%s/logs" .Values.airflowHome) | quote }}
  359. {{- end }}
  360. {{ define "airflow_logs_no_quote" -}}
  361. {{ (printf "%s/logs" .Values.airflowHome) }}
  362. {{- end }}
  363. {{ define "airflow_logs_volume_claim" -}}
  364. {{- if .Values.logs.persistence.existingClaim -}}
  365. {{ .Values.logs.persistence.existingClaim }}
  366. {{- else -}}
  367. {{ .Release.Name }}-logs
  368. {{- end -}}
  369. {{- end -}}
  370. {{ define "airflow_dags" -}}
  371. {{- if .Values.dags.gitSync.enabled -}}
  372. {{ (printf "%s/dags/repo/%s" .Values.airflowHome .Values.dags.gitSync.subPath) }}
  373. {{- else -}}
  374. {{ (printf "%s/dags" .Values.airflowHome) }}
  375. {{- end -}}
  376. {{- end -}}
  377. {{ define "airflow_dags_volume_claim" -}}
  378. {{- if .Values.dags.persistence.existingClaim -}}
  379. {{ .Values.dags.persistence.existingClaim }}
  380. {{- else -}}
  381. {{ .Release.Name }}-dags
  382. {{- end -}}
  383. {{- end -}}
  384. {{ define "airflow_dags_mount" -}}
  385. - name: dags
  386. mountPath: {{ (printf "%s/dags" .Values.airflowHome) }}
  387. {{ if .Values.dags.persistence.subPath -}}
  388. subPath: {{ .Values.dags.persistence.subPath }}
  389. {{- end }}
  390. readOnly: {{ .Values.dags.gitSync.enabled | ternary "True" "False" }}
  391. {{- end -}}
  392. {{ define "airflow_config_path" -}}
  393. {{ (printf "%s/airflow.cfg" .Values.airflowHome) | quote }}
  394. {{- end }}
  395. {{ define "airflow_webserver_config_path" -}}
  396. {{ (printf "%s/webserver_config.py" .Values.airflowHome) | quote }}
  397. {{- end }}
  398. {{ define "airflow_local_setting_path" -}}
  399. {{ (printf "%s/config/airflow_local_settings.py" .Values.airflowHome) | quote }}
  400. {{- end }}
  401. {{ define "airflow_config" -}}
  402. {{ (printf "%s-airflow-config" .Release.Name) }}
  403. {{- end }}
  404. {{/*
  405. Create the name of the webserver service account to use
  406. */}}
  407. {{- define "webserver.serviceAccountName" -}}
  408. {{- if .Values.webserver.serviceAccount.create -}}
  409. {{ default (printf "%s-webserver" (include "airflow.fullname" .)) .Values.webserver.serviceAccount.name }}
  410. {{- else -}}
  411. {{ default "default" .Values.webserver.serviceAccount.name }}
  412. {{- end -}}
  413. {{- end -}}
  414. {{/*
  415. Create the name of the redis service account to use
  416. */}}
  417. {{- define "redis.serviceAccountName" -}}
  418. {{- if .Values.redis.serviceAccount.create -}}
  419. {{ default (printf "%s-redis" (include "airflow.fullname" .)) .Values.redis.serviceAccount.name }}
  420. {{- else -}}
  421. {{ default "default" .Values.redis.serviceAccount.name }}
  422. {{- end -}}
  423. {{- end -}}
  424. {{/*
  425. Create the name of the flower service account to use
  426. */}}
  427. {{- define "flower.serviceAccountName" -}}
  428. {{- if .Values.flower.serviceAccount.create -}}
  429. {{ default (printf "%s-flower" (include "airflow.fullname" .)) .Values.flower.serviceAccount.name }}
  430. {{- else -}}
  431. {{ default "default" .Values.flower.serviceAccount.name }}
  432. {{- end -}}
  433. {{- end -}}
  434. {{/*
  435. Create the name of the scheduler service account to use
  436. */}}
  437. {{- define "scheduler.serviceAccountName" -}}
  438. {{- if .Values.scheduler.serviceAccount.create -}}
  439. {{ default (printf "%s-scheduler" (include "airflow.fullname" .)) .Values.scheduler.serviceAccount.name }}
  440. {{- else -}}
  441. {{ default "default" .Values.scheduler.serviceAccount.name }}
  442. {{- end -}}
  443. {{- end -}}
  444. {{/*
  445. Create the name of the StatsD service account to use
  446. */}}
  447. {{- define "statsd.serviceAccountName" -}}
  448. {{- if .Values.statsd.serviceAccount.create -}}
  449. {{ default (printf "%s-statsd" (include "airflow.fullname" .)) .Values.statsd.serviceAccount.name }}
  450. {{- else -}}
  451. {{ default "default" .Values.statsd.serviceAccount.name }}
  452. {{- end -}}
  453. {{- end -}}
  454. {{/*
  455. Create the name of the create user job service account to use
  456. */}}
  457. {{- define "createUserJob.serviceAccountName" -}}
  458. {{- if .Values.createUserJob.serviceAccount.create -}}
  459. {{ default (printf "%s-create-user-job" (include "airflow.fullname" .)) .Values.createUserJob.serviceAccount.name }}
  460. {{- else -}}
  461. {{ default "default" .Values.createUserJob.serviceAccount.name }}
  462. {{- end -}}
  463. {{- end -}}
  464. {{/*
  465. Create the name of the migrate database job service account to use
  466. */}}
  467. {{- define "migrateDatabaseJob.serviceAccountName" -}}
  468. {{- if .Values.migrateDatabaseJob.serviceAccount.create -}}
  469. {{ default (printf "%s-migrate-database-job" (include "airflow.fullname" .)) .Values.migrateDatabaseJob.serviceAccount.name }}
  470. {{- else -}}
  471. {{ default "default" .Values.migrateDatabaseJob.serviceAccount.name }}
  472. {{- end -}}
  473. {{- end -}}
  474. {{/*
  475. Create the name of the worker service account to use
  476. */}}
  477. {{- define "worker.serviceAccountName" -}}
  478. {{- if .Values.workers.serviceAccount.create -}}
  479. {{ default (printf "%s-worker" (include "airflow.fullname" .)) .Values.workers.serviceAccount.name }}
  480. {{- else -}}
  481. {{ default "default" .Values.workers.serviceAccount.name }}
  482. {{- end -}}
  483. {{- end -}}
  484. {{/*
  485. Create the name of the triggerer service account to use
  486. */}}
  487. {{- define "triggerer.serviceAccountName" -}}
  488. {{- if .Values.triggerer.serviceAccount.create -}}
  489. {{ default (printf "%s-triggerer" (include "airflow.fullname" .)) .Values.triggerer.serviceAccount.name }}
  490. {{- else -}}
  491. {{ default "default" .Values.triggerer.serviceAccount.name }}
  492. {{- end -}}
  493. {{- end -}}
  494. {{/*
  495. Create the name of the pgbouncer service account to use
  496. */}}
  497. {{- define "pgbouncer.serviceAccountName" -}}
  498. {{- if .Values.pgbouncer.serviceAccount.create -}}
  499. {{ default (printf "%s-pgbouncer" (include "airflow.fullname" .)) .Values.pgbouncer.serviceAccount.name }}
  500. {{- else -}}
  501. {{ default "default" .Values.pgbouncer.serviceAccount.name }}
  502. {{- end -}}
  503. {{- end -}}
  504. {{/*
  505. Create the name of the cleanup service account to use
  506. */}}
  507. {{- define "cleanup.serviceAccountName" -}}
  508. {{- if .Values.cleanup.serviceAccount.create -}}
  509. {{ default (printf "%s-cleanup" (include "airflow.fullname" .)) .Values.cleanup.serviceAccount.name }}
  510. {{- else -}}
  511. {{ default "default" .Values.cleanup.serviceAccount.name }}
  512. {{- end -}}
  513. {{- end -}}
  514. {{ define "wait-for-migrations-command" }}
  515. {{- if semverCompare ">=2.0.0" .Values.airflowVersion }}
  516. - airflow
  517. - db
  518. - check-migrations
  519. - --migration-wait-timeout={{ .Values.images.migrationsWaitTimeout }}
  520. {{- else }}
  521. - python
  522. - -c
  523. - |
  524. import airflow
  525. import logging
  526. import os
  527. import time
  528. from alembic.config import Config
  529. from alembic.runtime.migration import MigrationContext
  530. from alembic.script import ScriptDirectory
  531. from airflow import settings
  532. package_dir = os.path.abspath(os.path.dirname(airflow.__file__))
  533. directory = os.path.join(package_dir, 'migrations')
  534. config = Config(os.path.join(package_dir, 'alembic.ini'))
  535. config.set_main_option('script_location', directory)
  536. config.set_main_option('sqlalchemy.url', settings.SQL_ALCHEMY_CONN.replace('%', '%%'))
  537. script_ = ScriptDirectory.from_config(config)
  538. timeout=60
  539. with settings.engine.connect() as connection:
  540. context = MigrationContext.configure(connection)
  541. ticker = 0
  542. while True:
  543. source_heads = set(script_.get_heads())
  544. db_heads = set(context.get_current_heads())
  545. if source_heads == db_heads:
  546. break
  547. if ticker >= timeout:
  548. raise TimeoutError("There are still unapplied migrations after {} seconds.".format(ticker))
  549. ticker += 1
  550. time.sleep(1)
  551. logging.info('Waiting for migrations... %s second(s)', ticker)
  552. {{- end }}
  553. {{- end }}
  554. {{define "scheduler_liveness_check_command"}}
  555. {{- if semverCompare ">=2.0.0" .Values.airflowVersion }}
  556. - sh
  557. - -c
  558. - |
  559. CONNECTION_CHECK_MAX_COUNT=0 AIRFLOW__LOGGING__LOGGING_LEVEL=ERROR exec /entrypoint \
  560. airflow jobs check --job-type SchedulerJob --hostname $(hostname)
  561. {{- else }}
  562. - sh
  563. - -c
  564. - |
  565. CONNECTION_CHECK_MAX_COUNT=0 exec /entrypoint python -Wignore -c "
  566. import os
  567. os.environ['AIRFLOW__CORE__LOGGING_LEVEL'] = 'ERROR'
  568. os.environ['AIRFLOW__LOGGING__LOGGING_LEVEL'] = 'ERROR'
  569. from airflow.jobs.scheduler_job import SchedulerJob
  570. from airflow.utils.db import create_session
  571. from airflow.utils.net import get_hostname
  572. import sys
  573. with create_session() as session:
  574. job = session.query(SchedulerJob).filter_by(hostname=get_hostname()).order_by(
  575. SchedulerJob.latest_heartbeat.desc()).limit(1).first()
  576. sys.exit(0 if job.is_alive() else 1)"
  577. {{- end }}
  578. {{- end }}
  579. {{define "triggerer_liveness_check_command"}}
  580. - sh
  581. - -c
  582. - |
  583. CONNECTION_CHECK_MAX_COUNT=0 AIRFLOW__LOGGING__LOGGING_LEVEL=ERROR exec /entrypoint \
  584. airflow jobs check --job-type TriggererJob --hostname $(hostname)
  585. {{- end }}
  586. {{ define "registry_docker_config" -}}
  587. {{- $host := .Values.registry.connection.host }}
  588. {{- $email := .Values.registry.connection.email }}
  589. {{- $user := .Values.registry.connection.user -}}
  590. {{- $pass := .Values.registry.connection.pass -}}
  591. {{- $config := dict "auths" -}}
  592. {{- $auth := dict -}}
  593. {{- $data := dict -}}
  594. {{- $_ := set $data "username" $user -}}
  595. {{- $_ := set $data "password" $pass -}}
  596. {{- $_ := set $data "email" $email -}}
  597. {{- $_ := set $data "auth" (printf "%v:%v" $user $pass | b64enc) -}}
  598. {{- $_ := set $auth $host $data -}}
  599. {{- $_ := set $config "auths" $auth -}}
  600. {{ $config | toJson | print }}
  601. {{- end }}
  602. {{/* Allow Kubernetes Version to be overridden. Credit to https://github.com/prometheus-community/helm-charts for Regex. */}}
  603. {{- define "kubeVersion" -}}
  604. {{- $kubeVersion := default .Capabilities.KubeVersion.Version .Values.kubeVersionOverride -}}
  605. {{/* Special use case for Amazon EKS, Google GKE */}}
  606. {{- if and (regexMatch "\\d+\\.\\d+\\.\\d+-(?:eks|gke).+" $kubeVersion) (not .Values.kubeVersionOverride) -}}
  607. {{- $kubeVersion = regexFind "\\d+\\.\\d+\\.\\d+" $kubeVersion -}}
  608. {{- end -}}
  609. {{- $kubeVersion -}}
  610. {{- end -}}
  611. {{/*
  612. Set the default value for securityContext
  613. If no value is passed for securityContext or <node>.securityContext, defaults to global uid and gid.
  614. +------------------------+ +-----------------+ +-------------------------+
  615. | <node>.securityContext | -> | securityContext | -> | Values.uid + Values.gid |
  616. +------------------------+ +-----------------+ +-------------------------+
  617. Values are not accumulated meaning that if runAsUser is set to 10 in <node>.securityContext,
  618. any extra values set to securityContext or uid+gid will be ignored.
  619. The template can be called like so:
  620. include "airflowSecurityContext" (list . .Values.webserver)
  621. Where `.` is the global variables scope and `.Values.webserver` the local variables scope for the webserver template.
  622. */}}
  623. {{- define "airflowSecurityContext" -}}
  624. {{- $ := index . 0 -}}
  625. {{- with index . 1 }}
  626. {{- if .securityContext -}}
  627. {{ toYaml .securityContext | print }}
  628. {{- else if $.Values.securityContext -}}
  629. {{ toYaml $.Values.securityContext | print }}
  630. {{- else -}}
  631. runAsUser: {{ $.Values.uid }}
  632. fsGroup: {{ $.Values.gid }}
  633. {{- end -}}
  634. {{- end -}}
  635. {{- end -}}
  636. {{/*
  637. Set the default value for securityContext
  638. If no value is passed for securityContext or <node>.securityContext, defaults to UID in the local node.
  639. +------------------------+ +-------------+
  640. | <node>.securityContext | > | <node>.uid |
  641. +------------------------+ +-------------+
  642. The template can be called like so:
  643. include "localSecurityContext" .Values.statsd
  644. It is important to pass the local variables scope to this template as it is used to determine the local node value for uid.
  645. */}}
  646. {{- define "localSecurityContext" -}}
  647. {{- if .securityContext -}}
  648. {{ toYaml .securityContext | print }}
  649. {{- else -}}
  650. runAsUser: {{ .uid }}
  651. {{- end -}}
  652. {{- end -}}
  653. {{/*
  654. Set the default value for workers chown for persistent storage
  655. If no value is passed for securityContext or <node>.securityContext, defaults to global uid and gid.
  656. The template looks for `runAsUser` and `fsGroup` specifically, any other parameter will be ignored.
  657. +------------------------+ +-----------------+ +-------------------------+
  658. | <node>.securityContext | -> | securityContext | -> | Values.uid + Values.gid |
  659. +------------------------+ +-----------------+ +-------------------------+
  660. Values are not accumulated meaning that if runAsUser is set to 10 in <node>.securityContext,
  661. any extra values set to securityContext or uid+gid will be ignored.
  662. The template can be called like so:
  663. include "airflowSecurityContextIds" (list . .Values.workers)
  664. Where `.` is the global variables scope and `.Values.workers` the local variables scope for the workers template.
  665. */}}
  666. {{- define "airflowSecurityContextIds" -}}
  667. {{- $ := index . 0 -}}
  668. {{- with index . 1 }}
  669. {{- if .securityContext -}}
  670. {{ pluck "runAsUser" .securityContext | first | default $.Values.uid }}:{{ pluck "fsGroup" .securityContext | first | default $.Values.gid }}
  671. {{- else if $.Values.securityContext -}}
  672. {{ pluck "runAsUser" $.Values.securityContext | first | default $.Values.uid }}:{{ pluck "fsGroup" $.Values.securityContext | first | default $.Values.gid }}
  673. {{- else -}}
  674. {{ $.Values.uid }}:{{ $.Values.gid }}
  675. {{- end -}}
  676. {{- end -}}
  677. {{- end -}}