mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
Remarshal doesn’t seem to be maintained anymore. It is also affected by upstream bugs like https://github.com/yaml/pyyaml/issues/89 which affects e.g. prometheus-operator CRDs.
46 lines
1.4 KiB
Nix
46 lines
1.4 KiB
Nix
{
|
|
runCommand,
|
|
lib,
|
|
kubernetes-helm,
|
|
yq,
|
|
}:
|
|
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,
|
|
# whether to include CRD
|
|
includeCRDs ? false,
|
|
# whether to include hooks
|
|
noHooks ? false,
|
|
}: 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 (kubeVersion != null) "--kube-version ${kubeVersion}"} \
|
|
${optionalString (namespace != null) "--namespace ${namespace}"} \
|
|
${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
|
|
''
|