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/03/26 23:47:01 UTC

[airflow] branch master updated: Add more strict Helm Chart schema checks for image pullPolicy & dags accessMode (#15040)

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 28859ca  Add more strict Helm Chart schema checks for image pullPolicy & dags accessMode (#15040)
28859ca is described below

commit 28859ca24c4cde3af196443c6ace404aaed736ae
Author: Xiaodong DENG <xd...@apache.org>
AuthorDate: Sat Mar 27 00:46:42 2021 +0100

    Add more strict Helm Chart schema checks for image pullPolicy & dags accessMode (#15040)
    
    `values.schema.json` can be used to help check the structure & the values in `values.yaml`.
    
    - In this PR I extend the `values.schema.json` to ensure we have more strict checks on the values users add in `values.yaml`.
    - Tests are added.
---
 chart/tests/test_basic_helm_chart.py | 39 ++++++++++++++++++++++++++++++++++++
 chart/values.schema.json             | 27 ++++++++++++++++---------
 2 files changed, 57 insertions(+), 9 deletions(-)

diff --git a/chart/tests/test_basic_helm_chart.py b/chart/tests/test_basic_helm_chart.py
index 031fcf6..36684ee 100644
--- a/chart/tests/test_basic_helm_chart.py
+++ b/chart/tests/test_basic_helm_chart.py
@@ -19,6 +19,7 @@ from subprocess import CalledProcessError
 from typing import Any, Dict, List, Union
 
 import jmespath
+from parameterized import parameterized
 
 from tests.helm_template_generator import render_chart
 
@@ -146,3 +147,41 @@ class TestBaseChartTest(unittest.TestCase):
             'executor must be one of the following: "LocalExecutor", "CeleryExecutor", '
             '"KubernetesExecutor", "CeleryKubernetesExecutor"' in ex_ctx.exception.stderr.decode()
         )
+
+    @parameterized.expand(
+        [
+            ("airflow",),
+            ("pod_template",),
+            ("flower",),
+            ("statsd",),
+            ("redis",),
+            ("pgbouncer",),
+            ("pgbouncerExporter",),
+            ("gitSync",),
+        ]
+    )
+    def test_invalid_pull_policy(self, image):
+        with self.assertRaises(CalledProcessError) as ex_ctx:
+            render_chart(
+                "TEST-BASIC",
+                {
+                    "images": {image: {"pullPolicy": "InvalidPolicy"}},
+                },
+            )
+        assert (
+            'pullPolicy must be one of the following: "Always", "Never", "IfNotPresent"'
+            in ex_ctx.exception.stderr.decode()
+        )
+
+    def test_invalid_dags_access_mode(self):
+        with self.assertRaises(CalledProcessError) as ex_ctx:
+            render_chart(
+                "TEST-BASIC",
+                {
+                    "dags": {"persistence": {"accessMode": "InvalidMode"}},
+                },
+            )
+        assert (
+            'accessMode must be one of the following: "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany"'
+            in ex_ctx.exception.stderr.decode()
+        )
diff --git a/chart/values.schema.json b/chart/values.schema.json
index dd62052..2a41183 100644
--- a/chart/values.schema.json
+++ b/chart/values.schema.json
@@ -192,7 +192,8 @@
                         },
                         "pullPolicy": {
                             "description": "The airflow image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -216,7 +217,8 @@
                         },
                         "pullPolicy": {
                             "description": "The pod_template image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -240,7 +242,8 @@
                         },
                         "pullPolicy": {
                             "description": "The flower image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -258,7 +261,8 @@
                         },
                         "pullPolicy": {
                             "description": "The statsd image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -276,7 +280,8 @@
                         },
                         "pullPolicy": {
                             "description": "The redis image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -294,7 +299,8 @@
                         },
                         "pullPolicy": {
                             "description": "The PgBouncer image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -312,7 +318,8 @@
                         },
                         "pullPolicy": {
                             "description": "The PgBouncer exporter image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 },
@@ -330,7 +337,8 @@
                         },
                         "pullPolicy": {
                             "description": "The gitSync image pull policy.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["Always", "Never", "IfNotPresent"]
                         }
                     }
                 }
@@ -1386,7 +1394,8 @@
                         },
                         "accessMode": {
                             "description": "Access mode of the persistent volume.",
-                            "type": "string"
+                            "type": "string",
+                            "enum": ["ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany"]
                         },
                         "existingClaim": {
                             "description": "The name of an existing PVC to use.",