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 9f1b66f Fixes issue with affinity backcompat in Airflow 1.10 9f1b66f is described below commit 9f1b66f9e7cd250f28e1763ad95a99eb049fe3d8 Author: Daniel Imberman <daniel.imber...@gmail.com> AuthorDate: Thu Nov 19 10:29:59 2020 -0800 Fixes issue with affinity backcompat in Airflow 1.10 There was a breaking change in 1.10.12 where the affinity argument was being turned into a k8s.V1Affinity object instead of a python dict. This commit solves https://github.com/apache/airflow/issues/11731 --- airflow/kubernetes/pod_launcher.py | 2 +- tests/kubernetes/test_pod_launcher.py | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/airflow/kubernetes/pod_launcher.py b/airflow/kubernetes/pod_launcher.py index 704a77e..468e077 100644 --- a/airflow/kubernetes/pod_launcher.py +++ b/airflow/kubernetes/pod_launcher.py @@ -326,7 +326,7 @@ def _convert_to_airflow_pod(pod): resources=base_container.resources, service_account_name=pod.spec.service_account_name, secrets=secrets, - affinity=pod.spec.affinity, + affinity=api_client.sanitize_for_serialization(pod.spec.affinity), hostnetwork=pod.spec.host_network, security_context=_extract_security_context(pod.spec.security_context) ) diff --git a/tests/kubernetes/test_pod_launcher.py b/tests/kubernetes/test_pod_launcher.py index 63169ae..00198fe 100644 --- a/tests/kubernetes/test_pod_launcher.py +++ b/tests/kubernetes/test_pod_launcher.py @@ -175,9 +175,26 @@ class TestPodLauncherHelper(unittest.TestCase): input_pod = k8s.V1Pod( metadata=k8s.V1ObjectMeta( name="foo", - namespace="bar" + namespace="bar", + annotations={"foo": "bar"} ), spec=k8s.V1PodSpec( + affinity=k8s.V1Affinity( + pod_anti_affinity=k8s.V1PodAntiAffinity( + required_during_scheduling_ignored_during_execution=[ + k8s.V1WeightedPodAffinityTerm( + weight=1, + pod_affinity_term=k8s.V1PodAffinityTerm( + label_selector=k8s.V1LabelSelector( + match_expressions=[ + k8s.V1LabelSelectorRequirement(key="security", operator="In", values="S1") + ] + ), + topology_key="failure-domain.beta.kubernetes.io/zone", + ), + ) + ] + )), init_containers=[ k8s.V1Container( name="init-container", @@ -256,9 +273,12 @@ class TestPodLauncherHelper(unittest.TestCase): ) result_pod = _convert_to_airflow_pod(input_pod) + self.assertEqual(type(result_pod.affinity), dict) + expected = Pod( name="foo", namespace="bar", + annotations={"foo": "bar"}, envs={}, init_containers=[ {'name': 'init-container', 'volumeMounts': [{'mountPath': '/tmp', 'name': 'init-secret'}]} @@ -288,6 +308,14 @@ class TestPodLauncherHelper(unittest.TestCase): read_only=True )], image_pull_secrets="my-secret", + affinity={'podAntiAffinity': + {'requiredDuringSchedulingIgnoredDuringExecution': + [{'podAffinityTerm': + {'labelSelector': + {'matchExpressions': + [{'key': 'security', 'operator': 'In', 'values': 'S1'}]}, + 'topologyKey': 'failure-domain.beta.kubernetes.io/zone'}, + 'weight': 1}]}}, secrets=[Secret("env", "AIRFLOW_SECRET", "ai", "secret_key")], security_context={'fsGroup': 0, 'runAsUser': 0}, volumes=[Volume(name="myvolume", configs={'name': 'myvolume'}), @@ -295,8 +323,8 @@ class TestPodLauncherHelper(unittest.TestCase): 'name': 'airflow-config'}), Volume(name='airflow-secret', configs={'name': 'airflow-secret', 'secret': {'secretName': 'secret-name'}}), - Volume(name='init-secret', configs={'name': 'init-secret', 'secret': - {'secretName': 'init-secret'}})], + Volume(name='init-secret', configs={'name': 'init-secret', + 'secret': {'secretName': 'init-secret'}})], ) expected_dict = expected.as_dict() result_dict = result_pod.as_dict()