Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix elasticsearch secret created without elastticsearch enabled #16015

Merged
merged 3 commits into from
May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions chart/templates/check-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
2 changes: 1 addition & 1 deletion chart/templates/secrets/elasticsearch-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
49 changes: 48 additions & 1 deletion chart/tests/test_elasticsearch_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,59 @@

import base64
import unittest
from subprocess import CalledProcessError

import jmespath

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,
Expand All @@ -36,11 +82,12 @@ def test_should_correctly_handle_password_with_special_characters(self):
connection = self._get_connection(
{
"elasticsearch": {
"enabled": True,
"connection": {
"user": "username!@#$%%^&*()",
"pass": "password!@#$%%^&*()",
"host": "elastichostname",
}
},
}
}
)
Expand Down