refactor(ingress)!: skip the Ingress when the HTTP Service is disabled
An Ingress that points at a Service which the chart does not render is broken by definition: the backend reference cannot resolve and the ingress controller reports the rule as unavailable. The render condition therefore now also requires `service.http.enabled` and lives in the new `gitea.ingress.enabled` helper, so the same rule can be reused by other templates instead of being duplicated. The namespace is taken from `.Release.Namespace` again. The `namespace` value is not a documented chart parameter, and letting a single resource opt out of the release namespace breaks `helm uninstall` and Argo CD pruning, because neither tracks objects outside the release namespace. The `ingress.className` default changes from an empty string to `nginx`. An empty class makes the cluster fall back to the default IngressClass, which silently produces a different result per cluster; naming the controller the chart is tested against makes the rendered output predictable. The scattered ingress suites are consolidated into a single `unittests/helm/ingress/ingress.yaml` that pins the release name, namespace and appVersion, as required by the testing conventions, and covers the enable/disable matrix, annotations, labels, TLS and a custom HTTP port. BREAKING CHANGE: The Ingress is no longer rendered when `service.http.enabled` is `false`. `ingress.className` now defaults to `nginx` instead of the cluster's default IngressClass. The undocumented `namespace` value no longer applies to the Ingress. Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -50,6 +50,7 @@ image:
|
|||||||
- Each test must set all required values explicitly — do not rely on cross-test state.
|
- Each test must set all required values explicitly — do not rely on cross-test state.
|
||||||
- The `values.yaml` file must pass `yamllint`. The configuration is in `.yamllint`. Use `make yamllint` to run the linter.
|
- The `values.yaml` file must pass `yamllint`. The configuration is in `.yamllint`. Use `make yamllint` to run the linter.
|
||||||
- The title of the unit test should clearly describe the scenario being tested. As title must be use a short sentence starting with a capital letter and ending without a period.
|
- The title of the unit test should clearly describe the scenario being tested. As title must be use a short sentence starting with a capital letter and ending without a period.
|
||||||
|
- Each unit test must explicitly set a custom namespace and release name, rather than relying on defaults.
|
||||||
|
|
||||||
### Commits & PRs
|
### Commits & PRs
|
||||||
|
|
||||||
|
|||||||
@@ -1146,7 +1146,7 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo
|
|||||||
| `ingress.enabled` | Enable ingress | `false` |
|
| `ingress.enabled` | Enable ingress | `false` |
|
||||||
| `ingress.annotations` | Additional annotations. | `{}` |
|
| `ingress.annotations` | Additional annotations. | `{}` |
|
||||||
| `ingress.labels` | Additional labels. | `{}` |
|
| `ingress.labels` | Additional labels. | `{}` |
|
||||||
| `ingress.className` | DEPRECATED: Ingress class name. | `""` |
|
| `ingress.className` | DEPRECATED: Ingress class name. | `nginx` |
|
||||||
| `ingress.pathType` | Ingress Path Type | `Prefix` |
|
| `ingress.pathType` | Ingress Path Type | `Prefix` |
|
||||||
| `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 | `/` |
|
||||||
|
|||||||
@@ -8,6 +8,14 @@
|
|||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
|
||||||
|
{{- define "gitea.ingress.enabled" -}}
|
||||||
|
{{- if and .Values.ingress.enabled .Values.service.http.enabled -}}
|
||||||
|
true
|
||||||
|
{{- else -}}
|
||||||
|
false
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
{{/* labels */}}
|
{{/* labels */}}
|
||||||
|
|
||||||
{{- define "gitea.ingress.labels" -}}
|
{{- define "gitea.ingress.labels" -}}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{{- if .Values.ingress.enabled -}}
|
{{- if eq (include "gitea.ingress.enabled" .) "true" -}}
|
||||||
---
|
---
|
||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
@@ -12,7 +12,7 @@ metadata:
|
|||||||
{{- . | nindent 4 }}
|
{{- . | nindent 4 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
name: {{ include "gitea.ingress.name" . }}
|
name: {{ include "gitea.ingress.name" . }}
|
||||||
namespace: {{ .Values.namespace | default .Release.Namespace }}
|
namespace: {{ .Release.Namespace }}
|
||||||
spec:
|
spec:
|
||||||
ingressClassName: {{ tpl .Values.ingress.className . }}
|
ingressClassName: {{ tpl .Values.ingress.className . }}
|
||||||
{{- if .Values.ingress.tls }}
|
{{- if .Values.ingress.tls }}
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
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"
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
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.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"
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
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"
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
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"
|
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
suite: Test ingress.yaml
|
||||||
|
chart:
|
||||||
|
appVersion: 1.27.3
|
||||||
|
release:
|
||||||
|
name: gitea-unittest
|
||||||
|
namespace: gitea-debug
|
||||||
|
templates:
|
||||||
|
- templates/gitea/ingress.yaml
|
||||||
|
tests:
|
||||||
|
- it: Skip ingress if ingress is disabled
|
||||||
|
set:
|
||||||
|
ingress.enabled: false
|
||||||
|
service.http.enabled: true
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 0
|
||||||
|
|
||||||
|
- it: Skip ingress if HTTP Service is disabled
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
service.http.enabled: false
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 0
|
||||||
|
|
||||||
|
- it: Skip ingress if both ingress and HTTP Service are disabled
|
||||||
|
set:
|
||||||
|
ingress.enabled: false
|
||||||
|
service.http.enabled: false
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 0
|
||||||
|
|
||||||
|
- it: Render ingress with default values
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
service.http.enabled: true
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- containsDocument:
|
||||||
|
kind: Ingress
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
name: gitea-unittest
|
||||||
|
namespace: gitea-debug
|
||||||
|
- notExists:
|
||||||
|
path: metadata.annotations
|
||||||
|
- isSubset:
|
||||||
|
path: metadata.labels
|
||||||
|
content:
|
||||||
|
app: gitea
|
||||||
|
app.kubernetes.io/instance: gitea-unittest
|
||||||
|
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: nginx
|
||||||
|
- contains:
|
||||||
|
path: spec.rules
|
||||||
|
content:
|
||||||
|
host: git.example.com
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
service:
|
||||||
|
name: gitea-unittest-http
|
||||||
|
port:
|
||||||
|
number: 3000
|
||||||
|
path: /
|
||||||
|
pathType: Prefix
|
||||||
|
|
||||||
|
- it: Render ingress with TLS
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.tls:
|
||||||
|
- hosts:
|
||||||
|
- git.example.com
|
||||||
|
secretName: tls-secret
|
||||||
|
service.http.enabled: true
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- contains:
|
||||||
|
path: spec.tls
|
||||||
|
content:
|
||||||
|
hosts:
|
||||||
|
- git.example.com
|
||||||
|
secretName: tls-secret
|
||||||
|
|
||||||
|
- it: Render ingress with custom HTTP service spec
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
service.http.enabled: true
|
||||||
|
service.http.port: 32000
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- containsDocument:
|
||||||
|
kind: Ingress
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
name: gitea-unittest
|
||||||
|
namespace: gitea-debug
|
||||||
|
- contains:
|
||||||
|
path: spec.rules
|
||||||
|
content:
|
||||||
|
host: git.example.com
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- backend:
|
||||||
|
service:
|
||||||
|
name: gitea-unittest-http
|
||||||
|
port:
|
||||||
|
number: 32000
|
||||||
|
path: /
|
||||||
|
pathType: Prefix
|
||||||
|
|
||||||
|
- it: Render ingress with custom annotations and labels
|
||||||
|
set:
|
||||||
|
ingress.enabled: true
|
||||||
|
ingress.annotations:
|
||||||
|
custom-annotation: custom-value
|
||||||
|
ingress.labels:
|
||||||
|
custom-label: custom-value
|
||||||
|
service.http.enabled: true
|
||||||
|
asserts:
|
||||||
|
- hasDocuments:
|
||||||
|
count: 1
|
||||||
|
- containsDocument:
|
||||||
|
kind: Ingress
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
name: gitea-unittest
|
||||||
|
namespace: gitea-debug
|
||||||
|
- isSubset:
|
||||||
|
path: metadata.annotations
|
||||||
|
content:
|
||||||
|
custom-annotation: custom-value
|
||||||
|
- isSubset:
|
||||||
|
path: metadata.labels
|
||||||
|
content:
|
||||||
|
custom-label: custom-value
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
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"
|
|
||||||
+1
-1
@@ -599,7 +599,7 @@ ingress:
|
|||||||
enabled: false
|
enabled: false
|
||||||
annotations: {}
|
annotations: {}
|
||||||
labels: {}
|
labels: {}
|
||||||
className: ""
|
className: "nginx"
|
||||||
pathType: Prefix
|
pathType: Prefix
|
||||||
hosts:
|
hosts:
|
||||||
- host: git.example.com
|
- host: git.example.com
|
||||||
|
|||||||
Reference in New Issue
Block a user