From 809e1cf55c7dba1ca98d8180c1bc8993c0b18f88 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Fri, 26 Jun 2020 18:17:01 +0200 Subject: [PATCH 1/3] [logstash] add headless service for statefulset 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. --- logstash/templates/service-headless.yaml | 23 +++++++++++++++++++++++ logstash/templates/statefulset.yaml | 6 ++---- logstash/tests/logstash_test.py | 7 +++++-- 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 logstash/templates/service-headless.yaml diff --git a/logstash/templates/service-headless.yaml b/logstash/templates/service-headless.yaml new file mode 100644 index 000000000..2bf840b34 --- /dev/null +++ b/logstash/templates/service-headless.yaml @@ -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 }} diff --git a/logstash/templates/statefulset.yaml b/logstash/templates/statefulset.yaml index 30dbb062f..18811ed21 100644 --- a/logstash/templates/statefulset.yaml +++ b/logstash/templates/statefulset.yaml @@ -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" . }}" @@ -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 }} diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 07bd7c877..2d96500f7 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -78,8 +78,11 @@ 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]["containerPort"] == 9600 + ) # Other assert r["statefulset"][name]["spec"]["template"]["spec"]["securityContext"] == { From f25291a23da2535977fe2cf1f0b15ee576ddea6c Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Fri, 26 Jun 2020 18:26:53 +0200 Subject: [PATCH 2/3] fix test --- logstash/tests/logstash_test.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 2d96500f7..7aa81e69f 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -80,9 +80,7 @@ def test_defaults(): # Service assert r["statefulset"][name]["spec"]["serviceName"] == name + "-headless" assert name + "-headless" in r["service"] - assert ( - r["service"][name + "-headless"]["spec"]["ports"][0]["containerPort"] == 9600 - ) + assert r["service"][name + "-headless"]["spec"]["ports"][0]["port"] == 9600 # Other assert r["statefulset"][name]["spec"]["template"]["spec"]["securityContext"] == { From 64150802ea47ed8b67b075017455ce2310199d4d Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Fri, 26 Jun 2020 19:47:39 +0200 Subject: [PATCH 3/3] fix 6.x test --- logstash/examples/6.x/test/goss.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/logstash/examples/6.x/test/goss.yaml b/logstash/examples/6.x/test/goss.yaml index 7b942055b..2b926da9a 100644 --- a/logstash/examples/6.x/test/goss.yaml +++ b/logstash/examples/6.x/test/goss.yaml @@ -9,10 +9,10 @@ http: status: 200 timeout: 2000 body: - - '"host" : "helm-logstash-six-logstash-0"' + - '"host" : "helm-logstash-six-logstash-0.helm-logstash-six-logstash-headless.helm-charts-testing.svc.cluster.local"' - '"version" : "6.8.10"' - '"http_address" : "0.0.0.0:9600"' - - '"name" : "helm-logstash-six-logstash-0"' + - '"name" : "helm-logstash-six-logstash-0.helm-logstash-six-logstash-headless.helm-charts-testing.svc.cluster.local"' file: /usr/share/logstash/config/logstash.yml: