From e10cdbdf124d4f54a3a6d0c18cbcf8890deb1e7e Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Tue, 21 Sep 2021 10:44:54 +0200 Subject: [PATCH] [elasticsearch] add value to disable service (#1115) (#1339) Signed-off-by: nflaig Co-authored-by: Nico Flaig --- elasticsearch/README.md | 1 + elasticsearch/templates/service.yaml | 2 ++ elasticsearch/tests/elasticsearch_test.py | 17 +++++++++++++++++ elasticsearch/values.yaml | 1 + 4 files changed, 21 insertions(+) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index f12784fe6..b04c410bf 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -161,6 +161,7 @@ support multiple versions with minimal changes. | `secretMounts` | Allows you easily mount a secret as a file inside the StatefulSet. Useful for mounting certificates and other secrets. See [values.yaml][] for an example | `[]` | | `securityContext` | Allows you to set the [securityContext][] for the container | see [values.yaml][] | | `service.annotations` | [LoadBalancer annotations][] that Kubernetes will use for the service. This will configure load balancer if `service.type` is `LoadBalancer` | `{}` | +| `service.enabled` | Enable non-headless service | `true` | | `service.externalTrafficPolicy` | Some cloud providers allow you to specify the [LoadBalancer externalTrafficPolicy][]. Kubernetes will use this to preserve the client source IP. This will configure load balancer if `service.type` is `LoadBalancer` | `""` | | `service.httpPortName` | The name of the http port within the service | `http` | | `service.labelsHeadless` | Labels to be added to headless service | `{}` | diff --git a/elasticsearch/templates/service.yaml b/elasticsearch/templates/service.yaml index ee7ba5c9c..1da695185 100644 --- a/elasticsearch/templates/service.yaml +++ b/elasticsearch/templates/service.yaml @@ -1,4 +1,5 @@ --- +{{- if .Values.service.enabled -}} kind: Service apiVersion: v1 metadata: @@ -43,6 +44,7 @@ spec: {{- if .Values.service.externalTrafficPolicy }} externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} {{- end }} +{{- end }} --- kind: Service apiVersion: v1 diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 638c02066..29ba2a210 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -856,6 +856,23 @@ def test_scheduler_name(): ) +def test_disabling_non_headless_service(): + config = "" + + r = helm_template(config) + + assert uname in r["service"] + + config = """ +service: + enabled: false +""" + + r = helm_template(config) + + assert uname not in r["service"] + + def test_adding_a_nodePort(): config = "" diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 77a87932a..cf3531fc8 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -180,6 +180,7 @@ httpPort: 9200 transportPort: 9300 service: + enabled: true labels: {} labelsHeadless: {} type: ClusterIP