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 31375bb  Chart: Fix Elasticsearch secret created without Elasticsearch 
enabled (#16015)
31375bb is described below

commit 31375bbeda608319fdf1408b97c9d2f4f1820480
Author: Kamil BreguĊ‚a <[email protected]>
AuthorDate: Mon May 24 14:04:21 2021 +0200

    Chart: Fix Elasticsearch secret created without Elasticsearch enabled 
(#16015)
    
    * Fix elasticsearch secret created without elastticsearch enabled
    
    * Update chart/templates/check-values.yaml
    
    Co-authored-by: Kaxil Naik <[email protected]>
    
    * fixup! Update chart/templates/check-values.yaml
    
    Co-authored-by: Kaxil Naik <[email protected]>
---
 chart/templates/check-values.yaml                 | 11 +++++
 chart/templates/secrets/elasticsearch-secret.yaml |  2 +-
 chart/tests/test_elasticsearch_secret.py          | 49 ++++++++++++++++++++++-
 3 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/chart/templates/check-values.yaml 
b/chart/templates/check-values.yaml
index 01a764a..81fb809 100644
--- a/chart/templates/check-values.yaml
+++ b/chart/templates/check-values.yaml
@@ -49,3 +49,14 @@ The sole purpose of this yaml file is it to check the values 
file is consistent
     {{- end }}
 
   {{- end }}
+
+  {{- if .Values.elasticsearch.enabled  }}
+    {{- if and .Values.elasticsearch.secretName 
.Values.elasticsearch.connection }}
+      {{ required "You must not set both values elasticsearch.secretName and 
elasticsearch.connection" nil }}
+    {{- end }}
+
+    {{- if not (or .Values.elasticsearch.secretName 
.Values.elasticsearch.connection) }}
+      {{ required "You must set one of the values elasticsearch.secretName or 
elasticsearch.connection when using a Elasticsearch" nil }}
+    {{- end }}
+
+  {{- end }}
diff --git a/chart/templates/secrets/elasticsearch-secret.yaml 
b/chart/templates/secrets/elasticsearch-secret.yaml
index b220ab5..0e35b8b 100644
--- a/chart/templates/secrets/elasticsearch-secret.yaml
+++ b/chart/templates/secrets/elasticsearch-secret.yaml
@@ -18,7 +18,7 @@
 ################################
 ## Elasticsearch Secret
 #################################
-{{- if (and .Values.elasticsearch.connection (not 
.Values.elasticsearch.secretName)) }}
+{{- if (and .Values.elasticsearch.enabled (not 
.Values.elasticsearch.secretName)) }}
 kind: Secret
 apiVersion: v1
 metadata:
diff --git a/chart/tests/test_elasticsearch_secret.py 
b/chart/tests/test_elasticsearch_secret.py
index 9d2c2b9..69b4b4c 100644
--- a/chart/tests/test_elasticsearch_secret.py
+++ b/chart/tests/test_elasticsearch_secret.py
@@ -17,6 +17,7 @@
 
 import base64
 import unittest
+from subprocess import CalledProcessError
 
 import jmespath
 
@@ -24,6 +25,51 @@ from tests.helm_template_generator import render_chart
 
 
 class ElasticsearchSecretTest(unittest.TestCase):
+    def test_should_not_generate_a_document_if_elasticsearch_disabled(self):
+
+        docs = render_chart(
+            values={"elasticsearch": {"enabled": False}},
+            show_only=["templates/secrets/elasticsearch-secret.yaml"],
+        )
+
+        assert 0 == len(docs)
+
+    def test_should_raise_error_when_connection_not_provided(self):
+        with self.assertRaises(CalledProcessError) as ex_ctx:
+            render_chart(
+                values={
+                    "elasticsearch": {
+                        "enabled": True,
+                    }
+                },
+                show_only=["templates/secrets/elasticsearch-secret.yaml"],
+            )
+        assert (
+            "You must set one of the values elasticsearch.secretName or 
elasticsearch.connection "
+            "when using a Elasticsearch" in ex_ctx.exception.stderr.decode()
+        )
+
+    def test_should_raise_error_when_conflicting_options(self):
+        with self.assertRaises(CalledProcessError) as ex_ctx:
+            render_chart(
+                values={
+                    "elasticsearch": {
+                        "enabled": True,
+                        "secretName": "my-test",
+                        "connection": {
+                            "user": "username!@#$%%^&*()",
+                            "pass": "password!@#$%%^&*()",
+                            "host": "elastichostname",
+                        },
+                    },
+                },
+                show_only=["templates/secrets/elasticsearch-secret.yaml"],
+            )
+        assert (
+            "You must not set both values elasticsearch.secretName and 
elasticsearch.connection"
+            in ex_ctx.exception.stderr.decode()
+        )
+
     def _get_connection(self, values: dict) -> str:
         docs = render_chart(
             values=values,
@@ -36,11 +82,12 @@ class ElasticsearchSecretTest(unittest.TestCase):
         connection = self._get_connection(
             {
                 "elasticsearch": {
+                    "enabled": True,
                     "connection": {
                         "user": "username!@#$%%^&*()",
                         "pass": "password!@#$%%^&*()",
                         "host": "elastichostname",
-                    }
+                    },
                 }
             }
         )

Reply via email to