mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
feat(submodules): support for submodule passthru
This commit is contained in:
parent
7afbc91301
commit
a8dcc69d54
5 changed files with 30 additions and 30 deletions
|
|
@ -87,17 +87,8 @@ in {
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
|
|
||||||
docker.export = mkMerge [
|
# list of exported docker images
|
||||||
(mapAttrsToList (_: i: i.image)
|
docker.export = mapAttrsToList (_: i: i.image)
|
||||||
(filterAttrs (_: i: i.registry != null) config.docker.images))
|
(filterAttrs (_: i: i.registry != null) config.docker.images);
|
||||||
|
|
||||||
# passthru of docker exported images if passthru is enabled on submodule
|
|
||||||
# and submodule has docker module loaded
|
|
||||||
(flatten (mapAttrsToList (_: submodule:
|
|
||||||
optionals
|
|
||||||
(submodule.passthru.enable && (elem "docker" submodule.config._module.features))
|
|
||||||
submodule.config.docker.export
|
|
||||||
) config.submodules.instances))
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -363,21 +363,10 @@ in {
|
||||||
resources.${group}.${version}.${kind}.${name} = object;
|
resources.${group}.${version}.${kind}.${name} = object;
|
||||||
}) cfg.imports));
|
}) cfg.imports));
|
||||||
|
|
||||||
kubernetes.objects = mkMerge [
|
kubernetes.objects = flatten (map (type:
|
||||||
# versioned resources
|
mapAttrsToList (name: resource: moduleToAttrs resource)
|
||||||
(flatten (map (type:
|
cfg.api.resources.${type.group}.${type.version}.${type.kind}
|
||||||
mapAttrsToList (name: resource: moduleToAttrs resource)
|
) cfg.api.types);
|
||||||
cfg.api.resources.${type.group}.${type.version}.${type.kind}
|
|
||||||
) cfg.api.types))
|
|
||||||
|
|
||||||
# passthru of child kubernetes objects if passthru is enabled on submodule
|
|
||||||
# and submodule has k8s module loaded
|
|
||||||
(flatten (mapAttrsToList (_: submodule:
|
|
||||||
optionals
|
|
||||||
(submodule.passthru.enable && (elem "k8s" submodule.config._module.features))
|
|
||||||
submodule.config.kubernetes.objects
|
|
||||||
) config.submodules.instances))
|
|
||||||
];
|
|
||||||
|
|
||||||
kubernetes.generated = k8s.mkHashedList {
|
kubernetes.generated = k8s.mkHashedList {
|
||||||
items = config.kubernetes.objects;
|
items = config.kubernetes.objects;
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ with lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
passthru = mkOption {
|
passthru = mkOption {
|
||||||
description = "Attribute set to passthru to parent";
|
description = "Attribute set to passthru";
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrs;
|
type = types.attrs;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,20 @@ let
|
||||||
then throw "No module found ${name}/${if version == null then "latest" else version}"
|
then throw "No module found ${name}/${if version == null then "latest" else version}"
|
||||||
else head versionSortedSubmodules;
|
else head versionSortedSubmodules;
|
||||||
in matchingModule;
|
in matchingModule;
|
||||||
|
|
||||||
|
passthruConfig = mapAttrsToList (name: opt: {
|
||||||
|
${name} = mkMerge (mapAttrsToList (_: inst:
|
||||||
|
if inst.passthru.enable
|
||||||
|
then inst.config.submodule.passthru.${name} or {}
|
||||||
|
else {}
|
||||||
|
) config.submodules.instances);
|
||||||
|
|
||||||
|
_module.args = mkMerge (mapAttrsToList (_: inst:
|
||||||
|
if inst.passthru.enable
|
||||||
|
then inst.config.submodule.passthru._module.args or {}
|
||||||
|
else {}
|
||||||
|
) config.submodules.instances);
|
||||||
|
}) (removeAttrs options ["_definedNames" "_module" "submodules"]);
|
||||||
in {
|
in {
|
||||||
imports = [ ./base.nix ];
|
imports = [ ./base.nix ];
|
||||||
|
|
||||||
|
|
@ -248,5 +262,5 @@ in {
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
})
|
})
|
||||||
];
|
] ++ passthruConfig);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,13 @@ in {
|
||||||
imports = with kubenix.modules; [ submodule k8s docker ];
|
imports = with kubenix.modules; [ submodule k8s docker ];
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
submodule.name = "test-submodule";
|
submodule = {
|
||||||
|
name = "test-submodule";
|
||||||
|
passthru = {
|
||||||
|
kubernetes.objects = config.kubernetes.objects;
|
||||||
|
docker.images = config.docker.images;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
kubernetes.resources.pods.nginx = {
|
kubernetes.resources.pods.nginx = {
|
||||||
metadata.name = name;
|
metadata.name = name;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue