From 24765b5ccc0ac5a397932cb6a2694800152348f1 Mon Sep 17 00:00:00 2001 From: Felix Scheinost Date: Tue, 17 Oct 2023 15:51:43 +0200 Subject: [PATCH] helm: add support for `--api-versions` --- lib/helm/chart2json.nix | 3 +++ modules/helm.nix | 13 ++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/helm/chart2json.nix b/lib/helm/chart2json.nix index 67ded8e..bd9a5a0 100644 --- a/lib/helm/chart2json.nix +++ b/lib/helm/chart2json.nix @@ -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}"} \ diff --git a/modules/helm.nix b/modules/helm.nix index 563dfb0..10a5981 100644 --- a/modules/helm.nix +++ b/modules/helm.nix @@ -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; @@ -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 = { };