worker-kedaautoscaler.yaml 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. ## Airflow Worker KEDA Scaler
  19. #################################
  20. {{- if and .Values.workers.keda.enabled (has .Values.executor (list "CeleryExecutor" "CeleryKubernetesExecutor")) }}
  21. apiVersion: keda.sh/v1alpha1
  22. kind: ScaledObject
  23. metadata:
  24. name: {{ .Release.Name }}-worker
  25. labels:
  26. tier: airflow
  27. component: worker-horizontalpodautoscaler
  28. release: {{ .Release.Name }}
  29. chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
  30. heritage: {{ .Release.Service }}
  31. deploymentName: {{ .Release.Name }}-worker
  32. {{- with .Values.labels }}
  33. {{ toYaml . | indent 4 }}
  34. {{- end }}
  35. spec:
  36. scaleTargetRef:
  37. kind: {{ ternary "StatefulSet" "Deployment" .Values.workers.persistence.enabled }}
  38. name: {{ .Release.Name }}-worker
  39. pollingInterval: {{ .Values.workers.keda.pollingInterval }} # Optional. Default: 30 seconds
  40. cooldownPeriod: {{ .Values.workers.keda.cooldownPeriod }} # Optional. Default: 300 seconds
  41. minReplicaCount: {{ .Values.workers.keda.minReplicaCount }} # Optional. Default: 0
  42. maxReplicaCount: {{ .Values.workers.keda.maxReplicaCount }} # Optional. Default: 100
  43. triggers:
  44. - type: postgresql
  45. metadata:
  46. targetQueryValue: "1"
  47. connectionFromEnv: AIRFLOW_CONN_AIRFLOW_DB
  48. query: >-
  49. SELECT ceil(COUNT(*)::decimal / {{ .Values.config.celery.worker_concurrency }})
  50. FROM task_instance
  51. WHERE (state='running' OR state='queued')
  52. {{- if eq .Values.executor "CeleryKubernetesExecutor" }}
  53. AND queue != '{{ .Values.config.celery_kubernetes_executor.kubernetes_queue }}'
  54. {{- end }}
  55. {{- end }}