2019-02-28 13:17:40 +01:00
|
|
|
{
|
2023-06-19 18:14:20 +02:00
|
|
|
runCommand,
|
2022-04-02 12:40:35 -07:00
|
|
|
lib,
|
|
|
|
|
kubernetes-helm,
|
2023-06-19 18:14:20 +02:00
|
|
|
yq,
|
2021-05-13 17:27:08 -04:00
|
|
|
}:
|
2022-04-02 12:40:35 -07:00
|
|
|
with lib;
|
|
|
|
|
{
|
|
|
|
|
# chart to template
|
|
|
|
|
chart,
|
|
|
|
|
# release name
|
|
|
|
|
name,
|
|
|
|
|
# namespace to install release into
|
|
|
|
|
namespace ? null,
|
|
|
|
|
# values to pass to chart
|
|
|
|
|
values ? {},
|
|
|
|
|
# kubernetes version to template chart for
|
|
|
|
|
kubeVersion ? null,
|
2023-02-28 02:22:59 +01:00
|
|
|
# whether to include CRD
|
2023-06-03 03:11:07 -04:00
|
|
|
includeCRDs ? false,
|
2023-06-12 02:41:00 -04:00
|
|
|
# whether to include hooks
|
|
|
|
|
noHooks ? false,
|
2022-04-02 12:40:35 -07:00
|
|
|
}: let
|
|
|
|
|
valuesJsonFile = builtins.toFile "${name}-values.json" (builtins.toJSON values);
|
2023-06-19 18:14:20 +02:00
|
|
|
# The `helm template` and YAML -> JSON steps are separate `runCommand` derivations for easier debuggability
|
|
|
|
|
resourcesYaml = runCommand "${name}.yaml" {nativeBuildInputs = [kubernetes-helm];} ''
|
|
|
|
|
helm template "${name}" \
|
2023-01-18 00:27:56 -05:00
|
|
|
${optionalString (kubeVersion != null) "--kube-version ${kubeVersion}"} \
|
2022-04-02 12:40:35 -07:00
|
|
|
${optionalString (namespace != null) "--namespace ${namespace}"} \
|
|
|
|
|
${optionalString (values != {}) "-f ${valuesJsonFile}"} \
|
2023-06-03 03:11:07 -04:00
|
|
|
${optionalString includeCRDs "--include-crds"} \
|
2023-06-12 02:41:00 -04:00
|
|
|
${optionalString noHooks "--no-hooks"} \
|
2023-06-19 18:14:20 +02:00
|
|
|
${chart} >$out
|
|
|
|
|
'';
|
|
|
|
|
in
|
|
|
|
|
runCommand "${name}.json" {} ''
|
|
|
|
|
# Remove null values
|
|
|
|
|
${yq}/bin/yq -Scs 'walk(
|
|
|
|
|
if type == "object" then
|
|
|
|
|
with_entries(select(.value != null))
|
|
|
|
|
elif type == "array" then
|
|
|
|
|
map(select(. != null))
|
|
|
|
|
else
|
|
|
|
|
.
|
|
|
|
|
end)' ${resourcesYaml} >$out
|
|
|
|
|
''
|