This is an automated email from the ASF dual-hosted git repository.

kaxilnaik 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 6d3c6f6  Chart: Apply worker's node assigning settings to Pod Template 
File (#16663)
6d3c6f6 is described below

commit 6d3c6f665a7027da9abe6ef15fcf5593d6eb5377
Author: Kaxil Naik <[email protected]>
AuthorDate: Fri Jun 25 23:40:24 2021 +0100

    Chart: Apply worker's node assigning settings to Pod Template File (#16663)
    
    Since we treat Kubernetes Task Pod as worker when using KubernetesExecutor 
or CeleryKubernetesExecutor, we should allow overriding `.Values.nodeSelector` 
by `.Values.workers.nodeSelector` for Pod template file too.
    
    This is consistent with how we assign `serviceAccountName`, `VolumeMounts` 
etc
---
 chart/files/pod-template-file.kubernetes-helm-yaml |  9 +++--
 chart/tests/test_pod_template_file.py              | 46 ++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/chart/files/pod-template-file.kubernetes-helm-yaml 
b/chart/files/pod-template-file.kubernetes-helm-yaml
index 9ac4599..b3c1a41 100644
--- a/chart/files/pod-template-file.kubernetes-helm-yaml
+++ b/chart/files/pod-template-file.kubernetes-helm-yaml
@@ -15,6 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 ---
+{{- $nodeSelector := or .Values.nodeSelector .Values.workers.nodeSelector }}
+{{- $affinity := or .Values.affinity .Values.workers.affinity }}
+{{- $tolerations := or .Values.tolerations .Values.workers.tolerations }}
 apiVersion: v1
 kind: Pod
 metadata:
@@ -84,9 +87,9 @@ spec:
   securityContext:
     runAsUser: {{ .Values.uid }}
     fsGroup: {{ .Values.gid }}
-  nodeSelector: {{ toYaml .Values.nodeSelector | nindent 4 }}
-  affinity: {{ toYaml .Values.affinity | nindent 4 }}
-  tolerations: {{ toYaml .Values.tolerations | nindent 4 }}
+  nodeSelector: {{ toYaml $nodeSelector | nindent 4 }}
+  affinity: {{ toYaml $affinity | nindent 4 }}
+  tolerations: {{ toYaml $tolerations | nindent 4 }}
   serviceAccountName: {{ include "worker.serviceAccountName" . }}
   volumes:
   {{- if .Values.dags.persistence.enabled }}
diff --git a/chart/tests/test_pod_template_file.py 
b/chart/tests/test_pod_template_file.py
index e2233a4..161d6a2 100644
--- a/chart/tests/test_pod_template_file.py
+++ b/chart/tests/test_pod_template_file.py
@@ -486,3 +486,49 @@ class PodTemplateFileTest(unittest.TestCase):
             chart_dir=self.temp_chart_dir,
         )
         assert {} == jmespath.search("spec.containers[0].resources", docs[0])
+
+    def test_should_create_valid_affinity_tolerations_and_node_selector(self):
+        docs = render_chart(
+            values={
+                "executor": "KubernetesExecutor",
+                "workers": {
+                    "affinity": {
+                        "nodeAffinity": {
+                            "requiredDuringSchedulingIgnoredDuringExecution": {
+                                "nodeSelectorTerms": [
+                                    {
+                                        "matchExpressions": [
+                                            {"key": "foo", "operator": "In", 
"values": ["true"]},
+                                        ]
+                                    }
+                                ]
+                            }
+                        }
+                    },
+                    "tolerations": [
+                        {"key": "dynamic-pods", "operator": "Equal", "value": 
"true", "effect": "NoSchedule"}
+                    ],
+                    "nodeSelector": {"diskType": "ssd"},
+                },
+            },
+            show_only=["templates/pod-template-file.yaml"],
+            chart_dir=self.temp_chart_dir,
+        )
+
+        assert "Pod" == jmespath.search("kind", docs[0])
+        assert "foo" == jmespath.search(
+            "spec.affinity.nodeAffinity."
+            "requiredDuringSchedulingIgnoredDuringExecution."
+            "nodeSelectorTerms[0]."
+            "matchExpressions[0]."
+            "key",
+            docs[0],
+        )
+        assert "ssd" == jmespath.search(
+            "spec.nodeSelector.diskType",
+            docs[0],
+        )
+        assert "dynamic-pods" == jmespath.search(
+            "spec.tolerations[0].key",
+            docs[0],
+        )

Reply via email to