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/11/11 17:26:09 UTC

[airflow] branch master updated: Fix indentation for affinities in helm chart (#12288)

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

dimberman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new cbe4ef2  Fix indentation for affinities in helm chart (#12288)
cbe4ef2 is described below

commit cbe4ef2c5e143c87c9edd1c54a4949bbdd7a8edd
Author: Daniel Imberman <da...@gmail.com>
AuthorDate: Wed Nov 11 09:23:20 2020 -0800

    Fix indentation for affinities in helm chart (#12288)
    
    This PR fixes a bug in the helm chart where custom affinities in
    the pod_template_file cause the yaml to fail due to invalid spacing
---
 chart/files/pod-template-file.kubernetes-helm-yaml |  9 ++--
 chart/tests/test_pod_template_file.py              | 51 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/chart/files/pod-template-file.kubernetes-helm-yaml b/chart/files/pod-template-file.kubernetes-helm-yaml
index 8647060..b4ec9a5 100644
--- a/chart/files/pod-template-file.kubernetes-helm-yaml
+++ b/chart/files/pod-template-file.kubernetes-helm-yaml
@@ -66,12 +66,9 @@ spec:
   restartPolicy: Never
   securityContext:
     runAsUser: {{ .Values.uid }}
-  nodeSelector:
-    {{ toYaml .Values.nodeSelector | indent 8 }}
-  affinity:
-    {{ toYaml .Values.affinity | indent 8 }}
-  tolerations:
-    {{ toYaml .Values.tolerations | indent 8 }}
+  nodeSelector: {{ toYaml .Values.nodeSelector | nindent 4 }}
+  affinity: {{ toYaml .Values.affinity | nindent 4 }}
+  tolerations: {{ toYaml .Values.tolerations | nindent 4 }}
   serviceAccountName: '{{ .Release.Name }}-worker'
   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 d9334de..3c61733 100644
--- a/chart/tests/test_pod_template_file.py
+++ b/chart/tests/test_pod_template_file.py
@@ -184,3 +184,54 @@ class PodTemplateFileTest(unittest.TestCase):
         self.assertRegex(docs[0]["kind"], "Pod")
         self.assertEqual("dummy_image:latest", jmespath.search("spec.containers[0].image", docs[0]))
         self.assertEqual("base", jmespath.search("spec.containers[0].name", docs[0]))
+
+    def test_should_create_valid_affinity_and_node_selector(self):
+        docs = render_chart(
+            values={
+                "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"],
+        )
+
+        self.assertRegex(docs[0]["kind"], "Pod")
+        self.assertEqual(
+            "foo",
+            jmespath.search(
+                "spec.affinity.nodeAffinity."
+                "requiredDuringSchedulingIgnoredDuringExecution."
+                "nodeSelectorTerms[0]."
+                "matchExpressions[0]."
+                "key",
+                docs[0],
+            ),
+        )
+        self.assertEqual(
+            "ssd",
+            jmespath.search(
+                "spec.nodeSelector.diskType",
+                docs[0],
+            ),
+        )
+        self.assertEqual(
+            "dynamic-pods",
+            jmespath.search(
+                "spec.tolerations[0].key",
+                docs[0],
+            ),
+        )