From 383dd6a2d39a31eedd72cbc630c4ffb495b521bc Mon Sep 17 00:00:00 2001 From: Dom Goodwin Date: Mon, 16 Mar 2020 18:10:12 +0000 Subject: [PATCH 1/4] Update defaults for extra values to support lists --- elasticsearch/templates/statefulset.yaml | 8 ++++---- elasticsearch/values.yaml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index 31a6cec02..bc77ab19b 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -128,7 +128,7 @@ spec: {{- end }} {{ end }} {{- if .Values.extraVolumes }} -{{ tpl .Values.extraVolumes . | indent 8 }} +{{ toYaml .Values.extraVolumes | indent 8 }} {{- end }} {{- if .Values.imagePullSecrets }} imagePullSecrets: @@ -183,7 +183,7 @@ spec: {{- end }} {{ end }} {{- if .Values.extraInitContainers }} -{{ tpl .Values.extraInitContainers . | indent 6 }} +{{ toYaml .Values.extraInitContainers | indent 6 }} {{- end }} containers: - name: "{{ template "elasticsearch.name" . }}" @@ -290,7 +290,7 @@ spec: subPath: {{ $path }} {{- end -}} {{- if .Values.extraVolumeMounts }} -{{ tpl .Values.extraVolumeMounts . | indent 10 }} +{{ toYaml .Values.extraVolumeMounts | indent 10 }} {{- end }} {{- if .Values.masterTerminationFix }} {{- if eq .Values.roles.master "true" }} @@ -351,5 +351,5 @@ spec: {{ toYaml .Values.lifecycle | indent 10 }} {{- end }} {{- if .Values.extraContainers }} -{{ tpl .Values.extraContainers . | indent 6 }} +{{ toYaml .Values.extraContainers | indent 6 }} {{- end }} diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml index 053c02093..8ad990ee5 100755 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -112,21 +112,21 @@ persistence: enabled: true annotations: {} -extraVolumes: "" +extraVolumes: [] # - name: extras # emptyDir: {} -extraVolumeMounts: "" +extraVolumeMounts: [] # - name: extras # mountPath: /usr/share/extras # readOnly: true -extraContainers: "" +extraContainers: [] # - name: do-something # image: busybox # command: ['do', 'something'] -extraInitContainers: "" +extraInitContainers: [] # - name: do-something # image: busybox # command: ['do', 'something'] From c2896e546c361c5fd791c1da7f77422548e5ce68 Mon Sep 17 00:00:00 2001 From: Dom Goodwin Date: Mon, 20 Apr 2020 17:27:06 +0100 Subject: [PATCH 2/4] Added ability for string or yaml for extra* templates --- elasticsearch/templates/statefulset.yaml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index bc77ab19b..120d0073c 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -128,7 +128,11 @@ spec: {{- end }} {{ end }} {{- if .Values.extraVolumes }} + {{- if eq "string" (printf "%T" .Values.extraVolumes) }} +{{ tpl .Values.extraVolumes . | indent 8 }} + {{- else }} {{ toYaml .Values.extraVolumes | indent 8 }} + {{- end }} {{- end }} {{- if .Values.imagePullSecrets }} imagePullSecrets: @@ -183,7 +187,11 @@ spec: {{- end }} {{ end }} {{- if .Values.extraInitContainers }} -{{ toYaml .Values.extraInitContainers | indent 6 }} + {{- if eq "string" (printf "%T" .Values.extraInitContainers) }} +{{ tpl .Values.extraInitContainers . | indent 8 }} + {{- else }} +{{ toYaml .Values.extraInitContainers | indent 8 }} + {{- end }} {{- end }} containers: - name: "{{ template "elasticsearch.name" . }}" @@ -290,8 +298,12 @@ spec: subPath: {{ $path }} {{- end -}} {{- if .Values.extraVolumeMounts }} + {{- if eq "string" (printf "%T" .Values.extraVolumeMounts) }} +{{ tpl .Values.extraVolumeMounts . | indent 10 }} + {{- else }} {{ toYaml .Values.extraVolumeMounts | indent 10 }} {{- end }} + {{- end }} {{- if .Values.masterTerminationFix }} {{- if eq .Values.roles.master "true" }} # This sidecar will prevent slow master re-election @@ -351,5 +363,9 @@ spec: {{ toYaml .Values.lifecycle | indent 10 }} {{- end }} {{- if .Values.extraContainers }} + {{- if eq "string" (printf "%T" .Values.extraContainers) }} +{{ tpl .Values.extraContainers . | indent 6 }} + {{- else }} {{ toYaml .Values.extraContainers | indent 6 }} {{- end }} + {{- end }} From ef7025c57efd067d33f7ab1e8fda1c3b627bd811 Mon Sep 17 00:00:00 2001 From: Dom Goodwin Date: Tue, 21 Apr 2020 10:06:38 +0100 Subject: [PATCH 3/4] Updated tests to test both string and yaml --- elasticsearch/README.md | 8 ++-- elasticsearch/templates/statefulset.yaml | 16 ++++++- elasticsearch/tests/elasticsearch_test.py | 52 +++++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/elasticsearch/README.md b/elasticsearch/README.md index 6b380b57f..3b58343bf 100644 --- a/elasticsearch/README.md +++ b/elasticsearch/README.md @@ -99,10 +99,10 @@ helm install --name elasticsearch elastic/elasticsearch --set imageTag=7.6.2 | `esMajorVersion` | 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`) | `""` | | `esConfig` | Allows you to add any config files in `/usr/share/elasticsearch/config/` such as `elasticsearch.yml` and `log4j2.properties`. See [values.yaml](https://github.com/elastic/helm-charts/tree/master/elasticsearch/values.yaml) for an example of the formatting. | `{}` | | `extraEnvs` | Extra [environment variables](https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/#using-environment-variables-inside-of-your-config) which will be appended to the `env:` definition for the container | `[]` | -| `extraVolumes` | Templatable string of additional volumes to be passed to the `tpl` function | `""` | -| `extraVolumeMounts` | Templatable string of additional volumeMounts to be passed to the `tpl` function | `""` | -| `extraContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` | -| `extraInitContainers` | Templatable string of additional init containers to be passed to the `tpl` function | `""` | +| `extraVolumes` | Templatable string of additional volumes to be passed to the `tpl` function | `[]` | +| `extraVolumeMounts` | Templatable string of additional volumeMounts to be passed to the `tpl` function | `[]` | +| `extraContainers` | Templatable string of additional containers to be passed to the `tpl` function | `[]` | +| `extraInitContainers` | Templatable string of additional init containers to be passed to the `tpl` function | `[]` | | `secretMounts` | Allows you easily mount a secret as a file inside the statefulset. Useful for mounting certificates and other secrets. See [values.yaml](https://github.com/elastic/helm-charts/tree/master/elasticsearch/values.yaml) for an example | `[]` | | `image` | The Elasticsearch docker image | `docker.elastic.co/elasticsearch/elasticsearch` | | `imageTag` | The Elasticsearch docker image tag | `7.6.2` | diff --git a/elasticsearch/templates/statefulset.yaml b/elasticsearch/templates/statefulset.yaml index 120d0073c..0f6524c5d 100644 --- a/elasticsearch/templates/statefulset.yaml +++ b/elasticsearch/templates/statefulset.yaml @@ -128,6 +128,9 @@ spec: {{- end }} {{ end }} {{- if .Values.extraVolumes }} + # Currently some extra blocks accept strings + # to continue with backwards compatibility this is being kept + # whilst also allowing for yaml to be specified too. {{- if eq "string" (printf "%T" .Values.extraVolumes) }} {{ tpl .Values.extraVolumes . | indent 8 }} {{- else }} @@ -187,10 +190,13 @@ spec: {{- end }} {{ end }} {{- if .Values.extraInitContainers }} + # Currently some extra blocks accept strings + # to continue with backwards compatibility this is being kept + # whilst also allowing for yaml to be specified too. {{- if eq "string" (printf "%T" .Values.extraInitContainers) }} -{{ tpl .Values.extraInitContainers . | indent 8 }} +{{ tpl .Values.extraInitContainers . | indent 6 }} {{- else }} -{{ toYaml .Values.extraInitContainers | indent 8 }} +{{ toYaml .Values.extraInitContainers | indent 6 }} {{- end }} {{- end }} containers: @@ -298,6 +304,9 @@ spec: subPath: {{ $path }} {{- end -}} {{- if .Values.extraVolumeMounts }} + # Currently some extra blocks accept strings + # to continue with backwards compatibility this is being kept + # whilst also allowing for yaml to be specified too. {{- if eq "string" (printf "%T" .Values.extraVolumeMounts) }} {{ tpl .Values.extraVolumeMounts . | indent 10 }} {{- else }} @@ -363,6 +372,9 @@ spec: {{ toYaml .Values.lifecycle | indent 10 }} {{- end }} {{- if .Values.extraContainers }} + # Currently some extra blocks accept strings + # to continue with backwards compatibility this is being kept + # whilst also allowing for yaml to be specified too. {{- if eq "string" (printf "%T" .Values.extraContainers) }} {{ tpl .Values.extraContainers . | indent 6 }} {{- else }} diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 16d05c79f..80537dda9 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -306,6 +306,28 @@ def test_adding_a_extra_volume_with_volume_mount(): "readOnly": True, } in extraVolumeMounts +def test_adding_a_extra_volume_with_volume_mount_as_yaml(): + config = """ +extraVolumes: + - name: extras + emptyDir: {} +extraVolumeMounts: + - name: extras + mountPath: /usr/share/extras + readOnly: true +""" + r = helm_template(config) + extraVolume = r["statefulset"][uname]["spec"]["template"]["spec"]["volumes"] + assert {"name": "extras", "emptyDir": {}} in extraVolume + extraVolumeMounts = r["statefulset"][uname]["spec"]["template"]["spec"][ + "containers" + ][0]["volumeMounts"] + assert { + "name": "extras", + "mountPath": "/usr/share/extras", + "readOnly": True, + } in extraVolumeMounts + def test_adding_a_extra_container(): config = """ @@ -322,6 +344,20 @@ def test_adding_a_extra_container(): "command": ["do", "something"], } in extraContainer +def test_adding_a_extra_container_as_yaml(): + config = """ +extraContainers: + - name: do-something + image: busybox + command: ['do', 'something'] +""" + r = helm_template(config) + extraContainer = r["statefulset"][uname]["spec"]["template"]["spec"]["containers"] + assert { + "name": "do-something", + "image": "busybox", + "command": ["do", "something"], + } in extraContainer def test_adding_a_extra_init_container(): config = """ @@ -340,6 +376,22 @@ def test_adding_a_extra_init_container(): "command": ["do", "something"], } in extraInitContainer +def test_adding_a_extra_init_container_as_yaml(): + config = """ +extraInitContainers: + - name: do-something + image: busybox + command: ['do', 'something'] +""" + r = helm_template(config) + extraInitContainer = r["statefulset"][uname]["spec"]["template"]["spec"][ + "initContainers" + ] + assert { + "name": "do-something", + "image": "busybox", + "command": ["do", "something"], + } in extraInitContainer def test_sysctl_init_container_disabled(): config = """ From 252f270a8cb0ef2e39947b3eb46421237cb8825c Mon Sep 17 00:00:00 2001 From: Dom Goodwin Date: Tue, 21 Apr 2020 11:01:08 +0100 Subject: [PATCH 4/4] Fix linting errors --- elasticsearch/tests/elasticsearch_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 80537dda9..02ad5da00 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -306,6 +306,7 @@ def test_adding_a_extra_volume_with_volume_mount(): "readOnly": True, } in extraVolumeMounts + def test_adding_a_extra_volume_with_volume_mount_as_yaml(): config = """ extraVolumes: @@ -344,6 +345,7 @@ def test_adding_a_extra_container(): "command": ["do", "something"], } in extraContainer + def test_adding_a_extra_container_as_yaml(): config = """ extraContainers: @@ -359,6 +361,7 @@ def test_adding_a_extra_container_as_yaml(): "command": ["do", "something"], } in extraContainer + def test_adding_a_extra_init_container(): config = """ extraInitContainers: | @@ -376,6 +379,7 @@ def test_adding_a_extra_init_container(): "command": ["do", "something"], } in extraInitContainer + def test_adding_a_extra_init_container_as_yaml(): config = """ extraInitContainers: @@ -393,6 +397,7 @@ def test_adding_a_extra_init_container_as_yaml(): "command": ["do", "something"], } in extraInitContainer + def test_sysctl_init_container_disabled(): config = """ sysctlInitContainer: