Skip to content

Commit

Permalink
Add a validation to check if there is any yaml errors after merging f…
Browse files Browse the repository at this point in the history
…iles
  • Loading branch information
stavros-k committed Mar 9, 2023
1 parent 7d837e9 commit 024b5f1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions library/common/1.0.0/templates/loader/_apply.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{{/* Loads all spawners */}}
{{- define "ix.v1.common.loader.apply" -}}

{{/* Make sure there are not any YAML errors */}}
{{- include "ix.v1.common.values.validate" .Values -}}

{{/* Render ConfigMap(s) */}}
{{- include "ix.v1.common.spawner.configmap" . | nindent 0 -}}

Expand Down
18 changes: 18 additions & 0 deletions library/common/1.0.0/templates/values/_validate.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{/* Validates any object that it does not contain helm errors */}}
{{/* This usually can happen after merging values from an include that did not render correcly */}}
{{/* Any object will be passed to "toYaml" */}}
{{/* Call this template:
{{ include "ix.v1.common.values.validate" . }}
*/}}
{{- define "ix.v1.common.values.validate" -}}
{{- $allValues := (toYaml .) -}}

{{- if contains "error converting YAML to JSON" $allValues -}}
{{/* Print values to show values with the error included. */}}
{{/* Ideally we would want to extract the error only, but because it usually contains ":",
It gets parsed as dict and it cant regex matched it afterwards */}}

{{- fail (printf "Chart - Values contain an error that may be a result of merging. Values containing the error: \n\n %v \n\n See error above values." $allValues) -}}
{{- end -}}

{{- end -}}

0 comments on commit 024b5f1

Please sign in to comment.