Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helm: add support for --api-versions #38

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/helm/chart2json.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ with lib;
, includeCRDs ? false
# whether to include hooks
, noHooks ? false
# Kubernetes api versions used for Capabilities.APIVersions (--api-versions)
, 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 (kubeVersion != null) "--kube-version ${kubeVersion}"} \
${optionalString (namespace != null) "--namespace ${namespace}"} \
${optionalString (values != {}) "-f ${valuesJsonFile}"} \
Expand Down
13 changes: 12 additions & 1 deletion modules/helm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ in
default = false;
};

apiVersions = mkOption {
description = ''
Inform Helm about which CRDs are available in the cluster (`--api-versions` option).
This is useful for charts which contain `.Capabilities.APIVersions.Has` checks.
If you use `kubernetes.customTypes` to make kubenix aware of CRDs, it will include those as well by default.
'';
type = types.listOf types.str;
default = builtins.map (customType: "${customType.group}/${customType.version}")
(builtins.attrValues globalConfig.kubernetes.customTypes);
};

objects = mkOption {
description = "Generated kubernetes objects";
type = types.listOf types.attrs;
Expand All @@ -111,7 +122,7 @@ in
}];

config.objects = importJSON (helm.chart2json {
inherit (config) chart name namespace values kubeVersion includeCRDs noHooks;
inherit (config) chart name namespace values kubeVersion includeCRDs noHooks apiVersions;
});
}));
default = { };
Expand Down
Loading