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

Commit

Permalink
[logstash] add headless service for statefulset (#695)
Browse files Browse the repository at this point in the history
This commit add a mandatory headless service for Logstash statefulset.

Headless service is required for Statefulsets.
While Helm 2 allowed to deploy Statefulsets without a serviceName, Helm 3 enforce this requirement and fails if serviceName is missing.

Note: Statefulsets don't accept serviceName field update during release upgrades. This change is therefore considered as a breaking change and will require using `helm upgrade --force` for upgrades.
  • Loading branch information
jmlrt committed Jun 29, 2020
1 parent bc5c501 commit 4a6067e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
23 changes: 23 additions & 0 deletions logstash/templates/service-headless.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
kind: Service
apiVersion: v1
metadata:
name: "{{ template "logstash.fullname" . }}-headless"
labels:
app: "{{ template "logstash.fullname" . }}"
chart: "{{ .Chart.Name }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
{{- if .Values.labels }}
{{ toYaml .Values.labels | indent 4 }}
{{- end }}
spec:
clusterIP: None
selector:
app: "{{ template "logstash.fullname" . }}"
ports:
- name: http
port: {{ .Values.httpPort }}
{{- if .Values.extraPorts }}
{{- toYaml .Values.extraPorts | nindent 2 }}
{{- end }}
6 changes: 2 additions & 4 deletions logstash/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ metadata:
{{ $key }}: {{ $value | quote }}
{{- end }}
spec:
{{- if .Values.service }}
serviceName: {{ template "logstash.fullname" . }}
{{- end }}
serviceName: {{ template "logstash.fullname" . }}-headless
selector:
matchLabels:
app: "{{ template "logstash.fullname" . }}"
Expand Down Expand Up @@ -151,7 +149,7 @@ spec:
- name: http
containerPort: {{ .Values.httpPort }}
{{- if .Values.extraPorts }}
{{- toYaml .Values.extraPorts | nindent 8 }}
{{- toYaml .Values.extraPorts | nindent 8 }}
{{- end }}
resources:
{{ toYaml .Values.resources | indent 10 }}
Expand Down
5 changes: 3 additions & 2 deletions logstash/tests/logstash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ def test_defaults():
)

# Service
assert "serviceName" not in r["statefulset"][name]["spec"]
assert "service" not in r
assert r["statefulset"][name]["spec"]["serviceName"] == name + "-headless"
assert name + "-headless" in r["service"]
assert r["service"][name + "-headless"]["spec"]["ports"][0]["port"] == 9600

# Other
assert r["statefulset"][name]["spec"]["template"]["spec"]["securityContext"] == {
Expand Down

0 comments on commit 4a6067e

Please sign in to comment.