You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2025/08/24 21:36:10 UTC
(airflow) branch main updated: Fix k8s pod yaml test to expect redacted sensitive data (#54883)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new dac7ce95554 Fix k8s pod yaml test to expect redacted sensitive data (#54883)
dac7ce95554 is described below
commit dac7ce95554d6a6ac5e86b37fc13ffa19a71f1bd
Author: Amogh Desai <am...@gmail.com>
AuthorDate: Mon Aug 25 03:06:03 2025 +0530
Fix k8s pod yaml test to expect redacted sensitive data (#54883)
---
.../cncf/kubernetes/test_template_rendering.py | 60 +++++++++-------------
1 file changed, 25 insertions(+), 35 deletions(-)
diff --git a/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_template_rendering.py b/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_template_rendering.py
index 31a823d34bd..9ed6f585535 100644
--- a/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_template_rendering.py
+++ b/providers/cncf/kubernetes/tests/unit/cncf/kubernetes/test_template_rendering.py
@@ -205,47 +205,37 @@ def test_get_k8s_pod_yaml(render_k8s_pod_yaml, dag_maker, session):
Test that k8s_pod_yaml is rendered correctly, stored in the Database,
and are correctly fetched using RTIF.get_k8s_pod_yaml
"""
- from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS, AIRFLOW_V_3_1_PLUS
+ with dag_maker("test_get_k8s_pod_yaml") as dag:
+ task = BashOperator(task_id="test", bash_command="echo hi")
+ dr = dag_maker.create_dagrun()
+ dag.fileloc = "/test_get_k8s_pod_yaml.py"
- if AIRFLOW_V_3_1_PLUS:
- target = "airflow._shared.secrets_masker.redact"
- elif AIRFLOW_V_3_0_PLUS:
- target = "airflow.sdk.execution_time.secrets_masker.redact"
- else:
- target = "airflow.utils.log.secrets_masker.redact"
- with mock.patch(target, side_effect=lambda item, *args, **kwargs: item) as redact:
- with dag_maker("test_get_k8s_pod_yaml") as dag:
- task = BashOperator(task_id="test", bash_command="echo hi")
- dr = dag_maker.create_dagrun()
- dag.fileloc = "/test_get_k8s_pod_yaml.py"
-
- ti = dr.task_instances[0]
- ti.task = task
+ ti = dr.task_instances[0]
+ ti.task = task
- render_k8s_pod_yaml.return_value = {"I'm a": "pod"}
+ render_k8s_pod_yaml.return_value = {"I'm a": "pod", "secret": "password123"}
- rtif = RTIF(ti=ti)
+ rtif = RTIF(ti=ti)
- assert ti.dag_id == rtif.dag_id
- assert ti.task_id == rtif.task_id
- assert ti.run_id == rtif.run_id
+ assert ti.dag_id == rtif.dag_id
+ assert ti.task_id == rtif.task_id
+ assert ti.run_id == rtif.run_id
- expected_pod_yaml = {"I'm a": "pod"}
+ # Expect redacted version
+ expected_pod_yaml = {"I'm a": "pod", "secret": "***"}
- assert rtif.k8s_pod_yaml == render_k8s_pod_yaml.return_value
- # K8s pod spec dict was passed to redact
- redact.assert_any_call(rtif.k8s_pod_yaml)
+ assert rtif.k8s_pod_yaml == expected_pod_yaml
- with create_session() as session:
- session.add(rtif)
- session.flush()
+ with create_session() as session:
+ session.add(rtif)
+ session.flush()
- assert expected_pod_yaml == RTIF.get_k8s_pod_yaml(ti=ti, session=session)
- make_transient(ti)
- # "Delete" it from the DB
- session.rollback()
+ assert expected_pod_yaml == RTIF.get_k8s_pod_yaml(ti=ti, session=session)
+ make_transient(ti)
+ # "Delete" it from the DB
+ session.rollback()
- # Test the else part of get_k8s_pod_yaml
- # i.e. for the TIs that are not stored in RTIF table
- # Fetching them will return None
- assert RTIF.get_k8s_pod_yaml(ti=ti, session=session) is None
+ # Test the else part of get_k8s_pod_yaml
+ # i.e. for the TIs that are not stored in RTIF table
+ # Fetching them will return None
+ assert RTIF.get_k8s_pod_yaml(ti=ti, session=session) is None