diff --git a/helm.nix b/helm.nix index 8dc9505..7b445bc 100644 --- a/helm.nix +++ b/helm.nix @@ -89,12 +89,11 @@ in apiVersions = mkOption { description = '' - Inform Helm about which CRDs are available in the cluster (`--api-versions` option). + Inform Helm about which API versions 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 = lib.attrValues globalConfig.kubernetes.apiMappings; + default = [ ]; }; objects = mkOption { @@ -143,24 +142,45 @@ in }; }; - config = { - kubernetes.objects = lib.pipe cfg.releases [ - (lib.mapAttrsToList ( - _: release: lib.map (object: lib.pipe object release.overrides) release.objects - )) - lib.flatten - (lib.map ( - object: - let - kind = object.kind or (throw "no kind for ${object}"); - name = object.metadata.name or (throw "no name for ${object}"); - namespace = object.metadata.namespace or "none"; - in - { - ${namespace}.${kind}.${name} = object; - } - )) - lib.mkMerge - ]; - }; + config = + let + allObjects = lib.pipe cfg.releases [ + (lib.mapAttrsToList ( + _: release: lib.map (object: lib.pipe object release.overrides) release.objects + )) + lib.flatten + ]; + in + { + kubernetes.objects = lib.pipe allObjects [ + (lib.map ( + object: + let + kind = object.kind or (throw "no kind for ${object}"); + name = object.metadata.name or (throw "no name for ${object}"); + namespace = object.metadata.namespace or "none"; + in + { + ${namespace}.${kind}.${name} = object; + } + )) + lib.mkMerge + ]; + kubernetes.apiMappings = lib.pipe allObjects [ + (lib.filter (object: object.kind or null == "CustomResourceDefinition")) + (map (crd: { + name = crd.spec.names.kind; + value = + let + version = lib.pipe crd.spec.versions [ + (lib.filter (x: x.storage or false == true)) + lib.head + (x: x.name) + ]; + in + "${crd.spec.group}/${version}"; + })) + lib.listToAttrs + ]; + }; } diff --git a/importyaml.nix b/importyaml.nix index 218496a..ce6ba2a 100644 --- a/importyaml.nix +++ b/importyaml.nix @@ -76,16 +76,37 @@ in type = types.attrsOf importyaml; default = { }; }; - config = { - kubernetes.objects = lib.pipe cfg [ - (lib.mapAttrsToList ( - _: importspec: lib.map (object: lib.pipe object importspec.overrides) importspec.objects - )) - lib.flatten - (lib.map (object: { - ${object.metadata.namespace or "none"}.${object.kind}.${object.metadata.name} = object; - })) - lib.mkMerge - ]; - }; + config = + let + allObjects = lib.pipe cfg [ + (lib.mapAttrsToList ( + _: importspec: lib.map (object: lib.pipe object importspec.overrides) importspec.objects + )) + lib.flatten + ]; + in + { + kubernetes.objects = lib.pipe allObjects [ + (lib.map (object: { + ${object.metadata.namespace or "none"}.${object.kind}.${object.metadata.name} = object; + })) + lib.mkMerge + ]; + kubernetes.apiMappings = lib.pipe allObjects [ + (lib.filter (object: object.kind or null == "CustomResourceDefinition")) + (map (crd: { + name = crd.spec.names.kind; + value = + let + version = lib.pipe crd.spec.versions [ + (lib.filter (x: x.storage or false == true)) + lib.head + (x: x.name) + ]; + in + "${crd.spec.group}/${version}"; + })) + lib.listToAttrs + ]; + }; } diff --git a/kubernetes.nix b/kubernetes.nix index 17aa514..5bc0b69 100644 --- a/kubernetes.nix +++ b/kubernetes.nix @@ -223,7 +223,6 @@ in in lib.listToAttrs (map objectToAttr data.resources); - generated = lib.pipe cfg.objects [ # Convert kubernetes.objects.namespace.kind.name into a list of objects (lib.collect (x: x ? apiVersion && x ? kind && x ? metadata))