2019-03-07 23:23:07 +01:00
|
|
|
# helm defines kubenix module with options for using helm charts
|
|
|
|
|
# with kubenix
|
2022-04-02 12:40:35 -07:00
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
helm,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
with lib; let
|
2019-02-28 13:17:40 +01:00
|
|
|
cfg = config.kubernetes.helm;
|
|
|
|
|
|
|
|
|
|
globalConfig = config;
|
|
|
|
|
|
|
|
|
|
recursiveAttrs = mkOptionType {
|
|
|
|
|
name = "recursive-attrs";
|
|
|
|
|
description = "recursive attribute set";
|
|
|
|
|
check = isAttrs;
|
2022-04-02 13:41:07 -07:00
|
|
|
merge = _loc: foldl' (res: def: recursiveUpdate res def.value) {};
|
2019-02-28 13:17:40 +01:00
|
|
|
};
|
|
|
|
|
|
2022-04-02 12:40:35 -07:00
|
|
|
parseApiVersion = apiVersion: let
|
|
|
|
|
splitted = splitString "/" apiVersion;
|
|
|
|
|
in {
|
|
|
|
|
group =
|
|
|
|
|
if length splitted == 1
|
|
|
|
|
then "core"
|
|
|
|
|
else head splitted;
|
|
|
|
|
version = last splitted;
|
|
|
|
|
};
|
|
|
|
|
in {
|
|
|
|
|
imports = [./k8s.nix];
|
2019-03-07 23:23:07 +01:00
|
|
|
|
2019-02-28 13:17:40 +01:00
|
|
|
options.kubernetes.helm = {
|
|
|
|
|
instances = mkOption {
|
|
|
|
|
description = "Attribute set of helm instances";
|
2022-04-02 12:40:35 -07:00
|
|
|
type = types.attrsOf (types.submodule ({
|
|
|
|
|
config,
|
|
|
|
|
name,
|
|
|
|
|
...
|
|
|
|
|
}: {
|
2019-02-28 13:17:40 +01:00
|
|
|
options = {
|
|
|
|
|
name = mkOption {
|
|
|
|
|
description = "Helm release name";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = name;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
chart = mkOption {
|
|
|
|
|
description = "Helm chart to use";
|
|
|
|
|
type = types.package;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace = mkOption {
|
|
|
|
|
description = "Namespace to install helm chart to";
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
values = mkOption {
|
|
|
|
|
description = "Values to pass to chart";
|
|
|
|
|
type = recursiveAttrs;
|
2022-04-02 12:40:35 -07:00
|
|
|
default = {};
|
2019-02-28 13:17:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
kubeVersion = mkOption {
|
|
|
|
|
description = "Kubernetes version to build chart for";
|
|
|
|
|
type = types.str;
|
|
|
|
|
default = globalConfig.kubernetes.version;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
overrides = mkOption {
|
|
|
|
|
description = "Overrides to apply to all chart resources";
|
|
|
|
|
type = types.listOf types.unspecified;
|
2022-04-02 12:40:35 -07:00
|
|
|
default = [];
|
2019-02-28 13:17:40 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
overrideNamespace = mkOption {
|
|
|
|
|
description = "Whether to apply namespace override";
|
|
|
|
|
type = types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
objects = mkOption {
|
|
|
|
|
description = "Generated kubernetes objects";
|
|
|
|
|
type = types.listOf types.attrs;
|
2022-04-02 12:40:35 -07:00
|
|
|
default = [];
|
2019-02-28 13:17:40 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-02 12:40:35 -07:00
|
|
|
config.overrides = mkIf (config.overrideNamespace && config.namespace != null) [
|
|
|
|
|
{
|
|
|
|
|
metadata.namespace = config.namespace;
|
|
|
|
|
}
|
|
|
|
|
];
|
2019-02-28 13:17:40 +01:00
|
|
|
|
2019-03-07 23:23:07 +01:00
|
|
|
config.objects = importJSON (helm.chart2json {
|
2019-02-28 13:17:40 +01:00
|
|
|
inherit (config) chart name namespace values kubeVersion;
|
|
|
|
|
});
|
|
|
|
|
}));
|
2022-04-02 12:40:35 -07:00
|
|
|
default = {};
|
2019-02-28 13:17:40 +01:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
config = {
|
|
|
|
|
# expose helm helper methods as module argument
|
2022-04-02 12:40:35 -07:00
|
|
|
_module.args.helm = import ../lib/helm {inherit pkgs;};
|
2019-03-12 20:33:56 +01:00
|
|
|
|
2021-05-13 17:27:08 -04:00
|
|
|
kubernetes.api.resources = mkMerge (flatten (mapAttrsToList
|
2022-04-02 12:40:35 -07:00
|
|
|
(
|
|
|
|
|
_: instance:
|
|
|
|
|
map
|
|
|
|
|
(object: let
|
|
|
|
|
apiVersion = parseApiVersion object.apiVersion;
|
|
|
|
|
name = object.metadata.name;
|
|
|
|
|
in {
|
|
|
|
|
"${apiVersion.group}"."${apiVersion.version}".${object.kind}."${name}" = mkMerge ([
|
2021-05-13 17:27:08 -04:00
|
|
|
object
|
2022-04-02 12:40:35 -07:00
|
|
|
]
|
|
|
|
|
++ instance.overrides);
|
|
|
|
|
})
|
2021-05-13 17:27:08 -04:00
|
|
|
instance.objects
|
|
|
|
|
)
|
|
|
|
|
cfg.instances));
|
2019-03-12 20:33:56 +01:00
|
|
|
};
|
2019-02-28 13:17:40 +01:00
|
|
|
}
|