Skip to content

Commit e05a7d1

Browse files
committed
add fast fail for lightspeed files
Signed-off-by: Jordan Dubrick <jdubrick@redhat.com>
1 parent efb917f commit e05a7d1

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

charts/backstage/templates/_helpers.tpl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,26 @@ Return the relative path for a Lightspeed payload file.
206206

207207
{{/*
208208
Return rendered content of a Lightspeed payload file.
209+
210+
When optional=false is passed, fail fast if the referenced payload file is missing.
209211
*/}}
210212
{{- define "rhdh.lightspeed.fileContent" -}}
211213
{{- $path := include "rhdh.lightspeed.filePath" .file -}}
212214
{{- $content := .context.Files.Get $path -}}
213-
{{- if and (empty $content) .context.Subcharts (hasKey .context.Subcharts "upstream") -}}
214-
{{- $content = .context.Subcharts.upstream.Files.Get $path -}}
215+
{{- $exists := gt (len (.context.Files.Glob $path)) 0 -}}
216+
{{- if and .context.Subcharts (hasKey .context.Subcharts "upstream") -}}
217+
{{- $upstreamExists := gt (len (.context.Subcharts.upstream.Files.Glob $path)) 0 -}}
218+
{{- if and (empty $content) $upstreamExists -}}
219+
{{- $content = .context.Subcharts.upstream.Files.Get $path -}}
220+
{{- end -}}
221+
{{- $exists = or $exists $upstreamExists -}}
222+
{{- end -}}
223+
{{- if and (hasKey . "optional") (not .optional) -}}
224+
{{- $message := printf "missing required Lightspeed payload file %s" $path -}}
225+
{{- if hasKey . "ref" -}}
226+
{{- $message = printf "%s referenced by %s" $message .ref -}}
227+
{{- end -}}
228+
{{- $_ := required $message (ternary $path "" $exists) -}}
215229
{{- end -}}
216230
{{- $content -}}
217231
{{- end -}}
@@ -225,7 +239,11 @@ Return the stringData map for the Lightspeed Secret.
225239
{{- $context = get . "context" -}}
226240
{{- end -}}
227241
{{- $lightspeed := include "rhdh.lightspeed.resolve" (dict "context" $context "input" .) | fromYaml -}}
228-
{{- include "rhdh.lightspeed.fileContent" (dict "context" $context "file" $lightspeed.secret.sourceFile) | fromYaml | toYaml -}}
242+
{{- if not $lightspeed.secret.create -}}
243+
{{- dict | toYaml -}}
244+
{{- else -}}
245+
{{- include "rhdh.lightspeed.fileContent" (dict "context" $context "file" $lightspeed.secret.sourceFile "optional" $lightspeed.secret.optional "ref" "global.lightspeed.secret.sourceFile") | fromYaml | toYaml -}}
246+
{{- end -}}
229247
{{- end -}}
230248

231249
{{/*
@@ -246,7 +264,7 @@ Return the Lightspeed ConfigMap payloads for checksum calculation.
246264
"subPath" .subPath
247265
"sourceFile" .sourceFile
248266
"optional" .optional
249-
"content" (include "rhdh.lightspeed.fileContent" (dict "context" $context "file" .sourceFile))
267+
"content" (include "rhdh.lightspeed.fileContent" (dict "context" $context "file" .sourceFile "optional" .optional "ref" (printf "global.lightspeed.configMaps[%s].sourceFile" .name)))
250268
) -}}
251269
{{- end -}}
252270
{{- toJson $configMaps -}}

charts/backstage/vendor/backstage/charts/backstage/templates/lightspeed-configmaps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ metadata:
1111
namespace: {{ $.Release.Namespace | quote }}
1212
data:
1313
{{ $configMap.subPath }}: |
14-
{{ include "rhdh.lightspeed.fileContent" (dict "context" $ "file" $configMap.sourceFile) | nindent 4 }}
14+
{{ include "rhdh.lightspeed.fileContent" (dict "context" $ "file" $configMap.sourceFile "optional" $configMap.optional "ref" (printf "global.lightspeed.configMaps[%s].sourceFile" $configMap.name)) | nindent 4 }}
1515
{{- end }}
1616
{{- end }}

0 commit comments

Comments
 (0)