helm-charts/charts/library/common/templates/lib/configMap/_validate.tpl
Bernd Schorgers a01a89cb13
feat(common): Release common 4.0.0 (#398)
Co-authored-by: lab-assistant[bot] <180935599+lab-assistant[bot]@users.noreply.github.com>
2025-05-16 08:55:14 +02:00

32 lines
1.4 KiB
Smarty

{{/*
Validate configMap values
*/}}
{{- define "bjw-s.common.lib.configMap.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $configMapValues := .object -}}
{{- $identifier := .id -}}
{{- if eq (len (without (keys $configMapValues) "name" "identifier")) 0 -}}
{{- fail (printf "There was an error loading ConfigMap: %s. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`" $identifier) -}}
{{- end -}}
{{- if and (empty (get $configMapValues "data")) (empty (get $configMapValues "binaryData")) -}}
{{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }}
{{- end -}}
{{- end -}}
{{/*
Validate configMap from folder values
*/}}
{{- define "bjw-s.common.lib.configMap.fromFolder.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $basePath := required "If you're using `configMapsFromFolder` you need to specify a `basePath` key" .basePath -}}
{{ $topLevelFolders := dict}}
{{- range $path, $_ := $rootContext.Files.Glob (printf "%s/*/*" $basePath) -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}}
{{- $topLevelFoldersList := keys $topLevelFolders | sortAlpha -}}
{{- if empty $topLevelFoldersList -}}
{{- fail (printf "No configMaps found in the folder %s" $basePath) }}
{{- end -}}
{{- end -}}