From ddd0290b55fe7103de09f24a6efbdeed5c43a734 Mon Sep 17 00:00:00 2001 From: Ceddaerrix <48319+ceddaerrix@noreply.gitea.com> Date: Fri, 4 Dec 2026 17:08:33 +0000 Subject: [PATCH] feat: adding 'tpl' to ingress annotation values (#1124) ### Description of the change Adding templating support into ingress annotations so the following can be used (hence avoiding YAML anchors): ``` ingress: className: "{{ .Values.global.ingress.className }}" annotations: cert-manager.io/issuer: "{{ .Values.global.issuer.name }}" ``` ### Benefits - avoiding use of YAML anchors and related limitations - Possibility to inject a value into an annotation even from an umbrella chart ### Checklist - [x] Helm templating unittests are added (required when changing anything in `templates` folder) Reviewed-on: https://gitea.com/gitea/helm-gitea/pulls/1124 Reviewed-by: Markus Pesch <1641+volker.raschek@noreply.gitea.com> Co-authored-by: Ceddaerrix <48319+ceddaerrix@noreply.gitea.com> --- templates/ingress.yaml | 8 +- unittests/helm/ingress/dry-support.yaml | 100 ++++++++++++++++++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 unittests/helm/ingress/dry-support.yaml diff --git a/templates/ingress.yaml b/templates/ingress.yaml index 9f7ba93..bfe2e23 100644 --- a/templates/ingress.yaml +++ b/templates/ingress.yaml @@ -3,10 +3,10 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - {{- with (include "gitea.ingress.annotations" .) }} +{{- with (include "gitea.ingress.annotations" $) }} annotations: - {{- . | nindent 4 }} - {{- end }} +{{- tpl . $ | nindent 4 }} +{{- end }} {{- with (include "gitea.ingress.labels" .) }} labels: {{- . | nindent 4 }} @@ -14,7 +14,7 @@ metadata: name: {{ include "gitea.ingress.name" . }} namespace: {{ .Release.Namespace }} spec: - ingressClassName: {{ tpl .Values.ingress.ingressClassName . }} + ingressClassName: {{ tpl .Values.ingress.ingressClassName $ }} rules: {{- range .Values.ingress.hosts }} - host: {{ tpl .host $ | quote }} diff --git a/unittests/helm/ingress/dry-support.yaml b/unittests/helm/ingress/dry-support.yaml new file mode 100644 index 0000000..d4a0048 --- /dev/null +++ b/unittests/helm/ingress/dry-support.yaml @@ -0,0 +1,100 @@ +chart: + appVersion: 1.27.3 +release: + name: gitea-unittests + namespace: testing +suite: Test ingress +templates: + - templates/ingress.yaml +tests: + - it: Render ingress ingressClassName with paramater injection + set: + ingress.enabled: true + service.http.enabled: true + global.ingress.class: "my-ingress-class" + ingress.ingressClassName: "{{ .Values.global.ingress.class }}" + asserts: + - hasDocuments: + count: 1 + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: gitea-unittests + namespace: testing + - notExists: + path: metadata.annotations + - isSubset: + path: metadata.labels + content: + app: gitea + app.kubernetes.io/instance: gitea-unittests + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: gitea + app.kubernetes.io/version: 1.27.3 + helm.sh/chart: gitea-0.0.0 + version: 1.27.3 + - equal: + path: spec.ingressClassName + value: my-ingress-class + - contains: + path: spec.rules + content: + host: git.example.com + http: + paths: + - backend: + service: + name: gitea-unittests-http + port: + number: 3000 + path: / + pathType: Prefix + + - it: Render ingress annotations with paramater injection + set: + global.ingress.class: "my-ingress-class" + global.certificate.issuer: "my-issuer" + ingress.enabled: true + service.http.enabled: true + ingress.ingressClassName: "{{ .Values.global.ingress.class }}" + ingress.annotations: + cert-manager.io/issuer: "{{ .Values.global.certificate.issuer }}" + asserts: + - hasDocuments: + count: 1 + - containsDocument: + kind: Ingress + apiVersion: networking.k8s.io/v1 + name: gitea-unittests + namespace: testing + - exists: + path: metadata.annotations + - equal: + path: "metadata.annotations['cert-manager.io/issuer']" + value: "my-issuer" + - isSubset: + path: metadata.labels + content: + app: gitea + app.kubernetes.io/instance: gitea-unittests + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: gitea + app.kubernetes.io/version: 1.27.3 + helm.sh/chart: gitea-0.0.0 + version: 1.27.3 + - equal: + path: spec.ingressClassName + value: my-ingress-class + - contains: + path: spec.rules + content: + host: git.example.com + http: + paths: + - backend: + service: + name: gitea-unittests-http + port: + number: 3000 + path: / + pathType: Prefix \ No newline at end of file