From 85204a1b46a9aacf6ed85fd0ef8460d14f128656 Mon Sep 17 00:00:00 2001 From: Usama Ahmad Date: Tue, 29 Oct 2019 10:50:14 +0500 Subject: [PATCH 1/3] add support for labels for services --- elasticsearch/templates/service.yaml | 6 ++++++ elasticsearch/values.yaml | 2 ++ 2 files changed, 8 insertions(+) diff --git a/elasticsearch/templates/service.yaml b/elasticsearch/templates/service.yaml index 0a89edb80..898894cf2 100644 --- a/elasticsearch/templates/service.yaml +++ b/elasticsearch/templates/service.yaml @@ -8,6 +8,9 @@ metadata: release: {{ .Release.Name | quote }} chart: "{{ .Chart.Name }}" app: "{{ template "uname" . }}" +{{- if .Values.service.labels }} +{{ toYaml .Values.service.labels | indent 4}} +{{- end }} annotations: {{ toYaml .Values.service.annotations | indent 4 }} spec: @@ -37,6 +40,9 @@ metadata: release: {{ .Release.Name | quote }} chart: "{{ .Chart.Name }}" app: "{{ template "uname" . }}" +{{- if .Values.service.labelsHeadless }} +{{ toYaml .Values.service.labelsHeadless | indent 4 }} +{{- end }} annotations: service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" spec: diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 72bf2b47c..76f5024bb 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -151,6 +151,8 @@ httpPort: 9200 transportPort: 9300 service: + labels: {} + labelsHeadless: {} type: ClusterIP nodePort: "" annotations: {} From 4eea54c47654d511c914d6f4782c1d628bbaf84c Mon Sep 17 00:00:00 2001 From: Usama Ahmad Date: Tue, 29 Oct 2019 11:43:47 +0500 Subject: [PATCH 2/3] update readme --- elasticsearch/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index cfc2a01a3..1e28aed85 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -89,7 +89,9 @@ helm install --name elasticsearch elastic/elasticsearch --set imageTag=7.4.1 | `podManagementPolicy` | By default Kubernetes [deploys statefulsets serially](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#pod-management-policies). This deploys them in parallel so that they can discover eachother | `Parallel` | | `protocol` | The protocol that will be used for the readinessProbe. Change this to `https` if you have `xpack.security.http.ssl.enabled` set | `http` | | `httpPort` | The http port that Kubernetes will use for the healthchecks and the service. If you change this you will also need to set [http.port](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html#_settings) in `extraEnvs` | `9200` | -| `transportPort` | The transport port that Kubernetes will use for the service. If you change this you will also need to set [transport port configuration](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-transport.html#_transport_settings) in `extraEnvs` | `9300` | +| `transportPort` | The transport port that Kubernetes will use for the service. If you change this you will also need to set [transport port configuration](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-transport.html#_transport_settings) in `extraEnvs` | `9300` | +| `service.labels` | Labels to be added to non-headless service | `{}` | +| `service.labelsHeadless` | Labels to be added to headless service | `{}` | | `service.type` | Type of elasticsearch service. [Service Types](https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types) | `ClusterIP` | | `service.nodePort` | Custom [nodePort](https://kubernetes.io/docs/concepts/services-networking/service/#nodeport) port that can be set if you are using `service.type: nodePort`. | `` | | `service.annotations` | Annotations that Kubernetes will use for the service. This will configure load balancer if `service.type` is `LoadBalancer` [Annotations](https://kubernetes.io/docs/concepts/services-networking/service/#ssl-support-on-aws) | `{}` | From a9ca08687a80d6b197b9ce9451c1c4df8a150dc7 Mon Sep 17 00:00:00 2001 From: Usama Ahmad Date: Tue, 29 Oct 2019 11:43:56 +0500 Subject: [PATCH 3/3] add tests --- elasticsearch/tests/elasticsearch_test.py | 37 +++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 4517c9fc7..4a83deaf5 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -659,6 +659,43 @@ def test_adding_a_nodePort(): assert r['service'][uname]['spec']['ports'][0]['nodePort'] == 30001 + +def test_adding_a_label_on_non_headless_service(): + config = '' + + r = helm_template(config) + + assert 'label1' not in r['service'][uname]['metadata']['labels'] + + config = ''' + service: + labels: + label1: value1 + ''' + + r = helm_template(config) + + assert r['service'][uname]['metadata']['labels']['label1'] == 'value1' + + + +def test_adding_a_label_on_headless_service(): + config = '' + + r = helm_template(config) + + assert 'label1' not in r['service'][uname + '-headless']['metadata']['labels'] + + config = ''' + service: + labelsHeadless: + label1: value1 + ''' + + r = helm_template(config) + + assert r['service'][uname + '-headless']['metadata']['labels']['label1'] == 'value1' + def test_master_termination_fixed_enabled(): config = ''