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

Commit

Permalink
Added ingress support to the logstash chart (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbelo committed Oct 16, 2020
1 parent a5ae58d commit e4ab721
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 9 deletions.
7 changes: 6 additions & 1 deletion logstash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ in this [note][]).
to make default probes work. If restricting HTTP API to 127.0.0.1 is required by
using `http.host: 127.0.0.1`, default probes should be disabled or overrided
(see [values.yaml][] for the good syntax).
* An ingress is provided that can be used to expose the HTTP port. This can be
useful for the [http input plugin][], for instance.


## Configuration
Expand All @@ -111,9 +113,10 @@ using `http.host: 127.0.0.1`, default probes should be disabled or overrided
| `httpPort` | The http port that Kubernetes will use for the healthchecks and the service | `9600` |
| `imagePullPolicy` | The Kubernetes [imagePullPolicy][] value | `IfNotPresent` |
| `imagePullSecrets` | Configuration for [imagePullSecrets][] so that you can use a private registry for your image | `[]` |
| `imageTag` | The Logstash Docker image tag | `8.0.0-SNAPSHOT` |
| `imageTag` | The Logstash Docker image tag | `8.0.0-SNAPSHOT` |
| `image` | The Logstash Docker image | `docker.elastic.co/logstash/logstash` |
| `labels` | Configurable [labels][] applied to all Logstash pods | `{}` |
| `ingress` | Configurable [ingress][] for external access to Logstash HTTP port. | see [values.yaml][] |
| `lifecycle` | Allows you to add lifecycle configuration. See [values.yaml][] for an example of the formatting | `{}` |
| `livenessProbe` | Configuration fields for the liveness [probe][] | see [values.yaml][] |
| `logstashConfig` | Allows you to add any config files in `/usr/share/logstash/config/` such as `logstash.yml` and `log4j2.properties` See [values.yaml][] for an example of the formatting | `{}` |
Expand Down Expand Up @@ -200,8 +203,10 @@ about our development and testing process.
[examples/oss]: https://github.com/elastic/helm-charts/tree/master/logstash/examples/oss
[helm]: https://helm.sh
[helm 3 (beta)]: https://github.com/elastic/helm-charts/tree/master/README.md#helm-3-beta
[http input plugin]: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-http.html
[imagePullPolicy]: https://kubernetes.io/docs/concepts/containers/images/#updating-images
[imagePullSecrets]: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/#create-a-pod-that-uses-your-secret
[ingress]: https://kubernetes.io/docs/concepts/services-networking/ingress/
[kubernetes secrets]: https://kubernetes.io/docs/concepts/configuration/secret/
[labels]: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/
[logstash docker image]: https://www.elastic.co/guide/en/logstash/current/docker.html
Expand Down
11 changes: 11 additions & 0 deletions logstash/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ Return the appropriate apiVersion for statefulset.
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}

{{/*
Return the appropriate apiVersion for ingress.
*/}}
{{- define "logstash.ingress.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "extensions/v1beta1" -}}
{{- else -}}
{{- print "networking.k8s.io/v1beta1" -}}
{{- end -}}
{{- end -}}
33 changes: 33 additions & 0 deletions logstash/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "logstash.fullname" . -}}
apiVersion: {{ template "logstash.ingress.apiVersion" . }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
app: {{ $fullName | quote}}
chart: "{{ .Chart.Name }}"
heritage: {{ .Release.Service | quote }}
release: {{ .Release.Name | quote }}
{{- with .Values.ingress.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end }}
rules:
{{- range $.Values.ingress.hosts }}
- host: {{ .host }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ .servicePort }}
{{- end }}
{{- end }}
{{- end }}
40 changes: 32 additions & 8 deletions logstash/tests/logstash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def test_adding_persistence():
assert c["volumeMounts"][0]["mountPath"] == "/usr/share/logstash/data"
assert c["volumeMounts"][0]["name"] == name

v = r["statefulset"]["release-name-logstash"]["spec"]["volumeClaimTemplates"][0]
v = r["statefulset"][name]["spec"]["volumeClaimTemplates"][0]
assert v["metadata"]["name"] == name
assert v["spec"]["accessModes"] == ["ReadWriteOnce"]
assert v["spec"]["resources"]["requests"]["storage"] == "1Gi"
Expand Down Expand Up @@ -540,9 +540,9 @@ def test_adding_a_node_affinity():
- myvalue
"""
r = helm_template(config)
assert r["statefulset"]["release-name-logstash"]["spec"]["template"]["spec"][
"affinity"
]["nodeAffinity"] == {
assert r["statefulset"][name]["spec"]["template"]["spec"]["affinity"][
"nodeAffinity"
] == {
"preferredDuringSchedulingIgnoredDuringExecution": [
{
"weight": 100,
Expand Down Expand Up @@ -580,10 +580,9 @@ def test_adding_in_logstash_config():

s = r["statefulset"][name]["spec"]["template"]["spec"]

assert {
"configMap": {"name": "release-name-logstash-config"},
"name": "logstashconfig",
} in s["volumes"]
assert {"configMap": {"name": name + "-config"}, "name": "logstashconfig",} in s[
"volumes"
]
assert {
"mountPath": "/usr/share/logstash/config/logstash.yml",
"name": "logstashconfig",
Expand Down Expand Up @@ -876,3 +875,28 @@ def test_setting_fullnameOverride():
]
== "logstash"
)


def test_adding_an_ingress():
config = """
ingress:
enabled: true
annotations: {}
hosts:
- host: logstash.local
paths:
- path: /logs
servicePort: 8080
"""
r = helm_template(config)
s = r["ingress"][name]
assert s["metadata"]["name"] == name
assert len(s["spec"]["rules"]) == 1
assert s["spec"]["rules"][0] == {
"host": "logstash.local",
"http": {
"paths": [
{"path": "/logs", "backend": {"serviceName": name, "servicePort": 8080}}
]
},
}
10 changes: 10 additions & 0 deletions logstash/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,13 @@ service: {}
# port: 8080
# protocol: TCP
# targetPort: 8080

ingress:
enabled: false
# annotations: {}
# hosts:
# - host: logstash.local
# paths:
# - path: /logs
# servicePort: 8080
# tls: []

0 comments on commit e4ab721

Please sign in to comment.