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

[logstash] add flexible ingress #1569

Merged
merged 8 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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