helm: don't filter anything before it hits Nix
This commit is contained in:
parent
7941d48ea9
commit
672d465dc6
1 changed files with 24 additions and 22 deletions
|
|
@ -1,45 +1,47 @@
|
|||
{ runCommand, lib, kubernetes-helm, yq }:
|
||||
{
|
||||
runCommand,
|
||||
lib,
|
||||
kubernetes-helm,
|
||||
yq,
|
||||
}:
|
||||
with lib;
|
||||
{
|
||||
# chart to template
|
||||
chart
|
||||
chart,
|
||||
# release name
|
||||
, name
|
||||
name,
|
||||
# namespace to install release into
|
||||
, namespace ? null
|
||||
namespace ? null,
|
||||
# values to pass to chart
|
||||
, values ? { }
|
||||
values ? { },
|
||||
# kubernetes version to template chart for
|
||||
, kubeVersion ? null
|
||||
kubeVersion ? null,
|
||||
# whether to include CRD
|
||||
, includeCRDs ? false
|
||||
includeCRDs ? false,
|
||||
# whether to include hooks
|
||||
, noHooks ? false
|
||||
noHooks ? false,
|
||||
# Kubernetes api versions used for Capabilities.APIVersions (--api-versions)
|
||||
, apiVersions ? null
|
||||
apiVersions ? null,
|
||||
}:
|
||||
let
|
||||
valuesJsonFile = builtins.toFile "${name}-values.json" (builtins.toJSON values);
|
||||
# The `helm template` and YAML -> JSON steps are separate `runCommand` derivations for easier debuggability
|
||||
resourcesYaml = runCommand "${name}.yaml" { nativeBuildInputs = [ kubernetes-helm ]; } ''
|
||||
helm template "${name}" \
|
||||
${optionalString (apiVersions != null && apiVersions != []) "--api-versions ${lib.strings.concatStringsSep "," apiVersions}"} \
|
||||
${
|
||||
optionalString (
|
||||
apiVersions != null && apiVersions != [ ]
|
||||
) "--api-versions ${lib.strings.concatStringsSep "," apiVersions}"
|
||||
} \
|
||||
${optionalString (kubeVersion != null) "--kube-version ${kubeVersion}"} \
|
||||
${optionalString (namespace != null) "--namespace ${namespace}"} \
|
||||
${optionalString (values != {}) "-f ${valuesJsonFile}"} \
|
||||
${optionalString (values != { }) "-f ${valuesJsonFile}"} \
|
||||
${optionalString includeCRDs "--include-crds"} \
|
||||
${optionalString noHooks "--no-hooks"} \
|
||||
${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
|
||||
''
|
||||
runCommand "${name}.json" { } # bash
|
||||
''
|
||||
${yq}/bin/yq -Scs '.' ${resourcesYaml} >$out
|
||||
''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue