From 6ddd3e36b066ab7e116b3d2810918dc39223e3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luan=20Guimar=C3=A3es?= Date: Wed, 16 Sep 2020 05:32:21 -0300 Subject: [PATCH] [elasticsearch] add loadBalancer externalTrafficPolicy option (#810) --- elasticsearch/README.md | 2 ++ elasticsearch/templates/service.yaml | 3 +++ elasticsearch/tests/elasticsearch_test.py | 17 +++++++++++++++++ elasticsearch/values.yaml | 1 + 4 files changed, 23 insertions(+) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index 2aa71e355..1fde6db5e 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -157,6 +157,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.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 | `{}` | | `service.labels` | Labels to be added to non-headless service | `{}` | @@ -427,6 +428,7 @@ about our development and testing process. [labels]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ [lifecycle hooks]: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/ [loadBalancer annotations]: https://kubernetes.io/docs/concepts/services-networking/service/#ssl-support-on-aws +[loadBalancer externalTrafficPolicy]: https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip [loadBalancer]: https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer [maxUnavailable]: https://kubernetes.io/docs/tasks/run-application/configure-pdb/#specifying-a-poddisruptionbudget [migration guide]: https://github.com/elastic/helm-charts/tree/master/elasticsearch/examples/migration/README.md diff --git a/elasticsearch/templates/service.yaml b/elasticsearch/templates/service.yaml index 2c8f852f8..ee7ba5c9c 100644 --- a/elasticsearch/templates/service.yaml +++ b/elasticsearch/templates/service.yaml @@ -40,6 +40,9 @@ spec: loadBalancerSourceRanges: {{ toYaml . | indent 4 }} {{- end }} +{{- if .Values.service.externalTrafficPolicy }} + externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} +{{- end }} --- kind: Service apiVersion: v1 diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 5901c76e5..293453dd7 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -815,6 +815,23 @@ def test_adding_a_loadBalancerIP(): assert r["service"][uname]["spec"]["loadBalancerIP"] == "12.4.19.81" +def test_adding_an_externalTrafficPolicy(): + config = "" + + r = helm_template(config) + + assert "externalTrafficPolicy" not in r["service"][uname]["spec"] + + config = """ + service: + externalTrafficPolicy: Local + """ + + r = helm_template(config) + + assert r["service"][uname]["spec"]["externalTrafficPolicy"] == "Local" + + def test_adding_a_label_on_non_headless_service(): config = "" diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 42cefab14..e0fa0295b 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -182,6 +182,7 @@ service: transportPortName: transport loadBalancerIP: "" loadBalancerSourceRanges: [] + externalTrafficPolicy: "" updateStrategy: RollingUpdate