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 <m@rtyn.berlin>
Reviewed-on: https://gitea.com/gitea/helm-chart/pulls/252
Reviewed-by: justusbunsi <justusbunsi@noreply.gitea.io>
Reviewed-by: luhahn <luhahn@noreply.gitea.io>
Co-authored-by: iMartyn <imartyn@noreply.gitea.io>
Co-committed-by: iMartyn <imartyn@noreply.gitea.io>
This commit is contained in:
iMartyn 2021-12-20 19:54:37 +08:00 committed by luhahn
parent bef0cea1b1
commit d97b1567e2
3 changed files with 22 additions and 16 deletions

View File

@ -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

View File

@ -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:

View File

@ -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