From fca8dc72f377b7efea786c75021b52cc75462c32 Mon Sep 17 00:00:00 2001 From: Martin Lillemets Date: Mon, 16 May 2022 13:42:58 +0300 Subject: [PATCH] Logstash: Add option to configure PVC labels in StatefulSets Allows adding custom labels to PVCs created by StatefulSets --- logstash/templates/statefulset.yaml | 10 ++++++++++ logstash/tests/logstash_test.py | 13 +++++++++++++ logstash/values.yaml | 3 +++ 3 files changed, 26 insertions(+) diff --git a/logstash/templates/statefulset.yaml b/logstash/templates/statefulset.yaml index 239fac33f..28c07b081 100644 --- a/logstash/templates/statefulset.yaml +++ b/logstash/templates/statefulset.yaml @@ -25,6 +25,16 @@ spec: volumeClaimTemplates: - metadata: name: {{ template "logstash.fullname" . }} + {{- if .Values.persistence.labels.enabled }} + labels: + app: "{{ template "logstash.fullname" . }}" + chart: "{{ .Chart.Name }}" + heritage: {{ .Release.Service | quote }} + release: {{ .Release.Name | quote }} + {{- range $key, $value := .Values.labels }} + {{ $key }}: {{ $value | quote }} + {{- end }} + {{- end }} {{- with .Values.persistence.annotations }} annotations: {{ toYaml . | indent 8 }} diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 112f2ab6c..0160d3c36 100644 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -301,6 +301,19 @@ def test_adding_persistence(): assert v["spec"]["resources"]["requests"]["storage"] == "1Gi" +def test_adding_persistence_label_in_volumeclaimtemplate(): + config = """ +persistence: + enabled: true + labels: + enabled: true +""" + r = helm_template(config) + v = r["statefulset"][name]["spec"]["volumeClaimTemplates"][0]["metadata"]["labels"] + sts = r["statefulset"][name]["metadata"]["labels"] + assert v == sts + + def test_adding_storageclass_annotation_to_volumeclaimtemplate(): config = """ persistence: diff --git a/logstash/values.yaml b/logstash/values.yaml index 7d4dc4168..fc2e26a33 100644 --- a/logstash/values.yaml +++ b/logstash/values.yaml @@ -126,6 +126,9 @@ podSecurityPolicy: persistence: enabled: false + # Add default labels for the volumeClaimTemplate fo the StatefulSet + labels: + enabled: false annotations: {} extraVolumes: