You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by di...@apache.org on 2020/06/17 18:53:40 UTC
[airflow] branch v1-10-test updated: Fix KubernetesPodOperator pod
name length validation (#8829)
This is an automated email from the ASF dual-hosted git repository.
dimberman pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v1-10-test by this push:
new 5e16a12 Fix KubernetesPodOperator pod name length validation (#8829)
5e16a12 is described below
commit 5e16a12b7794ee076338b8789146ea674cc2d15c
Author: Daniel Saiz <ds...@gmail.com>
AuthorDate: Fri May 15 17:41:52 2020 +0200
Fix KubernetesPodOperator pod name length validation (#8829)
* Fix KubernetesPodOperator pod name length validation
* Add test, verify Exception is raised
(cherry picked from commit f82ad452b0f4ebd1428bc9669641a632dc87bb8c)
---
airflow/contrib/operators/kubernetes_pod_operator.py | 7 ++++---
kubernetes_tests/test_kubernetes_pod_operator.py | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/airflow/contrib/operators/kubernetes_pod_operator.py b/airflow/contrib/operators/kubernetes_pod_operator.py
index bfe128d..5d7dddc 100644
--- a/airflow/contrib/operators/kubernetes_pod_operator.py
+++ b/airflow/contrib/operators/kubernetes_pod_operator.py
@@ -42,8 +42,9 @@ class KubernetesPodOperator(BaseOperator): # pylint: disable=too-many-instance-
:param image: Docker image you wish to launch. Defaults to hub.docker.com,
but fully qualified URLS will point to custom repositories.
:type image: str
- :param namespace: the namespace to run within kubernetes.
- :type namespace: str
+ :param name: name of the pod in which the task will run, will be used (plus a random
+ suffix) to generate a pod id (DNS-1123 subdomain, containing only [a-z0-9.-]).
+ :type name: str
:param cmds: entrypoint of the container. (templated)
The docker images's entrypoint is used if this is not provided.
:type cmds: list[str]
@@ -201,7 +202,7 @@ class KubernetesPodOperator(BaseOperator): # pylint: disable=too-many-instance-
return [Resources(**resources) if resources else Resources()]
def _set_name(self, name):
- validate_key(name, max_length=63)
+ validate_key(name, max_length=220)
return re.sub(r'[^a-z0-9.-]+', '-', name.lower())
@apply_defaults
diff --git a/kubernetes_tests/test_kubernetes_pod_operator.py b/kubernetes_tests/test_kubernetes_pod_operator.py
index 360add1..814318f 100644
--- a/kubernetes_tests/test_kubernetes_pod_operator.py
+++ b/kubernetes_tests/test_kubernetes_pod_operator.py
@@ -735,3 +735,21 @@ class TestKubernetesPodOperatorSystem(unittest.TestCase):
actual_pod = self.api_client.sanitize_for_serialization(k.pod)
self.expected_pod['spec']['priorityClassName'] = priority_class_name
self.assertEqual(self.expected_pod, actual_pod)
+
+ def test_pod_name(self):
+ pod_name_too_long = "a" * 221
+ with self.assertRaises(AirflowException):
+ KubernetesPodOperator(
+ namespace='default',
+ image="ubuntu:16.04",
+ cmds=["bash", "-cx"],
+ arguments=["echo 10"],
+ labels={"foo": "bar"},
+ name=pod_name_too_long,
+ task_id="task",
+ in_cluster=False,
+ do_xcom_push=False,
+ )
+
+
+# pylint: enable=unused-argument