You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ka...@apache.org on 2021/01/08 22:44:52 UTC

[airflow] branch master updated: Fix image and add airflow config for cleanup pods (#13576)

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

kaxilnaik 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 77e0106  Fix image and add airflow config for cleanup pods (#13576)
77e0106 is described below

commit 77e010670f3f0ffc9094d665a5f6010798a4122a
Author: Jun <Ju...@users.noreply.github.com>
AuthorDate: Sat Jan 9 06:44:35 2021 +0800

    Fix image and add airflow config for cleanup pods (#13576)
---
 chart/templates/cleanup/cleanup-cronjob.yaml | 11 ++++-
 chart/tests/test_cleanup_pods.py             | 68 ++++++++++++++++++++++++++++
 2 files changed, 78 insertions(+), 1 deletion(-)

diff --git a/chart/templates/cleanup/cleanup-cronjob.yaml b/chart/templates/cleanup/cleanup-cronjob.yaml
index a2b1d0d..4bfc10e 100644
--- a/chart/templates/cleanup/cleanup-cronjob.yaml
+++ b/chart/templates/cleanup/cleanup-cronjob.yaml
@@ -61,10 +61,19 @@ spec:
           {{- end }}
           containers:
             - name: airflow-cleanup-pods
-              image: {{ template "default_airflow_image" . }}
+              image: {{ template "airflow_image" . }}
               imagePullPolicy: {{ .Values.images.airflow.pullPolicy }}
               # Don't use entry point here, we don't need to wait on pg-bouncer etc being available.
               args: ["kubernetes", "cleanup-pods", "--namespace={{ .Release.Namespace }}"]
               env:
               {{- include "standard_airflow_environment" . | indent 12 }}
+              volumeMounts:
+                - name: config
+                  mountPath: {{ template "airflow_config_path" . }}
+                  subPath: airflow.cfg
+                  readOnly: true
+          volumes:
+            - name: config
+              configMap:
+                name: {{ template "airflow_config" . }}
 {{- end }}
diff --git a/chart/tests/test_cleanup_pods.py b/chart/tests/test_cleanup_pods.py
new file mode 100644
index 0000000..df2b3a0
--- /dev/null
+++ b/chart/tests/test_cleanup_pods.py
@@ -0,0 +1,68 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import unittest
+
+import jmespath
+
+from tests.helm_template_generator import render_chart
+
+
+class CleanupPodsTest(unittest.TestCase):
+    def test_should_create_cronjob_for_enabled_cleanup(self):
+        docs = render_chart(
+            values={
+                "cleanup": {"enabled": True},
+            },
+            show_only=["templates/cleanup/cleanup-cronjob.yaml"],
+        )
+
+        self.assertEqual(
+            "airflow-cleanup-pods",
+            jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].name", docs[0]),
+        )
+        self.assertEqual(
+            "apache/airflow:2.0.0",
+            jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].image", docs[0]),
+        )
+        self.assertIn(
+            {"name": "config", "configMap": {"name": "RELEASE-NAME-airflow-config"}},
+            jmespath.search("spec.jobTemplate.spec.template.spec.volumes", docs[0]),
+        )
+        self.assertIn(
+            {
+                "name": "config",
+                "mountPath": "/opt/airflow/airflow.cfg",
+                "subPath": "airflow.cfg",
+                "readOnly": True,
+            },
+            jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].volumeMounts", docs[0]),
+        )
+
+    def test_should_change_image_when_set_airflow_image(self):
+        docs = render_chart(
+            values={
+                "cleanup": {"enabled": True},
+                "images": {"airflow": {"repository": "airflow", "tag": "test"}},
+            },
+            show_only=["templates/cleanup/cleanup-cronjob.yaml"],
+        )
+
+        self.assertEqual(
+            "airflow:test",
+            jmespath.search("spec.jobTemplate.spec.template.spec.containers[0].image", docs[0]),
+        )