From d9cba9e3ba97b5faff47bf33a72f189fc597e5f0 Mon Sep 17 00:00:00 2001 From: Julien Mailleret <8582351+jmlrt@users.noreply.github.com> Date: Wed, 2 Mar 2022 15:16:40 +0100 Subject: [PATCH] [logstash] add flexible ingress (#1569) * [logstash] add flexible ingress Update Logstash ingress to be consistent with Elasticsearch and Kibana ingresses: - add back custom ingress port support - allow to use single ingress path - also improve example values and tests Fix #1500 * fixup! [logstash] add flexible ingress * add a deprecation note for ingresspath * update example * remove dup line * format --- logstash/templates/ingress.yaml | 22 +++++++-- logstash/tests/logstash_test.py | 87 ++++++++++++++++++++++++++++----- logstash/values.yaml | 52 ++++++++++++-------- 3 files changed, 126 insertions(+), 35 deletions(-) diff --git a/logstash/templates/ingress.yaml b/logstash/templates/ingress.yaml index db5f87b26..cf23fb328 100644 --- a/logstash/templates/ingress.yaml +++ b/logstash/templates/ingress.yaml @@ -30,12 +30,27 @@ spec: {{- end }} secretName: {{ .secretName }} {{- end }} -{{- else }} + {{- else }} {{ toYaml .Values.ingress.tls | indent 4 }} {{- end }} {{- end}} rules: - {{- range $.Values.ingress.hosts }} + {{- range .Values.ingress.hosts }} + {{- /* + TODO: deprecate $ingressPath for Logstash 8.0.0 + */}} + {{- if $ingressPath }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $httpPort }} + {{- else }} - host: {{ .host }} http: paths: @@ -46,7 +61,8 @@ spec: service: name: {{ $fullName }} port: - number: {{ $httpPort }} + number: {{ .servicePort | default $httpPort }} + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index c10c6a3ef..ab03cac22 100644 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -991,29 +991,92 @@ def test_setting_fullnameOverride(): ) -def test_adding_an_ingress(): +def test_adding_an_ingress_rule(): config = """ ingress: enabled: true - annotations: {} + annotations: + kubernetes.io/ingress.class: nginx hosts: - - host: logstash.local + - host: logstash.elastic.co paths: - - path: /logs + - path: / + - host: '' + paths: + - path: / + - path: /logz servicePort: 9600 + - host: logstash.hello.there + paths: + - path: / + servicePort: 9601 + tls: + - secretName: elastic-co-wildcard + hosts: + - logstash.elastic.co """ + r = helm_template(config) - s = r["ingress"][name] - assert s["metadata"]["name"] == name - assert s["spec"]["rules"][0]["host"] == "logstash.local" - assert s["spec"]["rules"][0]["http"]["paths"][0]["path"] == "/logs" + assert name in r["ingress"] + i = r["ingress"][name]["spec"] + assert i["tls"][0]["hosts"][0] == "logstash.elastic.co" + assert i["tls"][0]["secretName"] == "elastic-co-wildcard" + + assert i["rules"][0]["host"] == "logstash.elastic.co" + assert i["rules"][0]["http"]["paths"][0]["path"] == "/" + assert i["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name assert ( - s["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 9600 ) + assert i["rules"][1]["host"] == None + assert i["rules"][1]["http"]["paths"][0]["path"] == "/" + assert i["rules"][1]["http"]["paths"][0]["backend"]["service"]["name"] == name assert ( - s["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"][ - "number" - ] + i["rules"][1]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 9600 + ) + assert i["rules"][1]["http"]["paths"][1]["path"] == "/logz" + assert i["rules"][1]["http"]["paths"][1]["backend"]["service"]["name"] == name + assert ( + i["rules"][1]["http"]["paths"][1]["backend"]["service"]["port"]["number"] + == 9600 + ) + assert i["rules"][2]["host"] == "logstash.hello.there" + assert i["rules"][2]["http"]["paths"][0]["path"] == "/" + assert i["rules"][2]["http"]["paths"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][2]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 9601 + ) + + +def test_adding_a_deprecated_ingress_rule(): + config = """ +ingress: + enabled: true + annotations: + kubernetes.io/ingress.class: nginx + path: / + hosts: + - logstash.elastic.co + tls: + - secretName: elastic-co-wildcard + hosts: + - logstash.elastic.co +""" + + r = helm_template(config) + assert name in r["ingress"] + i = r["ingress"][name]["spec"] + assert i["tls"][0]["hosts"][0] == "logstash.elastic.co" + assert i["tls"][0]["secretName"] == "elastic-co-wildcard" + + assert i["rules"][0]["host"] == "logstash.elastic.co" + assert i["rules"][0]["http"]["paths"][0]["path"] == "/" + assert i["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] == 9600 ) diff --git a/logstash/values.yaml b/logstash/values.yaml index 1f0c0e7d4..c388e4c2e 100644 --- a/logstash/values.yaml +++ b/logstash/values.yaml @@ -128,21 +128,25 @@ persistence: enabled: false annotations: {} -extraVolumes: [] +extraVolumes: + [] # - name: extras # emptyDir: {} -extraVolumeMounts: [] +extraVolumeMounts: + [] # - name: extras # mountPath: /usr/share/extras # readOnly: true -extraContainers: [] +extraContainers: + [] # - name: do-something # image: busybox # command: ['do', 'something'] -extraInitContainers: [] +extraInitContainers: + [] # - name: do-something # image: busybox # command: ['do', 'something'] @@ -256,28 +260,36 @@ lifecycle: # exec: # command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"] -service: {} -# annotations: {} -# type: ClusterIP -# loadBalancerIP: "" -# externalTrafficPolicy: "" -# ports: -# - name: beats -# port: 5044 -# protocol: TCP -# targetPort: 5044 -# - name: http -# port: 8080 -# protocol: TCP -# targetPort: 8080 +service: + {} + # annotations: {} + # type: ClusterIP + # loadBalancerIP: "" + # ports: + # - name: beats + # port: 5044 + # protocol: TCP + # targetPort: 5044 + # - name: http + # port: 8080 + # protocol: TCP + # targetPort: 8080 ingress: enabled: false + annotations: + {} + # kubernetes.io/tls-acme: "true" className: "nginx" pathtype: ImplementationSpecific hosts: - host: logstash-example.local paths: - - path: / + - path: /beats + servicePort: 5044 + - path: /http + servicePort: 8080 tls: [] -# annotations: {} + # - secretName: logstash-example-tls + # hosts: + # - logstash-example.local