Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
[elasticsearch] #1495 Configure JVM options files (#1496)
Browse files Browse the repository at this point in the history
* [elasticsearch] #1495 Configure JVM options files

* [elasticsearch] #1495 Configure JVM options files
  • Loading branch information
ebuildy authored Dec 16, 2021
1 parent 043800f commit d6adfc1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 1 deletion.
1 change: 1 addition & 0 deletions elasticsearch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ support multiple versions with minimal changes.
| `envFrom` | Templatable string to be passed to the [environment from variables][] which will be appended to the `envFrom:` definition for the container | `[]` |
| `esConfig` | Allows you to add any config files in `/usr/share/elasticsearch/config/` such as `elasticsearch.yml` and `log4j2.properties`. See [values.yaml][] for an example of the formatting | `{}` |
| `esJavaOpts` | [Java options][] for Elasticsearch. This is where you could configure the [jvm heap size][] | `""` |
| `esJvmOptions` | [Java options][] for Elasticsearch. Override the default JVM options by adding custom options files . See [values.yaml][] for an example of the formatting | `{}` |
| `esMajorVersion` | Deprecated. Instead, use the version of the chart corresponding to your ES minor version. Used to set major version specific configuration. If you are using a custom image and not running the default Elasticsearch version you will need to set this to the version you are running (e.g. `esMajorVersion: 6`) | `""` |
| `extraContainers` | Templatable string of additional `containers` to be passed to the `tpl` function | `""` |
| `extraEnvs` | Extra [environment variables][] which will be appended to the `env:` definition for the container | `[]` |
Expand Down
18 changes: 18 additions & 0 deletions elasticsearch/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if .Values.esConfig }}
---
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -14,3 +15,20 @@ data:
{{ $config | indent 4 -}}
{{- end -}}
{{- end -}}
{{- if .Values.esJvmOptions }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "elasticsearch.uname" . }}-jvm-options
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "elasticsearch.uname" . }}"
data:
{{- range $path, $config := .Values.esJvmOptions }}
{{ $path }}: |
{{ $config | indent 4 -}}
{{- end -}}
{{- end -}}
12 changes: 11 additions & 1 deletion elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ spec:
{{ $key }}: {{ $value | quote }}
{{- end }}
{{/* This forces a restart if the configmap has changed */}}
{{- if .Values.esConfig }}
{{- if or .Values.esConfig .Values.esJvmOptions }}
configchecksum: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum | trunc 63 }}
{{- end }}
spec:
Expand Down Expand Up @@ -131,6 +131,11 @@ spec:
configMap:
name: {{ template "elasticsearch.uname" . }}-config
{{- end }}
{{- if .Values.esJvmOptions }}
- name: esjvmoptions
configMap:
name: {{ template "elasticsearch.uname" . }}-jvm-options
{{- end }}
{{- if .Values.keystore }}
- name: keystore
emptyDir: {}
Expand Down Expand Up @@ -357,6 +362,11 @@ spec:
mountPath: /usr/share/elasticsearch/config/{{ $path }}
subPath: {{ $path }}
{{- end -}}
{{- range $path, $config := .Values.esJvmOptions }}
- name: esjvmoptions
mountPath: /usr/share/elasticsearch/config/jvm.options.d/{{ $path }}
subPath: {{ $path }}
{{- end -}}
{{- if .Values.extraVolumeMounts }}
# Currently some extra blocks accept strings
# to continue with backwards compatibility this is being kept
Expand Down
31 changes: 31 additions & 0 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,37 @@ def test_adding_in_es_config():
)


def test_adding_in_jvm_options():
config = """
esJvmOptions:
processors.options: |
-XX:ActiveProcessorCount=3
"""
r = helm_template(config)
c = r["configmap"][uname + "-jvm-options"]["data"]

assert "processors.options" in c

assert "-XX:ActiveProcessorCount=3" in c["processors.options"]

s = r["statefulset"][uname]["spec"]["template"]["spec"]

assert {
"configMap": {"name": "elasticsearch-master-jvm-options"},
"name": "esjvmoptions",
} in s["volumes"]
assert {
"mountPath": "/usr/share/elasticsearch/config/jvm.options.d/processors.options",
"name": "esjvmoptions",
"subPath": "processors.options",
} in s["containers"][0]["volumeMounts"]

assert (
"configchecksum"
in r["statefulset"][uname]["spec"]["template"]["metadata"]["annotations"]
)


def test_dont_add_data_volume_when_persistance_is_disabled():
config = """
persistence:
Expand Down
4 changes: 4 additions & 0 deletions elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ esConfig: {}
# log4j2.properties: |
# key = value

esJvmOptions: {}
# processors.options: |
# -XX:ActiveProcessorCount=3

# Extra environment variables to append to this nodeGroup
# This will be appended to the current 'env:' key. You can use any of the kubernetes env
# syntax here
Expand Down

0 comments on commit d6adfc1

Please sign in to comment.