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

Commit

Permalink
Elasticsearch: set PVC labels through setting all StatefulSet labels …
Browse files Browse the repository at this point in the history
…to its volumeClaimTemplate (#665)
  • Loading branch information
desaintmartin authored and jmlrt committed Jun 29, 2020
1 parent e93a51d commit c0b75d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
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

0 comments on commit c0b75d5

Please sign in to comment.