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

Commit

Permalink
[elasticsearch][kibana] Add flexible ingress (#994)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Mailleret <8582351+jmlrt@users.noreply.github.com>
  • Loading branch information
kevinsmithwrs and jmlrt committed Jan 12, 2021
1 parent d6f7844 commit ae7526c
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 8 deletions.
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 @@ -691,6 +691,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


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

0 comments on commit ae7526c

Please sign in to comment.