From 41dcb485641a57285aaafa48e12b3cf210ea6321 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Sun, 13 Sep 2026 19:34:56 +0200 Subject: [PATCH] refactor(ingress): extract annotation, label and name rendering into helpers The Ingress was the last chart-managed resource that built its metadata inline. Annotations were rendered with a `range` over the values map, which indents each entry manually and cannot be reused, and the resource had no way to attach additional labels. Annotations, labels and the name are now rendered by helpers in `_ingresses.tpl`, matching the pattern already used by the other resources. This also adds `ingress.labels` so extra labels can be attached to the Ingress, and reorders the `ingress` keys in `values.yaml` to the convention of `enabled`, `annotations` and `labels` first. The `$httpPort` variable was assigned before the `range` over `ingress.hosts` and therefore resolved against the wrong context once the loop rebound the dot. It has been replaced by `$.Values.service.http.port`, which reads the value from the root context at the point of use. Co-authored-by: Copilot --- README.md | 3 ++- templates/gitea/_ingresses.tpl | 24 ++++++++++++++++++++++++ templates/gitea/ingress.yaml | 25 +++++++++++++------------ values.yaml | 6 ++++-- 4 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 templates/gitea/_ingresses.tpl diff --git a/README.md b/README.md index 494eefe..18797cd 100644 --- a/README.md +++ b/README.md @@ -1144,9 +1144,10 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo | Name | Description | Value | | -------------------------------- | ---------------------------------------------------------------------------------------------- | ----------------- | | `ingress.enabled` | Enable ingress | `false` | +| `ingress.annotations` | Additional annotations. | `{}` | +| `ingress.labels` | Additional labels. | `{}` | | `ingress.className` | DEPRECATED: Ingress class name. | `""` | | `ingress.pathType` | Ingress Path Type | `Prefix` | -| `ingress.annotations` | Ingress annotations | `{}` | | `ingress.hosts[0].host` | Default Ingress host | `git.example.com` | | `ingress.hosts[0].paths[0].path` | Default Ingress path | `/` | | `ingress.tls` | Ingress tls settings | `[]` | diff --git a/templates/gitea/_ingresses.tpl b/templates/gitea/_ingresses.tpl new file mode 100644 index 0000000..741dd32 --- /dev/null +++ b/templates/gitea/_ingresses.tpl @@ -0,0 +1,24 @@ +{{/* vim: set filetype=mustache: */}} + +{{/* annotations */}} + +{{- define "gitea.ingress.annotations" -}} +{{- with .Values.ingress.annotations }} +{{- toYaml . -}} +{{- end }} +{{- end }} + +{{/* labels */}} + +{{- define "gitea.ingress.labels" -}} +{{ include "gitea.labels" . }} +{{- with .Values.ingress.labels }} +{{ toYaml . }} +{{- end }} +{{- end }} + +{{/* name */}} + +{{- define "gitea.ingress.name" -}} +{{ include "gitea.fullname" . }} +{{- end }} \ No newline at end of file diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 408cba6..5b1cf74 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -1,17 +1,18 @@ {{- if .Values.ingress.enabled -}} -{{- $fullName := include "gitea.fullname" . -}} -{{- $httpPort := .Values.service.http.port -}} +--- apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ $fullName }} - namespace: {{ .Values.namespace | default .Release.Namespace }} - labels: - {{- include "gitea.labels" . | nindent 4 }} + {{- with (include "gitea.ingress.annotations" .) }} annotations: - {{- range $key, $value := .Values.ingress.annotations }} - {{ $key }}: {{ $value | quote }} - {{- end }} + {{- . | nindent 4 }} + {{- end }} + {{- with (include "gitea.ingress.labels" .) }} + labels: + {{- . | nindent 4 }} + {{- end }} + name: {{ include "gitea.ingress.name" . }} + namespace: {{ .Values.namespace | default .Release.Namespace }} spec: ingressClassName: {{ tpl .Values.ingress.className . }} {{- if .Values.ingress.tls }} @@ -38,7 +39,7 @@ spec: service: name: {{ include "gitea.service.http.name" $ }} port: - number: {{ $httpPort }} + number: {{ $.Values.service.http.port }} {{- else }} - path: {{ .path | default "/" }} pathType: {{ .pathType | default "Prefix" }} @@ -46,7 +47,7 @@ spec: service: name: {{ include "gitea.service.http.name" $ }} port: - number: {{ $httpPort }} + number: {{ $.Values.service.http.port }} {{- end }} {{- end }} {{- else }} @@ -56,7 +57,7 @@ spec: service: name: {{ include "gitea.service.http.name" $ }} port: - number: {{ $httpPort }} + number: {{ $.Values.service.http.port }} {{- end }} {{- end }} {{- end }} diff --git a/values.yaml b/values.yaml index 6026615..5ca937d 100644 --- a/values.yaml +++ b/values.yaml @@ -588,17 +588,19 @@ gatewayAPI: ## @section Ingress ## @param ingress.enabled Enable ingress +## @param ingress.annotations Additional annotations. +## @param ingress.labels Additional labels. ## @param ingress.className DEPRECATED: Ingress class name. ## @param ingress.pathType Ingress Path Type -## @param ingress.annotations Ingress annotations ## @param ingress.hosts[0].host Default Ingress host ## @param ingress.hosts[0].paths[0].path Default Ingress path ## @param ingress.tls Ingress tls settings ingress: enabled: false + annotations: {} + labels: {} className: "" pathType: Prefix - annotations: {} hosts: - host: git.example.com paths: