This is an automated email from the ASF dual-hosted git repository.
uranusjr 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 45f4290712 Rename 'resources' arg in Kub op to k8s_resources (#24673)
45f4290712 is described below
commit 45f4290712f5f779e57034f81dbaab5d77d5de85
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Tue Jun 28 14:45:31 2022 +0800
Rename 'resources' arg in Kub op to k8s_resources (#24673)
---
.../cncf/kubernetes/operators/kubernetes_pod.py | 20 ++++++++++++++++----
kubernetes_tests/test_kubernetes_pod_operator.py | 2 +-
.../test_kubernetes_pod_operator_backcompat.py | 2 +-
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
index 07435436ce..1966b6bdb1 100644
--- a/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
+++ b/airflow/providers/cncf/kubernetes/operators/kubernetes_pod.py
@@ -112,7 +112,7 @@ class KubernetesPodOperator(BaseOperator):
:param annotations: non-identifying metadata you can attach to the Pod.
Can be a large range of data, and can include characters
that are not permitted by labels.
- :param resources: resources for the launched pod.
+ :param container_resources: resources for the launched pod.
:param affinity: affinity scheduling rules for the launched pod.
:param config_file: The path to the Kubernetes config file. (templated)
If not specified, default value is ``~/.kube/config``
@@ -188,7 +188,7 @@ class KubernetesPodOperator(BaseOperator):
get_logs: bool = True,
image_pull_policy: Optional[str] = None,
annotations: Optional[Dict] = None,
- resources: Optional[k8s.V1ResourceRequirements] = None,
+ container_resources: Optional[k8s.V1ResourceRequirements] = None,
affinity: Optional[k8s.V1Affinity] = None,
config_file: Optional[str] = None,
node_selectors: Optional[dict] = None,
@@ -210,11 +210,23 @@ class KubernetesPodOperator(BaseOperator):
pod_runtime_info_envs: Optional[List[k8s.V1EnvVar]] = None,
termination_grace_period: Optional[int] = None,
configmaps: Optional[List[str]] = None,
+ resources: Optional[Dict[str, Any]] = None,
**kwargs,
) -> None:
if kwargs.get('xcom_push') is not None:
raise AirflowException("'xcom_push' was deprecated, use
'do_xcom_push' instead")
- super().__init__(resources=None, **kwargs)
+
+ if isinstance(resources, k8s.V1ResourceRequirements):
+ warnings.warn(
+ "Specifying resources for the launched pod with 'resources' is
deprecated. "
+ "Use 'container_resources' instead.",
+ category=DeprecationWarning,
+ stacklevel=2,
+ )
+ container_resources = resources
+ resources = None
+
+ super().__init__(resources=resources, **kwargs)
self.kubernetes_conn_id = kubernetes_conn_id
self.do_xcom_push = do_xcom_push
self.image = image
@@ -250,7 +262,7 @@ class KubernetesPodOperator(BaseOperator):
self.node_selector = {}
self.annotations = annotations or {}
self.affinity = convert_affinity(affinity) if affinity else {}
- self.k8s_resources = convert_resources(resources) if resources else {}
+ self.k8s_resources = convert_resources(container_resources) if
container_resources else {}
self.config_file = config_file
self.image_pull_secrets =
convert_image_pull_secrets(image_pull_secrets) if image_pull_secrets else []
self.service_account_name = service_account_name
diff --git a/kubernetes_tests/test_kubernetes_pod_operator.py
b/kubernetes_tests/test_kubernetes_pod_operator.py
index da615b3790..fb661e46b0 100644
--- a/kubernetes_tests/test_kubernetes_pod_operator.py
+++ b/kubernetes_tests/test_kubernetes_pod_operator.py
@@ -362,7 +362,7 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
task_id="task" + self.get_current_task_name(),
in_cluster=False,
do_xcom_push=False,
- resources=resources,
+ container_resources=resources,
)
context = create_context(k)
k.execute(context)
diff --git a/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
b/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
index 5a4efc73d4..f15400edea 100644
--- a/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
+++ b/kubernetes_tests/test_kubernetes_pod_operator_backcompat.py
@@ -211,7 +211,7 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
task_id="task",
in_cluster=False,
do_xcom_push=False,
- resources=resources,
+ container_resources=resources,
)
context = create_context(k)
k.execute(context)