From f06e3e4298f479522121919df130371954bf5274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Zimmermann?= <101292599+ekneg54@users.noreply.github.com> Date: Thu, 18 Jul 2024 10:19:44 +0200 Subject: [PATCH] add support for extraVolumes and extraMounts (#635) * add support for extraVolumes and extraMounts populate volumes and mounts from value keys adds logprep-cache-dir in memory volume and mounts it to /home/logprep/.cache --- charts/logprep/Chart.yaml | 2 +- charts/logprep/templates/deployment.yaml | 11 +++++ charts/logprep/values.yaml | 15 +++++++ tests/unit/charts/test_deployment.py | 51 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 1 deletion(-) diff --git a/charts/logprep/Chart.yaml b/charts/logprep/Chart.yaml index e0461da08..50f71b756 100644 --- a/charts/logprep/Chart.yaml +++ b/charts/logprep/Chart.yaml @@ -6,7 +6,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: "13.1.1" +version: "13.2.0" # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/logprep/templates/deployment.yaml b/charts/logprep/templates/deployment.yaml index fec19187f..87e3bebf6 100644 --- a/charts/logprep/templates/deployment.yaml +++ b/charts/logprep/templates/deployment.yaml @@ -76,6 +76,8 @@ spec: mountPath: /tmp - name: prometheus-multiproc mountPath: /prometheus + - name: logprep-cache-dir + mountPath: /home/logprep/.cache {{- range $key, $value := .Values.configurations }} {{- if $value.data }} - name: configurations @@ -107,6 +109,9 @@ spec: subPath: {{ $value.name }} {{ end }} {{- end }} + {{- if .Values.extraMounts }} + {{- toYaml .Values.extraMounts | nindent 12 }} + {{- end }} {{- if or .Values.exporter.enabled (eq .Values.input.type "http_input") }} {{- if eq .Values.input.type "http_input" }} readinessProbe: @@ -150,6 +155,9 @@ spec: - name: prometheus-multiproc emptyDir: medium: "Memory" + - name: logprep-cache-dir + emptyDir: + medium: "Memory" - name: configurations configMap: name: {{ include "logprep.fullname" . }}-configurations @@ -177,6 +185,9 @@ spec: secretName: {{ $value.name }} {{- end }} {{- end }} + {{- if .Values.extraVolumes }} + {{- toYaml .Values.extraVolumes | nindent 8 }} + {{- end }} {{- if .Values.affinity }} affinity: podAntiAffinity: diff --git a/charts/logprep/values.yaml b/charts/logprep/values.yaml index 1e455f886..9ec46ba9e 100644 --- a/charts/logprep/values.yaml +++ b/charts/logprep/values.yaml @@ -63,6 +63,21 @@ affinity: false # inject extra labels to all resources metadata extraLabels: {} +# extraVolumes to populate the pod with +# Example: +# extraVolumes: +# - name: my-volume +# configMap: +# name: my-configmap +extraVolumes: [] + +# extraMounts to populate the pod with +# Example: +# extraMounts: +# - name: my-volume +# mountPath: /path/to/mount +extraMounts: [] + # Use this to annotate the logprep pods # podAnnotations: # sidecar.istio.io/rewriteAppHTTPProbers: "false" diff --git a/tests/unit/charts/test_deployment.py b/tests/unit/charts/test_deployment.py index 34d6fa7dc..5c8092d37 100644 --- a/tests/unit/charts/test_deployment.py +++ b/tests/unit/charts/test_deployment.py @@ -439,3 +439,54 @@ def test_environment_variables_populated_from_secrets(self): assert my_var["value"] == "my_value" my_var = [variable for variable in env if variable["name"] == "MY_OTHER_VAR"].pop() assert my_var["valueFrom"]["secretKeyRef"]["name"] == "my-secret" + + def test_extra_volumes_are_populated(self): + logprep_values = { + "extraVolumes": [ + { + "name": "my-volume", + "configMap": {"name": "my-configmap"}, + }, + { + "name": "my-volume2", + "configMap": {"name": "my-configmap"}, + }, + ] + } + self.manifests = self.render_chart("logprep", logprep_values) + volumes = self.deployment["spec.template.spec.volumes"] + volume = [volume for volume in volumes if volume["name"] == "my-volume"].pop() + assert volume["configMap"]["name"] == "my-configmap" + + def test_extra_mounts_are_populated(self): + logprep_values = { + "extraMounts": [ + { + "name": "my-volume", + "mountPath": "/my-path", + }, + { + "name": "my-volume2", + "mountPath": "/my-path2", + "subPath": "sub-path", + }, + ] + } + self.manifests = self.render_chart("logprep", logprep_values) + mounts = self.deployment["spec.template.spec.containers.0.volumeMounts"] + mount = [mount for mount in mounts if mount["name"] == "my-volume"].pop() + assert mount["mountPath"] == "/my-path" + mount = [mount for mount in mounts if mount["name"] == "my-volume2"].pop() + assert mount["subPath"] == "sub-path" + + def test_logprep_cache_dir_is_populated(self): + volumes = self.deployment["spec.template.spec.volumes"] + cache_dir_volume = [ + volume for volume in volumes if volume["name"] == "logprep-cache-dir" + ].pop() + assert cache_dir_volume + assert cache_dir_volume["emptyDir"] == {"medium": "Memory"} + mounts = self.deployment["spec.template.spec.containers.0.volumeMounts"] + cache_dir_mount = [mount for mount in mounts if mount["name"] == "logprep-cache-dir"].pop() + assert cache_dir_mount + assert cache_dir_mount["mountPath"] == "/home/logprep/.cache"