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

<!-- [Place an '[X]' (no spaces) in all applicable fields. Please remove unrelated fields.] -->

- [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>
This commit is contained in:
Ceddaerrix authored and Markus Pesch committed 2026-12-04 17:08:33 +00:00
1 parent 304f50981d
commit ddd0290b55
2 files changed
+104 -4

No files matched your search

+4 -4
View File
@@ -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 }}
+100
View File
@@ -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