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

Commit

Permalink
allow array values for extra (elastic#1450)
Browse files Browse the repository at this point in the history
* allow array values for extra

* add some tests

* fixup! add some tests

Co-authored-by: jmlrt <8582351+jmlrt@users.noreply.github.com>
  • Loading branch information
dmarcs and jmlrt committed Mar 1, 2022
1 parent c0a715e commit 2b09fdb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 8 deletions.
8 changes: 4 additions & 4 deletions logstash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ useful for the [http input plugin][], for instance.
| `antiAffinityTopologyKey` | The [anti-affinity][] topology key]. By default this will prevent multiple Logstash nodes from running on the same Kubernetes node | `kubernetes.io/hostname` |
| `antiAffinity` | Setting this to hard enforces the [anti-affinity][] rules. If it is set to soft it will be done "best effort". Other values will be ignored | `hard` |
| `envFrom` | Templatable string to be passed to the [environment from variables][] which will be appended to the `envFrom:` definition for the container | `[]` |
| `extraContainers` | Templatable string of additional containers to be passed to the `tpl` function | `""` |
| `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 | `[]` |
| `extraInitContainers` | Templatable string of additional `initContainers` to be passed to the `tpl` function | `""` |
| `extraInitContainers` | Templatable string of additional `initContainers` to be passed to the `tpl` function | `[]` |
| `extraPorts` | An array of extra ports to open on the pod | `[]` |
| `extraVolumeMounts` | Templatable string of additional `volumeMounts` 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 | `[]` |
| `extraVolumes` | Templatable string of additional `volumes` to be passed to the `tpl` function | `[]` |
| `fullnameOverride` | Overrides the full name of the resources. If not set the name will default to " `.Release.Name` - `.Values.nameOverride or .Chart.Name` " | `""` |
| `hostAliases` | Configurable [hostAliases][] | `[]` |
| `httpPort` | The http port that Kubernetes will use for the healthchecks and the service | `9600` |
Expand Down
16 changes: 16 additions & 0 deletions logstash/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ spec:
name: {{ template "logstash.fullname" . }}-pattern
{{- 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:
Expand All @@ -149,7 +153,11 @@ spec:
{{- end }}
{{- if .Values.extraInitContainers }}
initContainers:
{{- if eq "string" (printf "%T" .Values.extraInitContainers) }}
{{ tpl .Values.extraInitContainers . | indent 6 }}
{{- else }}
{{ toYaml .Values.extraInitContainers | indent 6 }}
{{- end }}
{{- end }}
containers:
- name: "{{ template "logstash.name" . }}"
Expand Down Expand Up @@ -210,12 +218,20 @@ spec:
{{- end -}}
{{- 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.lifecycle }}
lifecycle:
{{ 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 }}
57 changes: 57 additions & 0 deletions logstash/tests/logstash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,29 @@ def test_adding_a_extra_volume_with_volume_mount():
} 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"][name]["spec"]["template"]["spec"]["volumes"]
assert {"name": "extras", "emptyDir": {}} in extraVolume
extraVolumeMounts = r["statefulset"][name]["spec"]["template"]["spec"][
"containers"
][0]["volumeMounts"]
assert {
"name": "extras",
"mountPath": "/usr/share/extras",
"readOnly": True,
} in extraVolumeMounts


def test_adding_a_extra_container():
config = """
extraContainers: |
Expand All @@ -194,6 +217,22 @@ def test_adding_a_extra_container():
} 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"][name]["spec"]["template"]["spec"]["containers"]
assert {
"name": "do-something",
"image": "busybox",
"command": ["do", "something"],
} in extraContainer


def test_adding_a_extra_port():
config = """
extraPorts:
Expand Down Expand Up @@ -225,6 +264,24 @@ def test_adding_a_extra_init_container():
} 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"][name]["spec"]["template"]["spec"][
"initContainers"
]
assert {
"name": "do-something",
"image": "busybox",
"command": ["do", "something"],
} in extraInitContainer


def test_adding_persistence():
config = """
persistence:
Expand Down
8 changes: 4 additions & 4 deletions logstash/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,24 @@ persistence:
annotations: {}

extraVolumes:
""
[]
# - name: extras
# emptyDir: {}

extraVolumeMounts:
""
[]
# - name: extras
# mountPath: /usr/share/extras
# readOnly: true

extraContainers:
""
[]
# - name: do-something
# image: busybox
# command: ['do', 'something']

extraInitContainers:
""
[]
# - name: do-something
# image: busybox
# command: ['do', 'something']
Expand Down

0 comments on commit 2b09fdb

Please sign in to comment.