@@ -206,12 +206,26 @@ Return the relative path for a Lightspeed payload file.
206206
207207{{/*
208208Return 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 -}}
0 commit comments