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

[elasticsearch][kibana] Add flexible ingress #994

Merged
merged 4 commits into from
Dec 22, 2020
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
20 changes: 18 additions & 2 deletions elasticsearch/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "elasticsearch.uname" . -}}
{{- $servicePort := .Values.httpPort -}}
{{- $httpPort := .Values.httpPort -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
Expand All @@ -17,22 +17,38 @@ metadata:
spec:
{{- if .Values.ingress.tls }}
tls:
{{- if .ingressPath }}
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- else }}
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
{{- if $ingressPath }}
- host: {{ . }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $servicePort }}
servicePort: {{ $httpPort }}
{{- else }}
- host: {{ .host }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ .servicePort | default $httpPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
48 changes: 48 additions & 0 deletions elasticsearch/tests/elasticsearch_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,54 @@ def test_adding_a_node_affinity():

def test_adding_an_ingress_rule():
config = """
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
hosts:
- host: elasticsearch.elastic.co
paths:
- path: /
- host: ''
paths:
- path: /
- path: /mypath
servicePort: 8888
- host: elasticsearch.hello.there
paths:
- path: /
servicePort: 9999
tls:
- secretName: elastic-co-wildcard
hosts:
- elasticsearch.elastic.co
"""

r = helm_template(config)
assert uname in r["ingress"]
i = r["ingress"][uname]["spec"]
assert i["tls"][0]["hosts"][0] == "elasticsearch.elastic.co"
assert i["tls"][0]["secretName"] == "elastic-co-wildcard"

assert i["rules"][0]["host"] == "elasticsearch.elastic.co"
assert i["rules"][0]["http"]["paths"][0]["path"] == "/"
assert i["rules"][0]["http"]["paths"][0]["backend"]["serviceName"] == uname
assert i["rules"][0]["http"]["paths"][0]["backend"]["servicePort"] == 9200
assert i["rules"][1]["host"] == None
assert i["rules"][1]["http"]["paths"][0]["path"] == "/"
assert i["rules"][1]["http"]["paths"][0]["backend"]["serviceName"] == uname
assert i["rules"][1]["http"]["paths"][0]["backend"]["servicePort"] == 9200
assert i["rules"][1]["http"]["paths"][1]["path"] == "/mypath"
assert i["rules"][1]["http"]["paths"][1]["backend"]["serviceName"] == uname
assert i["rules"][1]["http"]["paths"][1]["backend"]["servicePort"] == 8888
assert i["rules"][2]["host"] == "elasticsearch.hello.there"
assert i["rules"][2]["http"]["paths"][0]["path"] == "/"
assert i["rules"][2]["http"]["paths"][0]["backend"]["serviceName"] == uname
assert i["rules"][2]["http"]["paths"][0]["backend"]["servicePort"] == 9999

kevinsmithwrs marked this conversation as resolved.
Show resolved Hide resolved

def test_adding_a_deprecated_ingress_rule():
config = """
ingress:
enabled: true
annotations:
Expand Down
5 changes: 3 additions & 2 deletions elasticsearch/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,10 @@ ingress:
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
- host: chart-example.local
paths:
- path: /
tls: []
# - secretName: chart-example-tls
# hosts:
Expand Down
26 changes: 24 additions & 2 deletions kibana/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "kibana.fullname" . -}}
{{- $servicePort := .Values.service.port -}}
{{- $httpPort := .Values.httpPort -}}
{{- $ingressPath := .Values.ingress.path -}}
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
Expand All @@ -14,16 +14,38 @@ metadata:
spec:
{{- if .Values.ingress.tls }}
tls:
{{- if .ingressPath }}
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- else }}
{{ toYaml .Values.ingress.tls | indent 4 }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
{{- if $ingressPath }}
- host: {{ . }}
http:
paths:
- path: {{ $ingressPath }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $servicePort }}
servicePort: {{ $httpPort }}
{{- else }}
- host: {{ .host }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ .servicePort | default $httpPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
76 changes: 76 additions & 0 deletions kibana/tests/kibana_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,54 @@ def test_adding_a_extra_init_container():

def test_adding_an_ingress_rule():
config = """
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
hosts:
- host: kibana.elastic.co
paths:
- path: /
- path: /testpath
servicePort: 8888
- host: ''
paths:
- path: /
- host: kibana.hello.there
paths:
- path: /mypath
servicePort: 9999
tls:
- secretName: elastic-co-wildcard
hosts:
- kibana.elastic.co
"""

r = helm_template(config)
assert name in r["ingress"]
i = r["ingress"][name]["spec"]
assert i["tls"][0]["hosts"][0] == "kibana.elastic.co"
assert i["tls"][0]["secretName"] == "elastic-co-wildcard"

assert i["rules"][0]["host"] == "kibana.elastic.co"
assert i["rules"][0]["http"]["paths"][0]["path"] == "/"
assert i["rules"][0]["http"]["paths"][0]["backend"]["serviceName"] == name
assert i["rules"][0]["http"]["paths"][0]["backend"]["servicePort"] == 5601
assert i["rules"][0]["http"]["paths"][1]["path"] == "/testpath"
assert i["rules"][0]["http"]["paths"][1]["backend"]["serviceName"] == name
assert i["rules"][0]["http"]["paths"][1]["backend"]["servicePort"] == 8888
assert i["rules"][1]["host"] == None
assert i["rules"][1]["http"]["paths"][0]["path"] == "/"
assert i["rules"][1]["http"]["paths"][0]["backend"]["serviceName"] == name
assert i["rules"][1]["http"]["paths"][0]["backend"]["servicePort"] == 5601
assert i["rules"][2]["host"] == "kibana.hello.there"
assert i["rules"][2]["http"]["paths"][0]["path"] == "/mypath"
assert i["rules"][2]["http"]["paths"][0]["backend"]["serviceName"] == name
assert i["rules"][2]["http"]["paths"][0]["backend"]["servicePort"] == 9999


def test_adding_a_deprecated_ingress_rule():
config = """
ingress:
enabled: true
annotations:
Expand Down Expand Up @@ -233,6 +281,34 @@ def test_adding_an_ingress_rule():

def test_adding_an_ingress_rule_wildcard():
config = """
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
hosts:
- host: kibana.elastic.co
paths:
- path: /
tls:
- secretName: elastic-co-wildcard
hosts:
- "*.elastic.co"
"""

r = helm_template(config)
assert name in r["ingress"]
i = r["ingress"][name]["spec"]
assert i["tls"][0]["hosts"][0] == "*.elastic.co"
assert i["tls"][0]["secretName"] == "elastic-co-wildcard"

assert i["rules"][0]["host"] == "kibana.elastic.co"
assert i["rules"][0]["http"]["paths"][0]["path"] == "/"
assert i["rules"][0]["http"]["paths"][0]["backend"]["serviceName"] == name
assert i["rules"][0]["http"]["paths"][0]["backend"]["servicePort"] == 5601


def test_adding_a_deprecated_ingress_rule_wildcard():
config = """
ingress:
enabled: true
annotations:
Expand Down
5 changes: 3 additions & 2 deletions kibana/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ ingress:
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
path: /
hosts:
- chart-example.local
- host: chart-example.local
paths:
- path: /
tls: []
# - secretName: chart-example-tls
# hosts:
Expand Down