|
29 | 29 |
|
30 | 30 | import pendulum
|
31 | 31 | import pytest
|
| 32 | +from kubernetes import client |
32 | 33 | from kubernetes.client import V1EnvVar, V1PodSecurityContext, V1SecurityContext, models as k8s
|
33 | 34 | from kubernetes.client.api_client import ApiClient
|
34 | 35 | from kubernetes.client.rest import ApiException
|
|
43 | 44 | from airflow.utils.context import Context
|
44 | 45 | from airflow.utils.types import DagRunType
|
45 | 46 | from airflow.version import version as airflow_version
|
| 47 | +from kubernetes_tests.test_base import BaseK8STest |
46 | 48 |
|
47 | 49 | HOOK_CLASS = "airflow.providers.cncf.kubernetes.operators.pod.KubernetesHook"
|
48 | 50 | POD_MANAGER_CLASS = "airflow.providers.cncf.kubernetes.utils.pod_manager.PodManager"
|
@@ -1331,3 +1333,32 @@ def __getattr__(self, name):
|
1331 | 1333 | task.render_template_fields(context=context)
|
1332 | 1334 | assert "password" in caplog.text
|
1333 | 1335 | assert "secretpassword" not in caplog.text
|
| 1336 | + |
| 1337 | + |
| 1338 | +class TestKubernetesPodOperator(BaseK8STest): |
| 1339 | + @pytest.mark.parametrize("active_deadline_seconds", [10, 20]) |
| 1340 | + def test_kubernetes_pod_operator_active_deadline_seconds(self, active_deadline_seconds): |
| 1341 | + k = KubernetesPodOperator( |
| 1342 | + task_id=f"test_task_{active_deadline_seconds}", |
| 1343 | + active_deadline_seconds=active_deadline_seconds, |
| 1344 | + image="busybox", |
| 1345 | + cmds=["sh", "-c", "echo 'hello world' && sleep 60"], |
| 1346 | + namespace="default", |
| 1347 | + on_finish_action="keep_pod", |
| 1348 | + ) |
| 1349 | + |
| 1350 | + context = create_context(k) |
| 1351 | + |
| 1352 | + with pytest.raises(AirflowException): |
| 1353 | + k.execute(context) |
| 1354 | + |
| 1355 | + pod = k.find_pod("default", context, exclude_checked=False) |
| 1356 | + |
| 1357 | + k8s_client = client.CoreV1Api() |
| 1358 | + |
| 1359 | + pod_status = k8s_client.read_namespaced_pod_status(name=pod.metadata.name, namespace="default") |
| 1360 | + phase = pod_status.status.phase |
| 1361 | + reason = pod_status.status.reason |
| 1362 | + |
| 1363 | + assert phase == "Failed" |
| 1364 | + assert reason == "DeadlineExceeded" |
0 commit comments