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

Elasticsearch: set PVC labels through setting all StatefulSet labels to its volumeClaimTemplate #665

Merged
merged 1 commit into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions elasticsearch/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ spec:
volumeClaimTemplates:
- metadata:
name: {{ template "elasticsearch.uname" . }}
{{- if .Values.persistence.labels.enabled }}
labels:
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
chart: "{{ .Chart.Name }}"
app: "{{ template "elasticsearch.uname" . }}"
{{- range $key, $value := .Values.labels }}
{{ $key }}: {{ $value | quote }}
{{- end }}
{{- end }}
{{- with .Values.persistence.annotations }}
annotations:
{{ toYaml . | indent 8 }}
Expand Down
16 changes: 16 additions & 0 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def test_defaults():
assert c["volumeMounts"][0]["mountPath"] == "/usr/share/elasticsearch/data"
assert c["volumeMounts"][0]["name"] == uname

# volumeClaimTemplates
v = r["statefulset"][uname]["spec"]["volumeClaimTemplates"][0]
assert v["metadata"]["name"] == uname
assert "labels" not in v["metadata"]
assert v["spec"]["accessModes"] == ["ReadWriteOnce"]
assert v["spec"]["resources"]["requests"]["storage"] == "30Gi"

Expand Down Expand Up @@ -479,6 +481,20 @@ def test_adding_multiple_persistence_annotations():
assert annotations["world"] == "hello"


def test_enabling_persistence_label_in_volumeclaimtemplate():
config = """
persistence:
labels:
enabled: true
"""
r = helm_template(config)
volume_claim_template_labels = r["statefulset"][uname]["spec"][
"volumeClaimTemplates"
][0]["metadata"]["labels"]
statefulset_labels = r["statefulset"][uname]["metadata"]["labels"]
assert volume_claim_template_labels == statefulset_labels


def test_adding_a_secret_mount():
config = """
secretMounts:
Expand Down
3 changes: 3 additions & 0 deletions elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ podSecurityPolicy:

persistence:
enabled: true
labels:
# Add default labels for the volumeClaimTemplate fo the StatefulSet
enabled: false
annotations: {}

extraVolumes: []
Expand Down