From 266b0ea8d857cd686c061ec751bcf9bfcfe3e92c Mon Sep 17 00:00:00 2001 From: Travis Loyd Date: Mon, 6 Sep 2021 14:16:34 -0600 Subject: [PATCH] Fix #19 (new kubernetes API version) This is a signed squash of unsigned commits made by both Andrew and Travis Loyd . It is a slight cleanup of Travis Loyd's PR #27 Travis Loyd : * Fix for issue number 19, current api version and previous api version need to be updated * Added helm if statement to handle previous ingress 'http paths' style and current 'http paths' style * adjusted helm if statement to accomidate scoping by setting as a variable up top * moved new apiVersion variable to the top just under check for ingress enabled * added ingressClassName and set a default value of 'nginx' in the values file Andrew : * PR Change Cleanup * rename $apiVersion to $apiVersions * rename ingress.ingressClassName to ingress.className * add documentation entry for ingress.className * fix README default value --- README.md | 1 + templates/ingress.yaml | 15 ++++++++++++++- values.yaml | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13f8eb8..4eb54d3 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ their default values. | `ingress.path` | Ingress service path | `/` | | `ingress.hosts` | Ingress hostnames | `[]` | | `ingress.tls` | Ingress TLS configuration (YAML) | `[]` | +| `ingress.className` | Ingress controller class name | `nginx` | | `metrics.enabled` | Enable metrics on Service | `false` | | `metrics.port` | TCP port on which the service metrics is exposed | `5001` | | `metrics.serviceMonitor.annotations` | Prometheus Operator ServiceMonitor annotations | `{}` | diff --git a/templates/ingress.yaml b/templates/ingress.yaml index d04656d..cb90c2f 100644 --- a/templates/ingress.yaml +++ b/templates/ingress.yaml @@ -1,8 +1,9 @@ {{- if .Values.ingress.enabled -}} +{{- $apiVersions := .Capabilities.APIVersions -}} {{- $serviceName := include "docker-registry.fullname" . -}} {{- $servicePort := .Values.service.port -}} {{- $path := .Values.ingress.path -}} -apiVersion: {{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }} networking.k8s.io/v1beta1 {{- else }} extensions/v1beta1 {{- end }} +apiVersion: {{- if $apiVersions.Has "networking.k8s.io/v1" }} networking.k8s.io/v1 {{- else }} networking.k8s.io/v1beta1 {{- end }} kind: Ingress metadata: name: {{ template "docker-registry.fullname" . }} @@ -20,15 +21,27 @@ metadata: {{ $key }}: {{ $value | quote }} {{- end }} spec: +{{- if $apiVersions.Has "networking.k8s.io/v1" }} + ingressClassName: {{ .Values.ingress.className }} +{{- end }} rules: {{- range $host := .Values.ingress.hosts }} - host: {{ $host }} http: paths: - path: {{ $path }} +{{- if $apiVersions.Has "networking.k8s.io/v1" }} + pathType: Prefix + backend: + service: + name: {{ $serviceName }} + port: + number: {{ $servicePort }} +{{- else }} backend: serviceName: {{ $serviceName }} servicePort: {{ $servicePort }} +{{- end }} {{- end -}} {{- if .Values.ingress.tls }} tls: diff --git a/values.yaml b/values.yaml index ad49095..ece8caa 100644 --- a/values.yaml +++ b/values.yaml @@ -37,6 +37,7 @@ service: # foo.io/bar: "true" ingress: enabled: false + className: nginx path: / # Used to create an Ingress record. hosts: