refactor: migrate ingress definition out of beta (#679)
### Description of the change Redesigned ingress configuration to align better with implicit best practices. ### Benefits - Smarter defaults - More tests - Remove [deprecated API Versions](extensions/v1beta1) (e.g. `extensions/v1beta1`) and always use `networking.k8s.io/v1` ### Possible drawbacks Hopefully 🙃 none ### Applicable issues fix #674 ### Additional information - Define `ingress.annotations` via helpers - Move tests from `tests/deployment` to `tests/ingress` - Use own tests file for ingress tpl tests - Ensure defaults of `path` and `pathType` are always rendered - Set top-level default value for `ingress. pathType` - Change default of `ingress.hosts[0].paths` to `[]` to ensure proper rendering via template ### ⚠ BREAKING I think all of these changes should be backward comp with existing ingress definitions, but surely worth highlighting in the changelog of the release. ### Checklist <!-- [Place an '[X]' (no spaces) in all applicable fields. Please remove unrelated fields.] --> - [x] Parameters are documented in the `values.yaml` and added to the `README.md` using [readme-generator-for-helm](https://github.com/bitnami-labs/readme-generator-for-helm) - [x] Breaking changes are documented in the `README.md` - [x] Templating unittests are added Co-authored-by: justusbunsi <justusbunsi@noreply.gitea.com> Co-authored-by: justusbunsi <sk.bunsenbrenner@gmail.com> Reviewed-on: https://gitea.com/gitea/helm-gitea/pulls/679 Co-authored-by: pat-s <patrick.schratz@gmail.com> Co-committed-by: pat-s <patrick.schratz@gmail.com>
This commit is contained in:
parent
87272a1244
commit
a94eec4238
@ -991,15 +991,14 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo
|
|||||||
### Ingress
|
### Ingress
|
||||||
|
|
||||||
| Name | Description | Value |
|
| Name | Description | Value |
|
||||||
| ------------------------------------ | --------------------------------------------------------------------------- | ----------------- |
|
| -------------------------------- | ------------------------------ | ----------------- |
|
||||||
| `ingress.enabled` | Enable ingress | `false` |
|
| `ingress.enabled` | Enable ingress | `false` |
|
||||||
| `ingress.className` | Ingress class name | `nil` |
|
| `ingress.className` | DEPRECATED: Ingress class name | `""` |
|
||||||
|
| `ingress.pathType` | Ingress Path Type | `Prefix` |
|
||||||
| `ingress.annotations` | Ingress annotations | `{}` |
|
| `ingress.annotations` | Ingress annotations | `{}` |
|
||||||
| `ingress.hosts[0].host` | Default Ingress host | `git.example.com` |
|
| `ingress.hosts[0].host` | Default Ingress host | `git.example.com` |
|
||||||
| `ingress.hosts[0].paths[0].path` | Default Ingress path | `/` |
|
| `ingress.hosts[0].paths[0].path` | Default Ingress path | `/` |
|
||||||
| `ingress.hosts[0].paths[0].pathType` | Ingress path type | `Prefix` |
|
|
||||||
| `ingress.tls` | Ingress tls settings | `[]` |
|
| `ingress.tls` | Ingress tls settings | `[]` |
|
||||||
| `ingress.apiVersion` | Specify APIVersion of ingress object. Mostly would only be used for argocd. | |
|
|
||||||
|
|
||||||
### deployment
|
### deployment
|
||||||
|
|
||||||
|
@ -428,6 +428,18 @@ https
|
|||||||
{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }}
|
{{ .Values.serviceAccount.name | default (include "gitea.fullname" .) }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
|
{{- define "ingress.annotations" -}}
|
||||||
|
{{- if .Values.ingress.annotations }}
|
||||||
|
annotations:
|
||||||
|
{{- $tp := typeOf .Values.ingress.annotations }}
|
||||||
|
{{- if eq $tp "string" }}
|
||||||
|
{{- tpl .Values.ingress.annotations . | nindent 4 }}
|
||||||
|
{{- else }}
|
||||||
|
{{- toYaml .Values.ingress.annotations | nindent 4 }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "gitea.admin.passwordMode" -}}
|
{{- define "gitea.admin.passwordMode" -}}
|
||||||
{{- if has .Values.gitea.admin.passwordMode (tuple "keepUpdated" "initialOnlyNoReset" "initialOnlyRequireReset") -}}
|
{{- if has .Values.gitea.admin.passwordMode (tuple "keepUpdated" "initialOnlyNoReset" "initialOnlyRequireReset") -}}
|
||||||
{{ .Values.gitea.admin.passwordMode }}
|
{{ .Values.gitea.admin.passwordMode }}
|
||||||
|
@ -1,15 +1,7 @@
|
|||||||
{{- if .Values.ingress.enabled -}}
|
{{- if .Values.ingress.enabled -}}
|
||||||
{{- $fullName := include "gitea.fullname" . -}}
|
{{- $fullName := include "gitea.fullname" . -}}
|
||||||
{{- $httpPort := .Values.service.http.port -}}
|
{{- $httpPort := .Values.service.http.port -}}
|
||||||
{{- $apiVersion := "extensions/v1beta1" -}}
|
apiVersion: networking.k8s.io/v1
|
||||||
{{- 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" }}
|
|
||||||
{{- end }}
|
|
||||||
apiVersion: {{ $apiVersion }}
|
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
name: {{ $fullName }}
|
name: {{ $fullName }}
|
||||||
@ -23,6 +15,8 @@ metadata:
|
|||||||
spec:
|
spec:
|
||||||
{{- if .Values.ingress.className }}
|
{{- if .Values.ingress.className }}
|
||||||
ingressClassName: {{ tpl .Values.ingress.className . }}
|
ingressClassName: {{ tpl .Values.ingress.className . }}
|
||||||
|
{{- else if .Values.ingress.ingressClassName }}
|
||||||
|
ingressClassName: {{ tpl .Values.ingress.ingressClassName . }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if .Values.ingress.tls }}
|
{{- if .Values.ingress.tls }}
|
||||||
tls:
|
tls:
|
||||||
@ -39,21 +33,34 @@ spec:
|
|||||||
- host: {{ tpl .host $ | quote }}
|
- host: {{ tpl .host $ | quote }}
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
|
{{- if .paths }}
|
||||||
{{- range .paths }}
|
{{- range .paths }}
|
||||||
- path: {{ .path }}
|
{{- if kindIs "string" . }}
|
||||||
{{- if and .pathType (eq $apiVersion "networking.k8s.io/v1") }}
|
- path: {{ . }}
|
||||||
pathType: {{ .pathType }}
|
pathType: {{ default "Prefix" $.Values.ingress.pathType }}
|
||||||
{{- end }}
|
|
||||||
backend:
|
backend:
|
||||||
{{- if eq $apiVersion "networking.k8s.io/v1" }}
|
|
||||||
service:
|
service:
|
||||||
name: {{ $fullName }}-http
|
name: {{ $fullName }}-http
|
||||||
port:
|
port:
|
||||||
number: {{ $httpPort }}
|
number: {{ $httpPort }}
|
||||||
{{- else }}
|
{{- else }}
|
||||||
serviceName: {{ $fullName }}-http
|
- path: {{ .path | default "/" }}
|
||||||
servicePort: {{ $httpPort }}
|
pathType: {{ .pathType | default "Prefix" }}
|
||||||
{{- end }}
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ $fullName }}-http
|
||||||
|
port:
|
||||||
|
number: {{ $httpPort }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
- path: "/"
|
||||||
|
pathType: "Prefix"
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ $fullName }}-http
|
||||||
|
port:
|
||||||
|
number: {{ $httpPort }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -1,28 +1,7 @@
|
|||||||
suite: ingress template
|
suite: Test ingress tpl use
|
||||||
release:
|
|
||||||
name: gitea-unittests
|
|
||||||
namespace: testing
|
|
||||||
templates:
|
templates:
|
||||||
- templates/gitea/ingress.yaml
|
- templates/gitea/ingress.yaml
|
||||||
tests:
|
tests:
|
||||||
- it: hostname using TPL
|
|
||||||
set:
|
|
||||||
global.giteaHostName: "gitea.example.com"
|
|
||||||
ingress.enabled: true
|
|
||||||
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
|
||||||
ingress.tls:
|
|
||||||
- secretName: gitea-tls
|
|
||||||
hosts:
|
|
||||||
- "{{ .Values.global.giteaHostName }}"
|
|
||||||
asserts:
|
|
||||||
- isKind:
|
|
||||||
of: Ingress
|
|
||||||
- equal:
|
|
||||||
path: spec.tls[0].hosts[0]
|
|
||||||
value: "gitea.example.com"
|
|
||||||
- equal:
|
|
||||||
path: spec.rules[0].host
|
|
||||||
value: "gitea.example.com"
|
|
||||||
- it: Ingress Class using TPL
|
- it: Ingress Class using TPL
|
||||||
set:
|
set:
|
||||||
global.ingress.className: "ingress-class"
|
global.ingress.className: "ingress-class"
|
||||||
@ -45,3 +24,22 @@ tests:
|
|||||||
- equal:
|
- equal:
|
||||||
path: spec.ingressClassName
|
path: spec.ingressClassName
|
||||||
value: "ingress-class"
|
value: "ingress-class"
|
||||||
|
|
||||||
|
- it: hostname using TPL
|
||||||
|
set:
|
||||||
|
global.giteaHostName: "gitea.example.com"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "{{ .Values.global.giteaHostName }}"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "gitea.example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "gitea.example.com"
|
||||||
|
93
unittests/helm/ingress/basic.yaml
Normal file
93
unittests/helm/ingress/basic.yaml
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
suite: Test ingress.yaml
|
||||||
|
templates:
|
||||||
|
- templates/gitea/ingress.yaml
|
||||||
|
tests:
|
||||||
|
- it: should enable ingress when ingress.enabled is true
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.apiVersion: networking.k8s.io/v1
|
||||||
|
ingress.annotations:
|
||||||
|
kubernetes.io/ingress.class: nginx
|
||||||
|
ingress.className: nginx
|
||||||
|
ingress.tls:
|
||||||
|
- hosts:
|
||||||
|
- example.com
|
||||||
|
secretName: tls-secret
|
||||||
|
ingress.hosts:
|
||||||
|
- host: example.com
|
||||||
|
paths: ["/"]
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: metadata.name
|
||||||
|
value: RELEASE-NAME-gitea
|
||||||
|
- matchRegex:
|
||||||
|
path: apiVersion
|
||||||
|
pattern: networking.k8s.io/v1
|
||||||
|
- equal:
|
||||||
|
path: spec.ingressClassName
|
||||||
|
value: nginx
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].secretName
|
||||||
|
value: tls-secret
|
||||||
|
- equal:
|
||||||
|
path: metadata.annotations["kubernetes.io/ingress.class"]
|
||||||
|
value: nginx
|
||||||
|
|
||||||
|
- it: should not create ingress when ingress.enabled is false
|
||||||
|
set:
|
||||||
|
ingress.enabled: false
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 0
|
||||||
|
|
||||||
|
- it: Ingress Class using TPL
|
||||||
|
set:
|
||||||
|
global.ingress.className: "ingress-class"
|
||||||
|
ingress.ingressClassName: "{{ .Values.global.ingress.className }}"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "some-host"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "some-host"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "some-host"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "some-host"
|
||||||
|
- equal:
|
||||||
|
path: spec.ingressClassName
|
||||||
|
value: "ingress-class"
|
||||||
|
|
||||||
|
- it: hostname using TPL
|
||||||
|
set:
|
||||||
|
global.giteaHostName: "gitea.example.com"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "{{ .Values.global.giteaHostName }}"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "gitea.example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "gitea.example.com"
|
23
unittests/helm/ingress/implicit-defaults.yaml
Normal file
23
unittests/helm/ingress/implicit-defaults.yaml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
suite: Test ingress with implicit path defaults
|
||||||
|
templates:
|
||||||
|
- templates/gitea/ingress.yaml
|
||||||
|
tests:
|
||||||
|
- it: should use default path and pathType when no paths are specified
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts:
|
||||||
|
- host: git.example.com
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "git.example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].http.paths[0].path
|
||||||
|
value: "/"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].http.paths[0].pathType
|
||||||
|
value: "Prefix"
|
45
unittests/helm/ingress/ingress.tpl.yaml
Normal file
45
unittests/helm/ingress/ingress.tpl.yaml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
suite: Test ingress tpl use
|
||||||
|
templates:
|
||||||
|
- templates/gitea/ingress.yaml
|
||||||
|
tests:
|
||||||
|
- it: Ingress Class using TPL
|
||||||
|
set:
|
||||||
|
global.ingress.className: "ingress-class"
|
||||||
|
ingress.className: "{{ .Values.global.ingress.className }}"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "some-host"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "some-host"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "some-host"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "some-host"
|
||||||
|
- equal:
|
||||||
|
path: spec.ingressClassName
|
||||||
|
value: "ingress-class"
|
||||||
|
|
||||||
|
- it: hostname using TPL
|
||||||
|
set:
|
||||||
|
global.giteaHostName: "gitea.example.com"
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts[0].host: "{{ .Values.global.giteaHostName }}"
|
||||||
|
ingress.tls:
|
||||||
|
- secretName: gitea-tls
|
||||||
|
hosts:
|
||||||
|
- "{{ .Values.global.giteaHostName }}"
|
||||||
|
asserts:
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.tls[0].hosts[0]
|
||||||
|
value: "gitea.example.com"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "gitea.example.com"
|
26
unittests/helm/ingress/structured-paths.yaml
Normal file
26
unittests/helm/ingress/structured-paths.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
suite: Test ingress with structured paths
|
||||||
|
templates:
|
||||||
|
- templates/gitea/ingress.yaml
|
||||||
|
tests:
|
||||||
|
- it: should work with structured path definitions
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.hosts:
|
||||||
|
- host: git.devxy.io
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- isKind:
|
||||||
|
of: Ingress
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].host
|
||||||
|
value: "git.devxy.io"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].http.paths[0].path
|
||||||
|
value: "/"
|
||||||
|
- equal:
|
||||||
|
path: spec.rules[0].http.paths[0].pathType
|
||||||
|
value: "Prefix"
|
18
values.yaml
18
values.yaml
@ -157,33 +157,25 @@ service:
|
|||||||
|
|
||||||
## @section Ingress
|
## @section Ingress
|
||||||
## @param ingress.enabled Enable ingress
|
## @param ingress.enabled Enable ingress
|
||||||
## @param ingress.className Ingress class name
|
## @param ingress.className DEPRECATED: Ingress class name
|
||||||
|
## @param ingress.pathType Ingress Path Type
|
||||||
## @param ingress.annotations Ingress annotations
|
## @param ingress.annotations Ingress annotations
|
||||||
## @param ingress.hosts[0].host Default Ingress host
|
## @param ingress.hosts[0].host Default Ingress host
|
||||||
## @param ingress.hosts[0].paths[0].path Default Ingress path
|
## @param ingress.hosts[0].paths[0].path Default Ingress path
|
||||||
## @param ingress.hosts[0].paths[0].pathType Ingress path type
|
|
||||||
## @param ingress.tls Ingress tls settings
|
## @param ingress.tls Ingress tls settings
|
||||||
## @extra ingress.apiVersion Specify APIVersion of ingress object. Mostly would only be used for argocd.
|
|
||||||
ingress:
|
ingress:
|
||||||
enabled: false
|
enabled: false
|
||||||
# className: nginx
|
className: ""
|
||||||
className:
|
pathType: Prefix
|
||||||
annotations:
|
annotations: {}
|
||||||
{}
|
|
||||||
# kubernetes.io/ingress.class: nginx
|
|
||||||
# kubernetes.io/tls-acme: "true"
|
|
||||||
hosts:
|
hosts:
|
||||||
- host: git.example.com
|
- host: git.example.com
|
||||||
paths:
|
paths:
|
||||||
- path: /
|
- path: /
|
||||||
pathType: Prefix
|
|
||||||
tls: []
|
tls: []
|
||||||
# - secretName: chart-example-tls
|
# - secretName: chart-example-tls
|
||||||
# hosts:
|
# hosts:
|
||||||
# - git.example.com
|
# - 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
|
|
||||||
|
|
||||||
## @section deployment
|
## @section deployment
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user