From 0626843a31bacc7954561b26cca7b413e951cb9f Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Tue, 25 May 2021 17:04:13 +0200 Subject: [PATCH] [elasticsearch] use new node.roles settings (#1186) * [elasticsearch] use new node.roles settings This commit update Elasticsearch chart to use the new node.roles settings introduced in elastic/elasticsearch#54998. * [elasticsearch] update doc * [elasticsearch] update examples * add link to roles doc * add workaround for coordinating node * update roles list * fixup! update roles list * remove data_frozen from default roles this is needed because `data_frozen` role doesn't exist in Elasticsearch < 7.12.0 * fixup! remove data_frozen from default roles --- elasticsearch/README.md | 26 +++++++++++++++++--- elasticsearch/examples/migration/client.yaml | 8 ++---- elasticsearch/examples/migration/data.yaml | 5 +--- elasticsearch/examples/migration/master.yaml | 7 ++---- elasticsearch/examples/multi/client.yaml | 14 +++++------ elasticsearch/examples/multi/data.yaml | 13 +++++----- elasticsearch/examples/multi/master.yaml | 7 +----- elasticsearch/examples/security/values.yaml | 6 ++--- elasticsearch/templates/_helpers.tpl | 6 +++++ elasticsearch/templates/statefulset.yaml | 13 +++------- elasticsearch/tests/elasticsearch_test.py | 24 ++++++------------ elasticsearch/values.yaml | 18 +++++++++----- 12 files changed, 74 insertions(+), 73 deletions(-) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index 35138ca54..d9c278b2a 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -154,7 +154,7 @@ support multiple versions with minimal changes. | `readinessProbe` | Configuration fields for the readiness [probe][] | see [values.yaml][] | | `replicas` | Kubernetes replica count for the StatefulSet (i.e. how many pods) | `3` | | `resources` | Allows you to set the [resources][] for the StatefulSet | see [values.yaml][] | -| `roles` | A hash map with the specific [roles][] for the `nodeGroup` | see [values.yaml][] | +| `roles` | A list with the specific [roles][] for the `nodeGroup` | see [values.yaml][] | | `schedulerName` | Name of the [alternate scheduler][] | `""` | | `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][] | @@ -212,8 +212,27 @@ while they share the same `clusterName` value. For each Helm release, the nodes types can then be defined using `roles` value. -An example of Elasticsearch cluster using 2 different Helm releases for master -and data nodes can be found in [examples/multi][]. +An example of Elasticsearch cluster using 2 different Helm releases for master, +data and coordinating nodes can be found in [examples/multi][]. + +#### Coordinating nodes + +Every node is implicitly a coordinating node. This means that a node that has an +explicit empty list of roles will only act as a coordinating node. + +When deploying coordinating-only node with Elasticsearch chart, it is required +to define the empty list of roles in both `roles` value and `node.roles` +settings: + +```yaml +roles: [] + +esConfig: + elasticsearch.yml: | + node.roles: [] +``` + +More details in [#1186 (comment)][] #### Clustering and Node Discovery @@ -380,6 +399,7 @@ about our development and testing process. [7.x]: https://github.com/elastic/helm-charts/releases [#63]: https://github.com/elastic/helm-charts/issues/63 +[#1186 (comment)]: https://github.com/elastic/helm-charts/pull/1186#discussion_r631166442 [7.9.2]: https://github.com/elastic/helm-charts/blob/7.9.2/elasticsearch/README.md [BREAKING_CHANGES.md]: https://github.com/elastic/helm-charts/blob/master/BREAKING_CHANGES.md [CHANGELOG.md]: https://github.com/elastic/helm-charts/blob/master/CHANGELOG.md diff --git a/elasticsearch/examples/migration/client.yaml b/elasticsearch/examples/migration/client.yaml index 30ee700e3..8ac0641ce 100644 --- a/elasticsearch/examples/migration/client.yaml +++ b/elasticsearch/examples/migration/client.yaml @@ -1,5 +1,4 @@ --- - replicas: 2 clusterName: "elasticsearch" @@ -7,13 +6,10 @@ nodeGroup: "client" esMajorVersion: 6 -roles: - master: "false" - ingest: "false" - data: "false" +roles: [] volumeClaimTemplate: - accessModes: [ "ReadWriteOnce" ] + accessModes: ["ReadWriteOnce"] storageClassName: "standard" resources: requests: diff --git a/elasticsearch/examples/migration/data.yaml b/elasticsearch/examples/migration/data.yaml index eedcbb063..012569d09 100644 --- a/elasticsearch/examples/migration/data.yaml +++ b/elasticsearch/examples/migration/data.yaml @@ -1,5 +1,4 @@ --- - replicas: 2 esMajorVersion: 6 @@ -12,6 +11,4 @@ clusterName: "elasticsearch" nodeGroup: "data" roles: - master: "false" - ingest: "false" - data: "true" + - data diff --git a/elasticsearch/examples/migration/master.yaml b/elasticsearch/examples/migration/master.yaml index 3e3a2f172..9f2f609a3 100644 --- a/elasticsearch/examples/migration/master.yaml +++ b/elasticsearch/examples/migration/master.yaml @@ -1,5 +1,4 @@ --- - # Temporarily set to 3 so we can scale up/down the old a new cluster # one at a time whilst always keeping 3 masters running replicas: 1 @@ -14,12 +13,10 @@ clusterName: "elasticsearch" nodeGroup: "master" roles: - master: "true" - ingest: "false" - data: "false" + - master volumeClaimTemplate: - accessModes: [ "ReadWriteOnce" ] + accessModes: ["ReadWriteOnce"] storageClassName: "standard" resources: requests: diff --git a/elasticsearch/examples/multi/client.yaml b/elasticsearch/examples/multi/client.yaml index dbe5b05aa..9ebfbcc11 100644 --- a/elasticsearch/examples/multi/client.yaml +++ b/elasticsearch/examples/multi/client.yaml @@ -1,14 +1,14 @@ --- - clusterName: "multi" nodeGroup: "client" -roles: - master: "false" - ingest: "false" - data: "false" - ml: "false" - remote_cluster_client: "false" +roles: [] persistence: enabled: false + +# For client nodes, we also need to add an empty node.roles in elasticsearch.yml +# This is due to https://github.com/elastic/helm-charts/pull/1186#discussion_r631225687 +esConfig: + elasticsearch.yml: | + node.roles: [] diff --git a/elasticsearch/examples/multi/data.yaml b/elasticsearch/examples/multi/data.yaml index 2e3a90935..16e10f78d 100644 --- a/elasticsearch/examples/multi/data.yaml +++ b/elasticsearch/examples/multi/data.yaml @@ -1,11 +1,12 @@ --- - clusterName: "multi" nodeGroup: "data" roles: - master: "false" - ingest: "true" - data: "true" - ml: "false" - remote_cluster_client: "false" + - data + - data_content + - data_hot + - data_warm + - data_cold + - data_frozen + - ingest diff --git a/elasticsearch/examples/multi/master.yaml b/elasticsearch/examples/multi/master.yaml index 6b8c08293..bb4ea303b 100644 --- a/elasticsearch/examples/multi/master.yaml +++ b/elasticsearch/examples/multi/master.yaml @@ -1,11 +1,6 @@ --- - clusterName: "multi" nodeGroup: "master" roles: - master: "true" - ingest: "false" - data: "false" - ml: "false" - remote_cluster_client: "false" + - master diff --git a/elasticsearch/examples/security/values.yaml b/elasticsearch/examples/security/values.yaml index 04d932caa..4a6f0cdd9 100644 --- a/elasticsearch/examples/security/values.yaml +++ b/elasticsearch/examples/security/values.yaml @@ -3,9 +3,9 @@ clusterName: "security" nodeGroup: "master" roles: - master: "true" - ingest: "true" - data: "true" + - master + - ingest + - data protocol: https diff --git a/elasticsearch/templates/_helpers.tpl b/elasticsearch/templates/_helpers.tpl index 91a15535a..070296673 100755 --- a/elasticsearch/templates/_helpers.tpl +++ b/elasticsearch/templates/_helpers.tpl @@ -51,6 +51,12 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- end -}} {{- end -}} +{{- define "elasticsearch.roles" -}} +{{- range $.Values.roles -}} +{{ . }}, +{{- end -}} +{{- end -}} + {{- define "elasticsearch.esMajorVersion" -}} {{- if .Values.esMajorVersion -}} {{ .Values.esMajorVersion }} diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index e3a34c513..1e8c5d1c4 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -295,15 +295,12 @@ spec: valueFrom: fieldRef: fieldPath: metadata.name - {{- if eq .Values.roles.master "true" }} - {{- if ge (int (include "elasticsearch.esMajorVersion" .)) 7 }} + {{- if has "master" .Values.roles }} - name: cluster.initial_master_nodes value: "{{ template "elasticsearch.endpoints" . }}" - {{- else }} - - name: discovery.zen.minimum_master_nodes - value: "{{ .Values.minimumMasterNodes }}" - {{- end }} {{- end }} + - name: node.roles + value: "{{ template "elasticsearch.roles" . }}" {{- if lt (int (include "elasticsearch.esMajorVersion" .)) 7 }} - name: discovery.zen.ping.unicast.hosts value: "{{ template "elasticsearch.masterService" . }}-headless" @@ -319,10 +316,6 @@ spec: - name: ES_JAVA_OPTS value: "{{ .Values.esJavaOpts }}" {{- end }} - {{- range $role, $enabled := .Values.roles }} - - name: node.{{ $role }} - value: "{{ $enabled }}" - {{- end }} {{- if .Values.extraEnvs }} {{ toYaml .Values.extraEnvs | indent 10 }} {{- end }} diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 9dd457f34..32bef1e82 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -45,9 +45,10 @@ def test_defaults(): {"name": "discovery.seed_hosts", "value": uname + "-headless"}, {"name": "network.host", "value": "0.0.0.0"}, {"name": "cluster.name", "value": clusterName}, - {"name": "node.master", "value": "true"}, - {"name": "node.data", "value": "true"}, - {"name": "node.ingest", "value": "true"}, + { + "name": "node.roles", + "value": "master,data,data_content,data_hot,data_warm,data_cold,ingest,ml,remote_cluster_client,transform,", + }, ] c = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0] @@ -174,7 +175,7 @@ def test_overriding_the_image_and_tag(): def test_set_initial_master_nodes(): config = """ roles: - master: "true" + - master """ r = helm_template(config) env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"] @@ -192,7 +193,7 @@ def test_set_initial_master_nodes(): def test_dont_set_initial_master_nodes_if_not_master(): config = """ roles: - master: "false" + - data """ r = helm_template(config) env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"] @@ -203,7 +204,7 @@ def test_dont_set_initial_master_nodes_if_not_master(): def test_set_discovery_seed_host(): config = """ roles: - master: "true" + - master """ r = helm_template(config) env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"] @@ -216,17 +217,6 @@ def test_set_discovery_seed_host(): assert e["name"] != "discovery.zen.ping.unicast.hosts" -def test_enabling_machine_learning_role(): - config = """ -roles: - ml: "true" -""" - r = helm_template(config) - env = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"][0]["env"] - - assert {"name": "node.ml", "value": "true"} in env - - def test_adding_extra_env_vars(): config = """ extraEnvs: diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index c9d9b6b5a..4bb6850db 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -7,13 +7,19 @@ nodeGroup: "master" masterService: "" # Elasticsearch roles that will be applied to this nodeGroup -# These will be set as environment variables. E.g. node.master=true +# These will be set as environment variables. E.g. node.roles=master +# https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#node-roles roles: - master: "true" - ingest: "true" - data: "true" - remote_cluster_client: "true" - ml: "true" + - master + - data + - data_content + - data_hot + - data_warm + - data_cold + - ingest + - ml + - remote_cluster_client + - transform replicas: 3 minimumMasterNodes: 2