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

Commit 24eab34

Browse files
authored
[logstash] add flexible ingress (#1569) (#1597)
* [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
1 parent 3d4c558 commit 24eab34

File tree

3 files changed

+118
-31
lines changed

3 files changed

+118
-31
lines changed

logstash/templates/ingress.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,27 @@ spec:
3030
{{- end }}
3131
secretName: {{ .secretName }}
3232
{{- end }}
33-
{{- else }}
33+
{{- else }}
3434
{{ toYaml .Values.ingress.tls | indent 4 }}
3535
{{- end }}
3636
{{- end}}
3737
rules:
38-
{{- range $.Values.ingress.hosts }}
38+
{{- range .Values.ingress.hosts }}
39+
{{- /*
40+
TODO: deprecate $ingressPath for Logstash 8.0.0
41+
*/}}
42+
{{- if $ingressPath }}
43+
- host: {{ . }}
44+
http:
45+
paths:
46+
- path: {{ $ingressPath }}
47+
pathType: {{ $pathtype }}
48+
backend:
49+
service:
50+
name: {{ $fullName }}
51+
port:
52+
number: {{ $httpPort }}
53+
{{- else }}
3954
- host: {{ .host }}
4055
http:
4156
paths:
@@ -46,7 +61,8 @@ spec:
4661
service:
4762
name: {{ $fullName }}
4863
port:
49-
number: {{ $httpPort }}
64+
number: {{ .servicePort | default $httpPort }}
65+
{{- end }}
5066
{{- end }}
5167
{{- end }}
5268
{{- end }}

logstash/tests/logstash_test.py

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -991,29 +991,92 @@ def test_setting_fullnameOverride():
991991
)
992992

993993

994-
def test_adding_an_ingress():
994+
def test_adding_an_ingress_rule():
995995
config = """
996996
ingress:
997997
enabled: true
998-
annotations: {}
998+
annotations:
999+
kubernetes.io/ingress.class: nginx
9991000
hosts:
1000-
- host: logstash.local
1001+
- host: logstash.elastic.co
10011002
paths:
1002-
- path: /logs
1003+
- path: /
1004+
- host: ''
1005+
paths:
1006+
- path: /
1007+
- path: /logz
10031008
servicePort: 9600
1009+
- host: logstash.hello.there
1010+
paths:
1011+
- path: /
1012+
servicePort: 9601
1013+
tls:
1014+
- secretName: elastic-co-wildcard
1015+
hosts:
1016+
- logstash.elastic.co
10041017
"""
1018+
10051019
r = helm_template(config)
1006-
s = r["ingress"][name]
1007-
assert s["metadata"]["name"] == name
1008-
assert s["spec"]["rules"][0]["host"] == "logstash.local"
1009-
assert s["spec"]["rules"][0]["http"]["paths"][0]["path"] == "/logs"
1020+
assert name in r["ingress"]
1021+
i = r["ingress"][name]["spec"]
1022+
assert i["tls"][0]["hosts"][0] == "logstash.elastic.co"
1023+
assert i["tls"][0]["secretName"] == "elastic-co-wildcard"
1024+
1025+
assert i["rules"][0]["host"] == "logstash.elastic.co"
1026+
assert i["rules"][0]["http"]["paths"][0]["path"] == "/"
1027+
assert i["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name
10101028
assert (
1011-
s["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name
1029+
i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"]
1030+
== 9600
10121031
)
1032+
assert i["rules"][1]["host"] == None
1033+
assert i["rules"][1]["http"]["paths"][0]["path"] == "/"
1034+
assert i["rules"][1]["http"]["paths"][0]["backend"]["service"]["name"] == name
10131035
assert (
1014-
s["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"][
1015-
"number"
1016-
]
1036+
i["rules"][1]["http"]["paths"][0]["backend"]["service"]["port"]["number"]
1037+
== 9600
1038+
)
1039+
assert i["rules"][1]["http"]["paths"][1]["path"] == "/logz"
1040+
assert i["rules"][1]["http"]["paths"][1]["backend"]["service"]["name"] == name
1041+
assert (
1042+
i["rules"][1]["http"]["paths"][1]["backend"]["service"]["port"]["number"]
1043+
== 9600
1044+
)
1045+
assert i["rules"][2]["host"] == "logstash.hello.there"
1046+
assert i["rules"][2]["http"]["paths"][0]["path"] == "/"
1047+
assert i["rules"][2]["http"]["paths"][0]["backend"]["service"]["name"] == name
1048+
assert (
1049+
i["rules"][2]["http"]["paths"][0]["backend"]["service"]["port"]["number"]
1050+
== 9601
1051+
)
1052+
1053+
1054+
def test_adding_a_deprecated_ingress_rule():
1055+
config = """
1056+
ingress:
1057+
enabled: true
1058+
annotations:
1059+
kubernetes.io/ingress.class: nginx
1060+
path: /
1061+
hosts:
1062+
- logstash.elastic.co
1063+
tls:
1064+
- secretName: elastic-co-wildcard
1065+
hosts:
1066+
- logstash.elastic.co
1067+
"""
1068+
1069+
r = helm_template(config)
1070+
assert name in r["ingress"]
1071+
i = r["ingress"][name]["spec"]
1072+
assert i["tls"][0]["hosts"][0] == "logstash.elastic.co"
1073+
assert i["tls"][0]["secretName"] == "elastic-co-wildcard"
1074+
1075+
assert i["rules"][0]["host"] == "logstash.elastic.co"
1076+
assert i["rules"][0]["http"]["paths"][0]["path"] == "/"
1077+
assert i["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name
1078+
assert (
1079+
i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"]
10171080
== 9600
10181081
)
10191082

logstash/values.yaml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -260,28 +260,36 @@ lifecycle:
260260
# exec:
261261
# command: ["/bin/sh", "-c", "echo Hello from the postStart handler > /usr/share/message"]
262262

263-
service: {}
264-
# annotations: {}
265-
# type: ClusterIP
266-
# loadBalancerIP: ""
267-
# externalTrafficPolicy: ""
268-
# ports:
269-
# - name: beats
270-
# port: 5044
271-
# protocol: TCP
272-
# targetPort: 5044
273-
# - name: http
274-
# port: 8080
275-
# protocol: TCP
276-
# targetPort: 8080
263+
service:
264+
{}
265+
# annotations: {}
266+
# type: ClusterIP
267+
# loadBalancerIP: ""
268+
# ports:
269+
# - name: beats
270+
# port: 5044
271+
# protocol: TCP
272+
# targetPort: 5044
273+
# - name: http
274+
# port: 8080
275+
# protocol: TCP
276+
# targetPort: 8080
277277

278278
ingress:
279279
enabled: false
280+
annotations:
281+
{}
282+
# kubernetes.io/tls-acme: "true"
280283
className: "nginx"
281284
pathtype: ImplementationSpecific
282285
hosts:
283286
- host: logstash-example.local
284287
paths:
285-
- path: /
288+
- path: /beats
289+
servicePort: 5044
290+
- path: /http
291+
servicePort: 8080
286292
tls: []
287-
# annotations: {}
293+
# - secretName: logstash-example-tls
294+
# hosts:
295+
# - logstash-example.local

0 commit comments

Comments
 (0)