From 57aa59a5c33c913f1d1eb8a5806fb821f87e52f2 Mon Sep 17 00:00:00 2001 From: framsouza Date: Thu, 14 Oct 2021 09:27:16 +0200 Subject: [PATCH] [all] Add support to ingress networking.k8s.io/v1 & ingressClassName (#1409) * Adding support to Ingress networking.k8s.io/v1 * Adjusting ES service name * Removing ingress typo & adjusting python test * Adjusting python tests to use the new ingress version * fixing conflict * Adding support to kubernetes ingress v1 & ClassName * Adding reformatted files * fixing conflict * Adding ClassName & Pathtype on ingress settings * Performing syntax adjustments and removing comments --- apm-server/templates/ingress.yaml | 23 +++++--- apm-server/values.yaml | 2 + elasticsearch/templates/ingress.yaml | 66 +++++++++++++---------- elasticsearch/tests/elasticsearch_test.py | 35 ++++++++---- elasticsearch/values.yaml | 2 + kibana/templates/ingress.yaml | 54 +++++++++++-------- kibana/tests/kibana_test.py | 49 ++++++++++++----- kibana/values.yaml | 6 ++- logstash/templates/ingress.yaml | 41 ++++++++++---- logstash/tests/logstash_test.py | 22 ++++---- logstash/values.yaml | 13 ++--- 11 files changed, 202 insertions(+), 111 deletions(-) mode change 100755 => 100644 elasticsearch/values.yaml diff --git a/apm-server/templates/ingress.yaml b/apm-server/templates/ingress.yaml index 64ebcced9..487208bf3 100644 --- a/apm-server/templates/ingress.yaml +++ b/apm-server/templates/ingress.yaml @@ -1,8 +1,9 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "apm.fullname" . -}} {{- $servicePort := .Values.service.port -}} +{{- $pathtype := .Values.ingress.pathtype -}} {{- $ingressPath := .Values.ingress.path -}} -apiVersion: networking.k8s.io/v1beta1 +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ template "apm.fullname" . }} @@ -17,18 +18,24 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className | quote }} + {{- end }} {{- if .Values.ingress.tls }} tls: {{ toYaml .Values.ingress.tls | indent 4 }} {{- end }} rules: {{- range .Values.ingress.hosts }} - - host: {{ . }} - http: - paths: - - path: {{ $ingressPath }} - backend: - serviceName: {{ $fullName }} - servicePort: {{ $servicePort }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $servicePort }} {{- end }} {{- end }} diff --git a/apm-server/values.yaml b/apm-server/values.yaml index 09716e121..90dbbb00b 100755 --- a/apm-server/values.yaml +++ b/apm-server/values.yaml @@ -157,6 +157,8 @@ autoscaling: ingress: enabled: false + className: "nginx" + pathtype: ImplementationSpecific annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" diff --git a/elasticsearch/templates/ingress.yaml b/elasticsearch/templates/ingress.yaml index bcb2befa6..e60cebf18 100644 --- a/elasticsearch/templates/ingress.yaml +++ b/elasticsearch/templates/ingress.yaml @@ -1,8 +1,9 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "elasticsearch.uname" . -}} {{- $httpPort := .Values.httpPort -}} +{{- $pathtype := .Values.ingress.pathtype -}} {{- $ingressPath := .Values.ingress.path -}} -apiVersion: networking.k8s.io/v1beta1 +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ $fullName }} @@ -15,40 +16,49 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className | quote }} + {{- end }} {{- if .Values.ingress.tls }} tls: {{- if .ingressPath }} - {{- range .Values.ingress.tls }} - - hosts: - {{- range .hosts }} - - {{ . }} - {{- end }} - secretName: {{ .secretName }} + {{- range .Values.ingress.tls }} + - hosts: + {{- range .hosts }} + - {{ . }} {{- end }} - {{- else }} + secretName: {{ .secretName }} + {{- end }} +{{- else }} {{ toYaml .Values.ingress.tls | indent 4 }} {{- end }} -{{- end }} +{{- end}} rules: {{- range .Values.ingress.hosts }} {{- if $ingressPath }} - - host: {{ . }} - http: - paths: - - path: {{ $ingressPath }} - backend: - serviceName: {{ $fullName }} - servicePort: {{ $httpPort }} - {{- else }} - - host: {{ .host }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - backend: - serviceName: {{ $fullName }} - servicePort: {{ .servicePort | default $httpPort }} - {{- end }} - {{- end }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $httpPort }} + {{- else }} + - host: {{ .host }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ .servicePort | default $httpPort }} + {{- end }} {{- end }} -{{- end }} + {{- end }} + {{- end }} diff --git a/elasticsearch/tests/elasticsearch_test.py b/elasticsearch/tests/elasticsearch_test.py index 20e2446dc..ba78f2b5d 100755 --- a/elasticsearch/tests/elasticsearch_test.py +++ b/elasticsearch/tests/elasticsearch_test.py @@ -644,19 +644,31 @@ def test_adding_an_ingress_rule(): 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"][0]["http"]["paths"][0]["backend"]["service"]["name"] == uname + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 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"][0]["backend"]["service"]["name"] == uname + assert ( + i["rules"][1]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 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"][1]["http"]["paths"][1]["backend"]["service"]["name"] == uname + assert ( + i["rules"][1]["http"]["paths"][1]["backend"]["service"]["port"]["number"] + == 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 + assert i["rules"][2]["http"]["paths"][0]["backend"]["service"]["name"] == uname + assert ( + i["rules"][2]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 9999 + ) def test_adding_a_deprecated_ingress_rule(): @@ -682,8 +694,11 @@ def test_adding_a_deprecated_ingress_rule(): 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"][0]["http"]["paths"][0]["backend"]["service"]["name"] == uname + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 9200 + ) def test_changing_the_protocol(): diff --git a/elasticsearch/values.yaml b/elasticsearch/values.yaml old mode 100755 new mode 100644 index 0efde9c0d..4019bc313 --- a/elasticsearch/values.yaml +++ b/elasticsearch/values.yaml @@ -246,6 +246,8 @@ tolerations: [] ingress: enabled: false annotations: {} + className: "nginx" + pathtype: ImplementationSpecific # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: diff --git a/kibana/templates/ingress.yaml b/kibana/templates/ingress.yaml index f79255f30..002538057 100644 --- a/kibana/templates/ingress.yaml +++ b/kibana/templates/ingress.yaml @@ -1,8 +1,9 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "kibana.fullname" . -}} {{- $httpPort := .Values.httpPort -}} +{{- $pathtype := .Values.ingress.pathtype -}} {{- $ingressPath := .Values.ingress.path -}} -apiVersion: networking.k8s.io/v1beta1 +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ $fullName }} @@ -12,6 +13,9 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className | quote }} + {{- end }} {{- if .Values.ingress.tls }} tls: {{- if .ingressPath }} @@ -21,31 +25,37 @@ spec: - {{ . }} {{- end }} secretName: {{ .secretName }} - {{- end }} - {{- else }} + {{- 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: {{ $httpPort }} - {{- else }} - - host: {{ .host }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - backend: - serviceName: {{ $fullName }} - servicePort: {{ .servicePort | default $httpPort }} - {{- end }} - {{- end }} + - host: {{ . }} + http: + paths: + - path: {{ $ingressPath }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $httpPort }} + {{- else }} + - host: {{ .host }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ .servicePort | default $httpPort }} + {{- end }} {{- end }} -{{- end }} + {{- end }} + {{- end }} diff --git a/kibana/tests/kibana_test.py b/kibana/tests/kibana_test.py index 4ffe56665..256cbf63a 100644 --- a/kibana/tests/kibana_test.py +++ b/kibana/tests/kibana_test.py @@ -260,19 +260,31 @@ def test_adding_an_ingress_rule(): 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"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 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"][0]["http"]["paths"][1]["backend"]["service"]["name"] == name + assert ( + i["rules"][0]["http"]["paths"][1]["backend"]["service"]["port"]["number"] + == 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"][1]["http"]["paths"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][1]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 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 + assert i["rules"][2]["http"]["paths"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][2]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 9999 + ) def test_adding_a_deprecated_ingress_rule(): @@ -298,8 +310,11 @@ def test_adding_a_deprecated_ingress_rule(): 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"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 5601 + ) def test_adding_an_ingress_rule_wildcard(): @@ -326,8 +341,11 @@ def test_adding_an_ingress_rule_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"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 5601 + ) def test_adding_a_deprecated_ingress_rule_wildcard(): @@ -353,8 +371,11 @@ def test_adding_a_deprecated_ingress_rule_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"][0]["backend"]["service"]["name"] == name + assert ( + i["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"]["number"] + == 5601 + ) def test_override_the_default_update_strategy(): diff --git a/kibana/values.yaml b/kibana/values.yaml index 5f88613aa..4902fa41c 100755 --- a/kibana/values.yaml +++ b/kibana/values.yaml @@ -141,14 +141,16 @@ service: ingress: enabled: false + className: "nginx" + pathtype: ImplementationSpecific annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: - - host: chart-example.local + - host: kibana-example.local paths: - path: / - tls: [] + #tls: [] # - secretName: chart-example-tls # hosts: # - chart-example.local diff --git a/logstash/templates/ingress.yaml b/logstash/templates/ingress.yaml index a4aeb145e..db5f87b26 100644 --- a/logstash/templates/ingress.yaml +++ b/logstash/templates/ingress.yaml @@ -1,6 +1,9 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "logstash.fullname" . -}} -apiVersion: networking.k8s.io/v1beta1 +{{- $httpPort := .Values.httpPort -}} +{{- $ingressPath := .Values.ingress.path -}} +{{- $pathtype := .Values.ingress.pathtype -}} +apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: {{ $fullName }} @@ -14,20 +17,36 @@ metadata: {{ toYaml . | indent 4 }} {{- end }} spec: + {{- if .Values.ingress.className }} + ingressClassName: {{ .Values.ingress.className | quote }} + {{- end }} {{- 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 }} +{{- end}} rules: {{- range $.Values.ingress.hosts }} - - host: {{ .host }} - http: - paths: - {{- range .paths }} - - path: {{ .path }} - backend: - serviceName: {{ $fullName }} - servicePort: {{ .servicePort }} - {{- end }} + - host: {{ .host }} + http: + paths: + {{- range .paths }} + - path: {{ .path }} + pathType: {{ $pathtype }} + backend: + service: + name: {{ $fullName }} + port: + number: {{ $httpPort }} + {{- end }} {{- end }} {{- end }} diff --git a/logstash/tests/logstash_test.py b/logstash/tests/logstash_test.py index 0f539aca2..4d6e7b2fe 100755 --- a/logstash/tests/logstash_test.py +++ b/logstash/tests/logstash_test.py @@ -932,20 +932,22 @@ def test_adding_an_ingress(): - host: logstash.local paths: - path: /logs - servicePort: 8080 + servicePort: 9600 """ 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}} - ] - }, - } + assert s["spec"]["rules"][0]["host"] == "logstash.local" + assert s["spec"]["rules"][0]["http"]["paths"][0]["path"] == "/logs" + assert ( + s["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["name"] == name + ) + assert ( + s["spec"]["rules"][0]["http"]["paths"][0]["backend"]["service"]["port"][ + "number" + ] + == 9600 + ) def test_hostaliases(): diff --git a/logstash/values.yaml b/logstash/values.yaml index 44b542df9..4cabddaf7 100755 --- a/logstash/values.yaml +++ b/logstash/values.yaml @@ -270,10 +270,11 @@ service: {} ingress: enabled: false + className: "nginx" + pathtype: ImplementationSpecific + hosts: + - host: logstash-example.local + paths: + - path: / + tls: [] # annotations: {} -# hosts: -# - host: logstash.local -# paths: -# - path: /logs -# servicePort: 8080 -# tls: []