Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions charts/automatisch/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{- end -}}

{{- define "automatisch.validate" -}}
{{- if and (not .Values.postgresql.enabled) (not .Values.database.external.host) -}}
{{- fail "database.external.host is required when postgresql.enabled is false" -}}
{{- end -}}
{{- if and (not .Values.postgresql.enabled) (not .Values.database.external.existingSecret) (not .Values.database.external.password) -}}
{{- fail "database.external.password or database.external.existingSecret is required when postgresql.enabled is false" -}}
{{- end -}}
{{- if and (not .Values.redis.enabled) (not .Values.redis_config.external.host) -}}
{{- fail "redis_config.external.host is required when redis.enabled is false" -}}
{{- end -}}
{{- if and .Values.ingress.enabled (not .Values.ingress.hosts) -}}
{{- fail "ingress.enabled requires ingress.hosts to contain at least one host" -}}
{{- end -}}
{{- if .Values.ingress.enabled -}}
{{- range $index, $host := .Values.ingress.hosts -}}
{{- if not $host.host -}}
{{- fail (printf "ingress.hosts[%d].host is required when ingress.enabled is true" $index) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $selectorLabels := include "automatisch.selectorLabels" . | fromYaml -}}
{{- range $key, $_ := .Values.podLabels -}}
{{- if hasKey $selectorLabels $key -}}
{{- fail (printf "podLabels must not override selector label %q" $key) -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "automatisch.image" -}}
{{- printf "%s:%s" .Values.image.repository .Values.image.tag -}}
{{- end -}}
Expand Down
2 changes: 2 additions & 0 deletions charts/automatisch/templates/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{/* SPDX-License-Identifier: Apache-2.0 */}}
{{- include "automatisch.validate" . -}}
67 changes: 67 additions & 0 deletions charts/automatisch/tests/validation_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-License-Identifier: Apache-2.0
suite: Validation
templates:
- templates/validate.yaml
tests:
- it: should render no validation manifest by default
asserts:
- hasDocuments:
count: 0

- it: should fail when external database host is missing
set:
postgresql.enabled: false
database.external.password: secret
asserts:
- failedTemplate:
errorMessage: "database.external.host is required when postgresql.enabled is false"

- it: should fail when external database credentials are missing
set:
postgresql.enabled: false
database.external.host: postgres.example.com
asserts:
- failedTemplate:
errorMessage: "database.external.password or database.external.existingSecret is required when postgresql.enabled is false"

- it: should fail when external redis host is missing
set:
redis.enabled: false
asserts:
- failedTemplate:
errorMessage: "redis_config.external.host is required when redis.enabled is false"

- it: should fail when ingress is enabled without hosts
set:
ingress.enabled: true
ingress.hosts: []
asserts:
- failedTemplate:
errorMessage: "ingress.enabled requires ingress.hosts to contain at least one host"

- it: should fail when an ingress host entry has no hostname
set:
ingress.enabled: true
ingress.hosts:
- paths:
- path: /
pathType: Prefix
asserts:
- failedTemplate:
errorMessage: "ingress.hosts[0].host is required when ingress.enabled is true"

- it: should fail when podLabels override selector labels
set:
podLabels:
app.kubernetes.io/name: custom
asserts:
- failedTemplate:
errorMessage: 'podLabels must not override selector label "app.kubernetes.io/name"'

- it: should fail when podLabels override release selector label
set:
podLabels:
app.kubernetes.io/instance: custom
asserts:
- failedTemplate:
errorMessage: 'podLabels must not override selector label "app.kubernetes.io/instance"'