add values validation

This commit is contained in:
Jonas Leder 2026-08-08 21:53:03 +02:00
commit 0720dc3996
3 changed files with 127 additions and 0 deletions

View file

@ -0,0 +1,124 @@
{{/*
Validate .Values and fail the render with a full list of problems instead of
letting a bad combination surface later as a broken pod.
*/}}
{{- define "nextcloud.validateValues" -}}
{{- $messages := list -}}
{{- if not .Values.image.repository -}}
{{- $messages = append $messages "image.repository must be set" -}}
{{- end -}}
{{- if not .Values.nextcloud.hostname -}}
{{- $messages = append $messages "nextcloud.hostname must be set" -}}
{{- end -}}
{{- if and (not .Values.nextcloud.admin.password) (not .Values.nextcloud.admin.existingSecret) -}}
{{- $messages = append $messages "nextcloud.admin.password or nextcloud.admin.existingSecret must be set" -}}
{{- end -}}
{{- if not (has .Values.service.type (list "ClusterIP" "NodePort" "LoadBalancer" "ExternalName")) -}}
{{- $messages = append $messages (printf "service.type must be one of ClusterIP, NodePort, LoadBalancer, ExternalName (got %q)" .Values.service.type) -}}
{{- end -}}
{{- if not (has .Values.storage.accessMode (list "ReadWriteOnce" "ReadWriteMany" "ReadOnlyMany" "ReadWriteOncePod")) -}}
{{- $messages = append $messages (printf "storage.accessMode must be one of ReadWriteOnce, ReadWriteMany, ReadOnlyMany, ReadWriteOncePod (got %q)" .Values.storage.accessMode) -}}
{{- end -}}
{{- if .Values.storage.useExistingPvc -}}
{{- if not .Values.storage.existingPvc -}}
{{- $messages = append $messages "storage.existingPvc must be set when storage.useExistingPvc is true" -}}
{{- end -}}
{{- else if not .Values.storage.storage -}}
{{- $messages = append $messages "storage.storage must be set when storage.useExistingPvc is false" -}}
{{- end -}}
{{- if .Values.postgresql.enabled -}}
{{- if .Values.postgresql.persistence.useExistingPvc -}}
{{- if not .Values.postgresql.persistence.existingPvcName -}}
{{- $messages = append $messages "postgresql.persistence.existingPvcName must be set when postgresql.persistence.useExistingPvc is true" -}}
{{- end -}}
{{- else if not .Values.postgresql.persistence.size -}}
{{- $messages = append $messages "postgresql.persistence.size must be set when postgresql.persistence.useExistingPvc is false" -}}
{{- end -}}
{{- if not .Values.postgresql.image.repository -}}
{{- $messages = append $messages "postgresql.image.repository must be set when postgresql.enabled is true" -}}
{{- end -}}
{{- else if not .Values.postgresql.externalHostname -}}
{{- $messages = append $messages "postgresql.externalHostname must be set when postgresql.enabled is false" -}}
{{- end -}}
{{- if not .Values.postgresql.auth.database -}}
{{- $messages = append $messages "postgresql.auth.database must be set" -}}
{{- end -}}
{{- if not .Values.postgresql.auth.username -}}
{{- $messages = append $messages "postgresql.auth.username must be set" -}}
{{- end -}}
{{- if not .Values.postgresql.auth.password.secretName -}}
{{- $messages = append $messages "postgresql.auth.password.secretName must be set (this chart never creates the postgres password secret itself)" -}}
{{- end -}}
{{- if not .Values.postgresql.auth.password.secretKey -}}
{{- $messages = append $messages "postgresql.auth.password.secretKey must be set" -}}
{{- end -}}
{{- if .Values.valkey.enabled -}}
{{- if .Values.valkey.persistence.useExistingPvc -}}
{{- if not .Values.valkey.persistence.existingPvcName -}}
{{- $messages = append $messages "valkey.persistence.existingPvcName must be set when valkey.persistence.useExistingPvc is true" -}}
{{- end -}}
{{- else if not .Values.valkey.persistence.size -}}
{{- $messages = append $messages "valkey.persistence.size must be set when valkey.persistence.useExistingPvc is false" -}}
{{- end -}}
{{- if not .Values.valkey.image.repository -}}
{{- $messages = append $messages "valkey.image.repository must be set when valkey.enabled is true" -}}
{{- end -}}
{{- else if not .Values.valkey.externalHostname -}}
{{- $messages = append $messages "valkey.externalHostname must be set when valkey.enabled is false" -}}
{{- end -}}
{{- if eq (.Values.valkey.databasePhp | toString) (.Values.valkey.databaseNextcloud | toString) -}}
{{- $messages = append $messages "valkey.databasePhp and valkey.databaseNextcloud must be different redis database indexes" -}}
{{- end -}}
{{- if .Values.ingress.enabled -}}
{{- if not .Values.ingress.hosts -}}
{{- $messages = append $messages "ingress.hosts must not be empty when ingress.enabled is true" -}}
{{- end -}}
{{- range .Values.ingress.hosts -}}
{{- if not .host -}}
{{- $messages = append $messages "every entry in ingress.hosts must set host" -}}
{{- end -}}
{{- if not .paths -}}
{{- $messages = append $messages (printf "ingress host %q must define at least one path" .host) -}}
{{- end -}}
{{- end -}}
{{- range .Values.ingress.tls -}}
{{- if not .secretName -}}
{{- $messages = append $messages "every entry in ingress.tls must set secretName" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if .Values.autoscaling.enabled -}}
{{- if gt (int .Values.autoscaling.minReplicas) (int .Values.autoscaling.maxReplicas) -}}
{{- $messages = append $messages "autoscaling.minReplicas must not be greater than autoscaling.maxReplicas" -}}
{{- end -}}
{{- if and (not .Values.autoscaling.targetCPUUtilizationPercentage) (not .Values.autoscaling.targetMemoryUtilizationPercentage) -}}
{{- $messages = append $messages "autoscaling.targetCPUUtilizationPercentage or autoscaling.targetMemoryUtilizationPercentage must be set when autoscaling.enabled is true" -}}
{{- end -}}
{{- end -}}
{{- if and (not .Values.serviceAccount.create) .Values.serviceAccount.automount -}}
{{- /* not an error, just noting automount only affects service accounts this chart creates */ -}}
{{- end -}}
{{- if .Values.cron.enabled -}}
{{- if not .Values.cron.resources -}}
{{- $messages = append $messages "cron.resources must be set when cron.enabled is true" -}}
{{- end -}}
{{- end -}}
{{- if $messages -}}
{{- fail (printf "\n\nnextcloud chart values are invalid:\n - %s\n" (join "\n - " $messages)) -}}
{{- end -}}
{{- end -}}

View file

@ -1,3 +1,4 @@
{{- include "nextcloud.validateValues" . -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:

View file

@ -136,6 +136,8 @@ postgresql:
database: nextcloud
username: nextcloud
password:
# Required: a secret with this name and key must exist (this chart never
# creates it, so a default password is never checked into git).
secretName: ""
secretKey: "password"
persistence: