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

Commit

Permalink
[logstash] add flexible ingress (#1569)
Browse files Browse the repository at this point in the history
* [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
  • Loading branch information
jmlrt authored Mar 2, 2022
1 parent 115e53d commit d9cba9e
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 35 deletions.
22 changes: 19 additions & 3 deletions logstash/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -46,7 +61,8 @@ spec:
service:
name: {{ $fullName }}
port:
number: {{ $httpPort }}
number: {{ .servicePort | default $httpPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
87 changes: 75 additions & 12 deletions logstash/tests/logstash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
52 changes: 32 additions & 20 deletions logstash/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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

0 comments on commit d9cba9e

Please sign in to comment.