From 68a85c0ab1e53179d26bcd7590414d40cd92f86c Mon Sep 17 00:00:00 2001 From: Julien Mailleret Date: Mon, 21 Oct 2019 21:49:34 +0200 Subject: [PATCH] [logstash] manage services for inputs implementing a listener --- logstash/templates/service.yaml | 23 +++++++++++++++++++++++ logstash/templates/statefulset.yaml | 3 +++ logstash/tests/logstash_test.py | 29 ++++++++++++++++++++++++++--- logstash/values.yaml | 13 +++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 logstash/templates/service.yaml diff --git a/logstash/templates/service.yaml b/logstash/templates/service.yaml new file mode 100644 index 000000000..0d22d4e20 --- /dev/null +++ b/logstash/templates/service.yaml @@ -0,0 +1,23 @@ +{{- if .Values.service }} +--- +kind: Service +apiVersion: v1 +metadata: + name: "{{ template "fullname" . }}" + labels: + app: "{{ template "fullname" . }}" + chart: "{{ .Chart.Name }}" + heritage: {{ .Release.Service | quote }} + release: {{ .Release.Name | quote }} + annotations: +{{ toYaml .Values.service.annotations | indent 4 }} +spec: + type: {{ .Values.service.type }} + selector: + app: "{{ template "fullname" . }}" + chart: "{{ .Chart.Name }}" + heritage: {{ .Release.Service | quote }} + release: {{ .Release.Name | quote }} + ports: +{{ toYaml .Values.service.ports | indent 4 }} +{{- end }} diff --git a/logstash/templates/statefulset.yaml b/logstash/templates/statefulset.yaml index 769e20ddf..53ec806f9 100644 --- a/logstash/templates/statefulset.yaml +++ b/logstash/templates/statefulset.yaml @@ -12,6 +12,9 @@ metadata: {{ $key }}: {{ $value | quote }} {{- end }} spec: + {{- if .Values.service }} + serviceName: {{ template "fullname" . }} + {{- end }} selector: matchLabels: app: "{{ template "fullname" . }}" diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 723af3765..743483004 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -73,7 +73,6 @@ def test_defaults(): assert '/' in c['readinessProbe']['httpGet']['path'] assert 'http' in c['readinessProbe']['httpGet']['port'] - # Resources assert c['resources'] == { 'requests': { @@ -90,6 +89,11 @@ def test_defaults(): assert 'volumeClaimTemplates' not in r['statefulset'][name]['spec'] assert r['statefulset'][name]['spec']['template']['spec']['containers'][0]['volumeMounts'] == None + # Service + assert 'serviceName' not in r['statefulset'][name]['spec'] + assert 'service' not in r + + # Other assert r['statefulset'][name]['spec']['template']['spec']['securityContext'] == { 'fsGroup': 1000, @@ -104,8 +108,6 @@ def test_defaults(): assert 'imagePullSecrets' not in r['statefulset'][name]['spec']['template']['spec'] assert 'tolerations' not in r['statefulset'][name]['spec']['template']['spec'] assert 'nodeSelector' not in r['statefulset'][name]['spec']['template']['spec'] - assert 'service' not in r - assert 'ingress' not in r def test_increasing_the_replicas(): @@ -547,3 +549,24 @@ def test_external_service_account(): # When referencing an external service account we do not want any resources to be created. for resource in resources: assert resource not in r + + +def test_adding_a_service(): + config = ''' +service: + annotations: {} + type: ClusterIP + ports: + - name: beats + port: 5044 + protocol: TCP + targetPort: 5044 +''' + r = helm_template(config) + s = r['service'][name] + assert s['metadata']['name'] == name + assert s['metadata']['annotations'] == None + assert s['spec']['type'] == 'ClusterIP' + assert len(s['spec']['ports']) == 1 + assert s['spec']['ports'][0] == { + 'name': 'beats', 'port': 5044, 'protocol': 'TCP', 'targetPort': 5044} diff --git a/logstash/values.yaml b/logstash/values.yaml index b23ac56df..e23690683 100755 --- a/logstash/values.yaml +++ b/logstash/values.yaml @@ -184,3 +184,16 @@ lifecycle: {} # postStart: # exec: # command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"] + +service: {} +# annotations: {} +# type: ClusterIP +# ports: +# - name: beats +# port: 5044 +# protocol: TCP +# targetPort: 5044 +# - name: http +# port: 8080 +# protocol: TCP +# targetPort: 8080