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
24 changes: 22 additions & 2 deletions charts/archivebox/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- end -}}
{{- end -}}

{{- define "archivebox.validate" -}}
{{/* Triggers backup validation failures through archivebox.backupEnabled; the return value is unused. */}}
{{- $backupEnabled := include "archivebox.backupEnabled" . -}}
{{- 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 -}}
{{- range $key, $_ := .Values.podLabels -}}
{{- if or (eq $key "app.kubernetes.io/name") (eq $key "app.kubernetes.io/instance") -}}
{{- fail (printf "podLabels must not override selector label %q" $key) -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- define "archivebox.image" -}}
{{- printf "%s:%s" .Values.image.repository .Values.image.tag -}}
{{- end -}}
Expand Down Expand Up @@ -96,8 +116,8 @@ app.kubernetes.io/instance: {{ .Release.Name }}
{{- if not .Values.backup.s3.bucket -}}
{{- fail "backup.s3.bucket is required when backup.enabled is true" -}}
{{- end -}}
{{- if and (not .Values.backup.s3.existingSecret) (not .Values.backup.s3.accessKey) -}}
{{- fail "backup.s3.accessKey or backup.s3.existingSecret is required when backup.enabled is true" -}}
{{- if and (not .Values.backup.s3.existingSecret) (or (not .Values.backup.s3.accessKey) (not .Values.backup.s3.secretKey)) -}}
{{- fail "backup requires either backup.s3.existingSecret or both backup.s3.accessKey and backup.s3.secretKey" -}}
{{- end -}}
true
{{- end -}}
Expand Down
2 changes: 2 additions & 0 deletions charts/archivebox/templates/validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{/* SPDX-License-Identifier: Apache-2.0 */}}
{{- include "archivebox.validate" . -}}
11 changes: 11 additions & 0 deletions charts/archivebox/tests/backup_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,14 @@ tests:
asserts:
- failedTemplate:
errorMessage: "backup.s3.bucket is required when backup.enabled is true"

- it: should fail without s3 secret key
set:
backup.enabled: true
backup.s3.endpoint: http://minio:9000
backup.s3.bucket: backups
backup.s3.accessKey: admin
template: backup-cronjob.yaml
asserts:
- failedTemplate:
errorMessage: "backup requires either backup.s3.existingSecret or both backup.s3.accessKey and backup.s3.secretKey"
55 changes: 55 additions & 0 deletions charts/archivebox/tests/validation_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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 backup endpoint is missing
set:
backup.enabled: true
backup.s3.bucket: backups
backup.s3.accessKey: access
backup.s3.secretKey: secret
asserts:
- failedTemplate:
errorMessage: "backup.s3.endpoint is required when backup.enabled is true"

- it: should fail when backup credentials are missing
set:
backup.enabled: true
backup.s3.endpoint: http://minio:9000
backup.s3.bucket: backups
asserts:
- failedTemplate:
errorMessage: "backup requires either backup.s3.existingSecret or both backup.s3.accessKey and backup.s3.secretKey"

- 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: archivebox-custom
asserts:
- failedTemplate:
errorMessage: 'podLabels must not override selector label "app.kubernetes.io/name"'