This is an automated email from the ASF dual-hosted git repository.

Miretpl pushed a commit to branch chart/v1-2x-test
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/chart/v1-2x-test by this push:
     new db1bfe15d17 Helm: Scope KEDA_DB_CONN to worker and triggerer pods 
(#70213) (#71982)
db1bfe15d17 is described below

commit db1bfe15d17126305360b4eedad5724c139e08ef
Author: Pranay Yelugam <[email protected]>
AuthorDate: Wed Sep 9 13:49:48 2026 -0700

    Helm: Scope KEDA_DB_CONN to worker and triggerer pods (#70213) (#71982)
    
    (cherry picked from commit b74616b500e64cb0e665d23bbd81f32246e125d0)
    
    Co-authored-by: Przemysław Mirowski 
<[email protected]>
---
 chart/templates/_helpers.yaml                      | 27 ++++++-------
 .../templates/triggerer/triggerer-deployment.yaml  |  3 ++
 chart/templates/workers/worker-deployment.yaml     |  3 ++
 helm-tests/tests/helm_tests/other/test_keda.py     | 44 ++++++++++++++++++++++
 4 files changed, 61 insertions(+), 16 deletions(-)

diff --git a/chart/templates/_helpers.yaml b/chart/templates/_helpers.yaml
index 17bc1803238..807f2f926e9 100644
--- a/chart/templates/_helpers.yaml
+++ b/chart/templates/_helpers.yaml
@@ -84,22 +84,6 @@ If release name contains chart name it will be used as a 
full name.
         name: {{ template "airflow_metadata_secret" . }}
         key: {{ template "airflow_metadata_secret_key" . }}
   {{- end }}
-  {{- $kedaEnabled := .Values.workers.keda.enabled }}
-  {{- $kedaUsePgBouncer := .Values.workers.keda.usePgbouncer }}
-  {{- if hasKey .Values.workers "celery" }}
-    {{- $kedaEnabled = or .Values.workers.celery.keda.enabled (and (not (has 
.Values.workers.celery.keda.enabled (list true false))) 
.Values.workers.keda.enabled) }}
-    {{- $kedaUsePgBouncer = or .Values.workers.celery.keda.usePgbouncer (and 
(not (has .Values.workers.celery.keda.usePgbouncer (list true false))) 
.Values.workers.keda.usePgbouncer) }}
-  {{- end }}
-  {{- $triggererKedaEnabled := and .Values.triggerer.enabled 
.Values.triggerer.keda.enabled }}
-  {{- $workersKedaNeedsDbConn := and $kedaEnabled (or (eq 
.Values.data.metadataConnection.protocol "mysql") (and 
.Values.pgbouncer.enabled (not $kedaUsePgBouncer))) }}
-  {{- $triggererKedaNeedsDbConn := and $triggererKedaEnabled (or (eq 
.Values.data.metadataConnection.protocol "mysql") (and 
.Values.pgbouncer.enabled (not .Values.triggerer.keda.usePgbouncer))) }}
-  {{- if or $workersKedaNeedsDbConn $triggererKedaNeedsDbConn }}
-  - name: KEDA_DB_CONN
-    valueFrom:
-      secretKeyRef:
-        name: {{ template "airflow_metadata_secret" . }}
-        key: kedaConnection
-  {{- end }}
   {{- if and (semverCompare "<3.0.0" .Values.airflowVersion) 
.Values.enableBuiltInSecretEnvVars.AIRFLOW__WEBSERVER__SECRET_KEY }}
   - name: AIRFLOW__WEBSERVER__SECRET_KEY
     valueFrom:
@@ -175,6 +159,17 @@ If release name contains chart name it will be used as a 
full name.
   {{- end }}
 {{- end }}
 
+{{/* KEDA scaler database connection for the worker and triggerer autoscalers 
*/}}
+{{- define "keda_airflow_environment" }}
+  {{- if or (eq .Values.data.metadataConnection.protocol "mysql") (and 
.Values.pgbouncer.enabled (not .UsePgbouncer)) }}
+  - name: KEDA_DB_CONN
+    valueFrom:
+      secretKeyRef:
+        name: {{ template "airflow_metadata_secret" . }}
+        key: kedaConnection
+  {{- end }}
+{{- end }}
+
 {{/* User defined Airflow environment variables */}}
 {{- define "custom_airflow_environment" }}
   # Dynamically created environment variables
diff --git a/chart/templates/triggerer/triggerer-deployment.yaml 
b/chart/templates/triggerer/triggerer-deployment.yaml
index cc557191f25..80f510f834a 100644
--- a/chart/templates/triggerer/triggerer-deployment.yaml
+++ b/chart/templates/triggerer/triggerer-deployment.yaml
@@ -213,6 +213,9 @@ spec:
           env:
             {{- include "custom_airflow_environment" . | indent 10 }}
             {{- include "standard_airflow_environment" . | indent 10 }}
+            {{- if $keda }}
+            {{- include "keda_airflow_environment" (merge (dict "UsePgbouncer" 
.Values.triggerer.keda.usePgbouncer) .) | indent 10 }}
+            {{- end }}
             {{- include "container_extra_envs" (list . .Values.triggerer.env) 
| nindent 10 }}
           livenessProbe:
             initialDelaySeconds: {{ 
.Values.triggerer.livenessProbe.initialDelaySeconds }}
diff --git a/chart/templates/workers/worker-deployment.yaml 
b/chart/templates/workers/worker-deployment.yaml
index 5c49888b1df..2ae69c0b012 100644
--- a/chart/templates/workers/worker-deployment.yaml
+++ b/chart/templates/workers/worker-deployment.yaml
@@ -351,6 +351,9 @@ spec:
               value: "0"
             {{- include "custom_airflow_environment" . | indent 10 }}
             {{- include "standard_airflow_environment" . | indent 10 }}
+            {{- if $keda }}
+            {{- include "keda_airflow_environment" (merge (dict "UsePgbouncer" 
.Values.workers.keda.usePgbouncer) .) | indent 10 }}
+            {{- end }}
             {{- include "container_extra_envs" (list . .Values.workers.env) | 
indent 10 }}
             {{- if .Values.workers.kerberosSidecar.enabled }}
             - name: KRB5_CONFIG
diff --git a/helm-tests/tests/helm_tests/other/test_keda.py 
b/helm-tests/tests/helm_tests/other/test_keda.py
index 1d0b9e4191e..0d1f0ef49bd 100644
--- a/helm-tests/tests/helm_tests/other/test_keda.py
+++ b/helm-tests/tests/helm_tests/other/test_keda.py
@@ -540,3 +540,47 @@ class TestKeda:
         )
 
         assert jmespath.search("spec.maxReplicaCount", docs[0]) == 5
+
+    @staticmethod
+    def _env_names(doc):
+        return jmespath.search("spec.template.spec.containers[].env[].name", 
doc) or []
+
+    def test_worker_keda_db_conn_not_leaked_to_other_components(self):
+        docs = render_chart(
+            values={
+                "workers": {"celery": {"keda": {"enabled": True, 
"usePgbouncer": False}}},
+                "executor": "CeleryExecutor",
+                "pgbouncer": {"enabled": True},
+            },
+            show_only=[
+                "templates/workers/worker-deployment.yaml",
+                "templates/scheduler/scheduler-deployment.yaml",
+                "templates/api-server/api-server-deployment.yaml",
+                "templates/dag-processor/dag-processor-deployment.yaml",
+                "templates/triggerer/triggerer-deployment.yaml",
+            ],
+        )
+        worker, scheduler, api_server, dag_processor, triggerer = docs
+        assert "KEDA_DB_CONN" in self._env_names(worker)
+        assert "KEDA_DB_CONN" not in self._env_names(scheduler)
+        assert "KEDA_DB_CONN" not in self._env_names(api_server)
+        assert "KEDA_DB_CONN" not in self._env_names(dag_processor)
+        assert "KEDA_DB_CONN" not in self._env_names(triggerer)
+
+    def test_triggerer_keda_db_conn_not_leaked_to_other_components(self):
+        docs = render_chart(
+            values={
+                "triggerer": {"keda": {"enabled": True, "usePgbouncer": 
False}},
+                "executor": "CeleryExecutor",
+                "pgbouncer": {"enabled": True},
+            },
+            show_only=[
+                "templates/triggerer/triggerer-deployment.yaml",
+                "templates/workers/worker-deployment.yaml",
+                "templates/scheduler/scheduler-deployment.yaml",
+            ],
+        )
+        triggerer, worker, scheduler = docs
+        assert "KEDA_DB_CONN" in self._env_names(triggerer)
+        assert "KEDA_DB_CONN" not in self._env_names(worker)
+        assert "KEDA_DB_CONN" not in self._env_names(scheduler)

Reply via email to