diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index ee6aefe..9c8e289 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -50,6 +50,7 @@ image: - 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 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 diff --git a/README.md b/README.md index 18797cd..1c2a969 100644 --- a/README.md +++ b/README.md @@ -1146,7 +1146,7 @@ To comply with the Gitea helm chart definition of the digest parameter, a "custo | `ingress.enabled` | Enable ingress | `false` | | `ingress.annotations` | Additional annotations. | `{}` | | `ingress.labels` | Additional labels. | `{}` | -| `ingress.className` | DEPRECATED: Ingress class name. | `""` | +| `ingress.className` | DEPRECATED: Ingress class name. | `nginx` | | `ingress.pathType` | Ingress Path Type | `Prefix` | | `ingress.hosts[0].host` | Default Ingress host | `git.example.com` | | `ingress.hosts[0].paths[0].path` | Default Ingress path | `/` | diff --git a/templates/gitea/_ingresses.tpl b/templates/gitea/_ingresses.tpl index 741dd32..e4454db 100644 --- a/templates/gitea/_ingresses.tpl +++ b/templates/gitea/_ingresses.tpl @@ -8,6 +8,14 @@ {{- end }} {{- end }} +{{- define "gitea.ingress.enabled" -}} +{{- if and .Values.ingress.enabled .Values.service.http.enabled -}} +true +{{- else -}} +false +{{- end }} +{{- end }} + {{/* labels */}} {{- define "gitea.ingress.labels" -}} diff --git a/templates/gitea/ingress.yaml b/templates/gitea/ingress.yaml index 5b1cf74..0095f89 100644 --- a/templates/gitea/ingress.yaml +++ b/templates/gitea/ingress.yaml @@ -1,4 +1,4 @@ -{{- if .Values.ingress.enabled -}} +{{- if eq (include "gitea.ingress.enabled" .) "true" -}} --- apiVersion: networking.k8s.io/v1 kind: Ingress @@ -12,7 +12,7 @@ metadata: {{- . | nindent 4 }} {{- end }} name: {{ include "gitea.ingress.name" . }} - namespace: {{ .Values.namespace | default .Release.Namespace }} + namespace: {{ .Release.Namespace }} spec: ingressClassName: {{ tpl .Values.ingress.className . }} {{- if .Values.ingress.tls }} diff --git a/unittests/helm/deployment/ingress-configuration.yaml b/unittests/helm/deployment/ingress-configuration.yaml deleted file mode 100644 index 5136c1c..0000000 --- a/unittests/helm/deployment/ingress-configuration.yaml +++ /dev/null @@ -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" diff --git a/unittests/helm/ingress/basic.yaml b/unittests/helm/ingress/basic.yaml deleted file mode 100644 index 733e557..0000000 --- a/unittests/helm/ingress/basic.yaml +++ /dev/null @@ -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" diff --git a/unittests/helm/ingress/implicit-defaults.yaml b/unittests/helm/ingress/implicit-defaults.yaml deleted file mode 100644 index 2337286..0000000 --- a/unittests/helm/ingress/implicit-defaults.yaml +++ /dev/null @@ -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" diff --git a/unittests/helm/ingress/ingress.tpl.yaml b/unittests/helm/ingress/ingress.tpl.yaml deleted file mode 100644 index 5136c1c..0000000 --- a/unittests/helm/ingress/ingress.tpl.yaml +++ /dev/null @@ -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" diff --git a/unittests/helm/ingress/ingress.yaml b/unittests/helm/ingress/ingress.yaml new file mode 100644 index 0000000..b201648 --- /dev/null +++ b/unittests/helm/ingress/ingress.yaml @@ -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 \ No newline at end of file diff --git a/unittests/helm/ingress/structured-paths.yaml b/unittests/helm/ingress/structured-paths.yaml deleted file mode 100644 index 3183ac7..0000000 --- a/unittests/helm/ingress/structured-paths.yaml +++ /dev/null @@ -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" diff --git a/values.yaml b/values.yaml index 5ca937d..6d65745 100644 --- a/values.yaml +++ b/values.yaml @@ -599,7 +599,7 @@ ingress: enabled: false annotations: {} labels: {} - className: "" + className: "nginx" pathType: Prefix hosts: - host: git.example.com