From d97b1567e2e321e335685a088d0bb1be9336c748 Mon Sep 17 00:00:00 2001 From: iMartyn Date: Mon, 20 Dec 2021 19:54:37 +0800 Subject: [PATCH] Enable overriding of ingress api version for systems where detection doesn't work (#252) fixes #251 The rendering is a bit more programatic but the result is the same if you don't have an override. This makes the code a little easier at the end of the template, and slightly less easier to read at the beginning, which I think is a valid tradeoff. Co-authored-by: Martyn Ranyard Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/252 Reviewed-by: justusbunsi Reviewed-by: luhahn Co-authored-by: iMartyn Co-committed-by: iMartyn --- README.md | 19 ++++++++++--------- templates/gitea/ingress.yaml | 16 +++++++++------- values.yaml | 3 +++ 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index a97bd84..59db63e 100644 --- a/README.md +++ b/README.md @@ -607,15 +607,16 @@ gitea: ### Ingress -| Parameter | Description | Default | -| ------------------------------------ | ---------------------------------------------- | ----------------- | -| `ingress.enabled` | enable ingress | `false` | -| `ingress.annotations` | add ingress annotations | | -| `ingress.hosts[0].host` | add hosts for ingress | `git.example.com` | -| `ingress.hosts[0].paths[0].path` | add path for each ingress host | `/` | -| `ingress.hosts[0].paths[0].pathType` | add ingress path type | `Prefix` | -| `ingress.tls` | add ingress tls settings | `[]` | -| `ingress.className` | add ingress class name. Only used in k8s 1.19+ | | +| Parameter | Description | Default | +| ------------------------------------ | ---------------------------------------------------------------------------- | -------------------------------------------------- | +| `ingress.enabled` | enable ingress | `false` | +| `ingress.annotations` | add ingress annotations | | +| `ingress.hosts[0].host` | add hosts for ingress | `git.example.com` | +| `ingress.hosts[0].paths[0].path` | add path for each ingress host | `/` | +| `ingress.hosts[0].paths[0].pathType` | add ingress path type | `Prefix` | +| `ingress.tls` | add ingress tls settings | `[]` | +| `ingress.className` | add ingress class name. Only used in k8s 1.19+ | | +| `ingress.apiVersion` | specify APIVersion of ingress object. Mostly would only be used for argocd. | version indicated by helm's `Capabilities` object. | ### Service diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 2af0804..224e777 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -1,13 +1,15 @@ {{- if .Values.ingress.enabled -}} {{- $fullName := include "gitea.fullname" . -}} {{- $httpPort := .Values.service.http.port -}} -{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" -}} -apiVersion: networking.k8s.io/v1 +{{- $apiVersion := "extensions/v1beta1" -}} +{{- if .Values.ingress.apiVersion -}} +{{- $apiVersion = .Values.ingress.apiVersion -}} +{{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" -}} +{{- $apiVersion = "networking.k8s.io/v1" }} {{- else if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1/Ingress" -}} -apiVersion: networking.k8s.io/v1beta1 -{{- else -}} -apiVersion: extensions/v1beta1 +{{- $apiVersion = "networking.k8s.io/v1beta1" }} {{- end }} +apiVersion: {{ $apiVersion }} kind: Ingress metadata: name: {{ $fullName }} @@ -38,11 +40,11 @@ spec: paths: {{- range .paths }} - path: {{ .path }} - {{- if and .pathType ($.Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress") }} + {{- if and .pathType (eq $apiVersion "networking.k8s.io/v1") }} pathType: {{ .pathType }} {{- end }} backend: - {{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1/Ingress" }} + {{- if eq $apiVersion "networking.k8s.io/v1" }} service: name: {{ $fullName }}-http port: diff --git a/values.yaml b/values.yaml index ef6f324..1290ef9 100644 --- a/values.yaml +++ b/values.yaml @@ -78,6 +78,9 @@ ingress: # - secretName: chart-example-tls # hosts: # - git.example.com + # Mostly for argocd or any other CI that uses `helm template | kubectl apply` or similar + # If helm doesn't correctly detect your ingress API version you can set it here. + # apiVersion: networking.k8s.io/v1 resources: {} # We usually recommend not to specify default resources and to leave this as a conscious