derive apiMappings from CRDs in importers instead of kubernetes.nix
Move CRD-to-apiMapping extraction into importyaml.nix and helm.nix where raw objects are available before module evaluation, breaking the infinite recursion cycle that occurred when kubernetes.nix read CRD data from config.kubernetes.objects (which triggered submodule evaluation that depended on apiMappings). Drop the apiVersions default in helm.nix that referenced apiMappings, since it created a dependency from helm objects back to apiMappings. Users can still pass a hardcoded list if a chart needs it.
This commit is contained in:
parent
eb2a380f7b
commit
b88b7b9623
3 changed files with 76 additions and 36 deletions
66
helm.nix
66
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
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue