mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-13 00:20:07 +01:00
fmt
This commit is contained in:
parent
c3fa598922
commit
db6d83c61e
53 changed files with 1916 additions and 1599 deletions
|
|
@ -13,27 +13,27 @@ with lib;
|
|||
_m.features = mkOption {
|
||||
description = "List of features exposed by module";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
_m.propagate = mkOption {
|
||||
description = "Module propagation options";
|
||||
type = types.listOf (types.submodule ({config, ...}: {
|
||||
type = types.listOf (types.submodule ({ config, ... }: {
|
||||
options = {
|
||||
features = mkOption {
|
||||
description = "List of features that submodule has to have to propagate module";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
module = mkOption {
|
||||
description = "Module to propagate";
|
||||
type = types.unspecified;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
{ config, lib, pkgs, docker, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.docker;
|
||||
in {
|
||||
in
|
||||
{
|
||||
imports = [ ./base.nix ];
|
||||
|
||||
options.docker = {
|
||||
|
|
@ -52,13 +52,13 @@ in {
|
|||
};
|
||||
};
|
||||
}));
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
export = mkOption {
|
||||
description = "List of images to export";
|
||||
type = types.listOf types.package;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
copyScript = mkOption {
|
||||
|
|
@ -73,7 +73,7 @@ in {
|
|||
|
||||
config = {
|
||||
# define docker feature
|
||||
_m.features = ["docker"];
|
||||
_m.features = [ "docker" ];
|
||||
|
||||
# propagate docker options if docker feature is enabled
|
||||
_m.propagate = [{
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
{ config, lib, pkgs, helm, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.kubernetes.helm;
|
||||
|
||||
|
|
@ -14,17 +13,20 @@ let
|
|||
name = "recursive-attrs";
|
||||
description = "recursive attribute set";
|
||||
check = isAttrs;
|
||||
merge = loc: foldl' (res: def: recursiveUpdate res def.value) {};
|
||||
merge = loc: foldl' (res: def: recursiveUpdate res def.value) { };
|
||||
};
|
||||
|
||||
parseApiVersion = apiVersion: let
|
||||
splitted = splitString "/" apiVersion;
|
||||
in {
|
||||
group = if length splitted == 1 then "core" else head splitted;
|
||||
version = last splitted;
|
||||
};
|
||||
parseApiVersion = apiVersion:
|
||||
let
|
||||
splitted = splitString "/" apiVersion;
|
||||
in
|
||||
{
|
||||
group = if length splitted == 1 then "core" else head splitted;
|
||||
version = last splitted;
|
||||
};
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
imports = [ ./k8s.nix ];
|
||||
|
||||
options.kubernetes.helm = {
|
||||
|
|
@ -52,7 +54,7 @@ in {
|
|||
values = mkOption {
|
||||
description = "Values to pass to chart";
|
||||
type = recursiveAttrs;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
kubeVersion = mkOption {
|
||||
|
|
@ -64,7 +66,7 @@ in {
|
|||
overrides = mkOption {
|
||||
description = "Overrides to apply to all chart resources";
|
||||
type = types.listOf types.unspecified;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
overrideNamespace = mkOption {
|
||||
|
|
@ -76,7 +78,7 @@ in {
|
|||
objects = mkOption {
|
||||
description = "Generated kubernetes objects";
|
||||
type = types.listOf types.attrs;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -88,7 +90,7 @@ in {
|
|||
inherit (config) chart name namespace values kubeVersion;
|
||||
});
|
||||
}));
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -96,15 +98,21 @@ in {
|
|||
# expose helm helper methods as module argument
|
||||
_module.args.helm = import ../lib/helm { inherit pkgs; };
|
||||
|
||||
kubernetes.api.resources = mkMerge (flatten (mapAttrsToList (_: instance:
|
||||
map (object: let
|
||||
apiVersion = parseApiVersion object.apiVersion;
|
||||
name = object.metadata.name;
|
||||
in {
|
||||
"${apiVersion.group}"."${apiVersion.version}".${object.kind}."${name}" = mkMerge ([
|
||||
object
|
||||
] ++ instance.overrides);
|
||||
}) instance.objects
|
||||
) cfg.instances));
|
||||
kubernetes.api.resources = mkMerge (flatten (mapAttrsToList
|
||||
(_: instance:
|
||||
map
|
||||
(object:
|
||||
let
|
||||
apiVersion = parseApiVersion object.apiVersion;
|
||||
name = object.metadata.name;
|
||||
in
|
||||
{
|
||||
"${apiVersion.group}"."${apiVersion.version}".${object.kind}."${name}" = mkMerge ([
|
||||
object
|
||||
] ++ instance.overrides);
|
||||
})
|
||||
instance.objects
|
||||
)
|
||||
cfg.instances));
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,11 +3,12 @@
|
|||
with lib;
|
||||
|
||||
{
|
||||
"istio_networking_v1alpha3_StringMatch" = recursiveUpdate (recursiveUpdate
|
||||
definitions."istio_networking_v1alpha3_StringMatch_Exact"
|
||||
definitions."istio_networking_v1alpha3_StringMatch_Prefix"
|
||||
)
|
||||
definitions."istio_networking_v1alpha3_StringMatch_Regex";
|
||||
"istio_networking_v1alpha3_StringMatch" = recursiveUpdate
|
||||
(recursiveUpdate
|
||||
definitions."istio_networking_v1alpha3_StringMatch_Exact"
|
||||
definitions."istio_networking_v1alpha3_StringMatch_Prefix"
|
||||
)
|
||||
definitions."istio_networking_v1alpha3_StringMatch_Regex";
|
||||
|
||||
"istio_networking_v1alpha3_PortSelector" = recursiveUpdate
|
||||
definitions."istio_networking_v1alpha3_PortSelector_Name"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
# This file was generated with kubenix k8s generator, do not edit
|
||||
{lib, config, ... }:
|
||||
{ lib, config, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
types = lib.types // rec {
|
||||
str = mkOptionType {
|
||||
|
|
@ -15,61 +14,68 @@ let
|
|||
# Either value of type `finalType` or `coercedType`, the latter is
|
||||
# converted to `finalType` using `coerceFunc`.
|
||||
coercedTo = coercedType: coerceFunc: finalType:
|
||||
mkOptionType rec {
|
||||
name = "coercedTo";
|
||||
description = "${finalType.description} or ${coercedType.description}";
|
||||
check = x: finalType.check x || coercedType.check x;
|
||||
merge = loc: defs:
|
||||
let
|
||||
coerceVal = val:
|
||||
if finalType.check val then val
|
||||
else let
|
||||
coerced = coerceFunc val;
|
||||
in assert finalType.check coerced; coerced;
|
||||
mkOptionType rec {
|
||||
name = "coercedTo";
|
||||
description = "${finalType.description} or ${coercedType.description}";
|
||||
check = x: finalType.check x || coercedType.check x;
|
||||
merge = loc: defs:
|
||||
let
|
||||
coerceVal = val:
|
||||
if finalType.check val then val
|
||||
else
|
||||
let
|
||||
coerced = coerceFunc val;
|
||||
in
|
||||
assert finalType.check coerced; coerced;
|
||||
|
||||
in finalType.merge loc (map (def: def // { value = coerceVal def.value; }) defs);
|
||||
getSubOptions = finalType.getSubOptions;
|
||||
getSubModules = finalType.getSubModules;
|
||||
substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m);
|
||||
typeMerge = t1: t2: null;
|
||||
functor = (defaultFunctor name) // { wrapped = finalType; };
|
||||
};
|
||||
in
|
||||
finalType.merge loc (map (def: def // { value = coerceVal def.value; }) defs);
|
||||
getSubOptions = finalType.getSubOptions;
|
||||
getSubModules = finalType.getSubModules;
|
||||
substSubModules = m: coercedTo coercedType coerceFunc (finalType.substSubModules m);
|
||||
typeMerge = t1: t2: null;
|
||||
functor = (defaultFunctor name) // { wrapped = finalType; };
|
||||
};
|
||||
};
|
||||
|
||||
mkOptionDefault = mkOverride 1001;
|
||||
|
||||
extraOptions = {
|
||||
kubenix = {};
|
||||
kubenix = { };
|
||||
};
|
||||
|
||||
mergeValuesByKey = mergeKey: values:
|
||||
listToAttrs (map
|
||||
(value: nameValuePair (
|
||||
if isAttrs value.${mergeKey}
|
||||
then toString value.${mergeKey}.content
|
||||
else (toString value.${mergeKey})
|
||||
) value)
|
||||
values);
|
||||
(value: nameValuePair
|
||||
(
|
||||
if isAttrs value.${mergeKey}
|
||||
then toString value.${mergeKey}.content
|
||||
else (toString value.${mergeKey})
|
||||
)
|
||||
value)
|
||||
values);
|
||||
|
||||
submoduleOf = ref: types.submodule ({name, ...}: {
|
||||
submoduleOf = ref: types.submodule ({ name, ... }: {
|
||||
options = definitions."${ref}".options;
|
||||
config = definitions."${ref}".config;
|
||||
});
|
||||
|
||||
submoduleWithMergeOf = ref: mergeKey: types.submodule ({name, ...}: let
|
||||
convertName = name:
|
||||
if definitions."${ref}".options.${mergeKey}.type == types.int
|
||||
then toInt name
|
||||
else name;
|
||||
in {
|
||||
options = definitions."${ref}".options;
|
||||
config = definitions."${ref}".config // {
|
||||
${mergeKey} = mkOverride 1002 (convertName name);
|
||||
};
|
||||
});
|
||||
submoduleWithMergeOf = ref: mergeKey: types.submodule ({ name, ... }:
|
||||
let
|
||||
convertName = name:
|
||||
if definitions."${ref}".options.${mergeKey}.type == types.int
|
||||
then toInt name
|
||||
else name;
|
||||
in
|
||||
{
|
||||
options = definitions."${ref}".options;
|
||||
config = definitions."${ref}".config // {
|
||||
${mergeKey} = mkOverride 1002 (convertName name);
|
||||
};
|
||||
});
|
||||
|
||||
submoduleForDefinition = ref: resource: kind: group: version:
|
||||
types.submodule ({name, ...}: {
|
||||
types.submodule ({ name, ... }: {
|
||||
options = definitions."${ref}".options // extraOptions;
|
||||
config = mkMerge ([
|
||||
definitions."${ref}".config
|
||||
|
|
@ -80,8 +86,8 @@ let
|
|||
# metdata.name cannot use option default, due deep config
|
||||
metadata.name = mkOptionDefault name;
|
||||
}
|
||||
] ++ (config.defaults.${resource} or [])
|
||||
++ (config.defaults.all or []));
|
||||
] ++ (config.defaults.${resource} or [ ])
|
||||
++ (config.defaults.all or [ ]));
|
||||
});
|
||||
|
||||
coerceAttrsOfSubmodulesToListByKey = ref: mergeKey: (types.coercedTo
|
||||
|
|
@ -2846,7 +2852,7 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
"istio_mixer_v1_ReportResponse" = {};
|
||||
"istio_mixer_v1_ReportResponse" = { };
|
||||
|
||||
"istio_mixer_v1_RouteDirective" = {
|
||||
options = {
|
||||
|
|
@ -4697,225 +4703,261 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
} // (import ./istio-overrides.nix {inherit definitions lib;});
|
||||
in {
|
||||
} // (import ./istio-overrides.nix { inherit definitions lib; });
|
||||
in
|
||||
{
|
||||
kubernetes.customResources = [
|
||||
{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "DestinationRule";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_DestinationRule";
|
||||
}{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "EnvoyFilter";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_EnvoyFilter";
|
||||
}{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "Gateway";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_Gateway";
|
||||
}{
|
||||
group = "authentication.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "Policy";
|
||||
description = "";
|
||||
module = definitions."istio_authentication_v1alpha1_Policy";
|
||||
}{
|
||||
group = "rbac.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "RbacConfig";
|
||||
description = "";
|
||||
module = definitions."istio_rbac_v1alpha1_RbacConfig";
|
||||
}{
|
||||
group = "policy.istio.io";
|
||||
version = "v1beta1";
|
||||
kind = "Rule";
|
||||
description = "";
|
||||
module = definitions."istio_policy_v1beta1_Rule";
|
||||
}{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "ServiceEntry";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_ServiceEntry";
|
||||
}{
|
||||
group = "rbac.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "ServiceRole";
|
||||
description = "";
|
||||
module = definitions."istio_rbac_v1alpha1_ServiceRole";
|
||||
}{
|
||||
group = "rbac.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "ServiceRoleBinding";
|
||||
description = "";
|
||||
module = definitions."istio_rbac_v1alpha1_ServiceRoleBinding";
|
||||
}{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "VirtualService";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_VirtualService";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "apikey";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_apikey_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "authorization";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_authorization_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "bypass";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_bypass_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "checknothing";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_checknothing_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "circonus";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_circonus_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "denier";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_denier_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "edge";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_edge_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "fluentd";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_fluentd_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "kubernetesenv";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_kubernetesenv_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "listentry";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_listentry_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "logentry";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_logentry_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "memquota";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_memquota_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "metric";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_metric_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "opa";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_opa_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "prometheus";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_prometheus_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "quota";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_quota_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "rbac";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_rbac_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "redisquota";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_redisquota_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "reportnothing";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_reportnothing_InstanceMsg";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "servicecontrol";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_servicecontrol_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "signalfx";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_signalfx_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "solarwinds";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_solarwinds_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "stackdriver";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_stackdriver_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "statsd";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_statsd_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "stdio";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_stdio_Params";
|
||||
}{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "tracespan";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_tracespan_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "DestinationRule";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_DestinationRule";
|
||||
}
|
||||
{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "EnvoyFilter";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_EnvoyFilter";
|
||||
}
|
||||
{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "Gateway";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_Gateway";
|
||||
}
|
||||
{
|
||||
group = "authentication.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "Policy";
|
||||
description = "";
|
||||
module = definitions."istio_authentication_v1alpha1_Policy";
|
||||
}
|
||||
{
|
||||
group = "rbac.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "RbacConfig";
|
||||
description = "";
|
||||
module = definitions."istio_rbac_v1alpha1_RbacConfig";
|
||||
}
|
||||
{
|
||||
group = "policy.istio.io";
|
||||
version = "v1beta1";
|
||||
kind = "Rule";
|
||||
description = "";
|
||||
module = definitions."istio_policy_v1beta1_Rule";
|
||||
}
|
||||
{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "ServiceEntry";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_ServiceEntry";
|
||||
}
|
||||
{
|
||||
group = "rbac.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "ServiceRole";
|
||||
description = "";
|
||||
module = definitions."istio_rbac_v1alpha1_ServiceRole";
|
||||
}
|
||||
{
|
||||
group = "rbac.istio.io";
|
||||
version = "v1alpha1";
|
||||
kind = "ServiceRoleBinding";
|
||||
description = "";
|
||||
module = definitions."istio_rbac_v1alpha1_ServiceRoleBinding";
|
||||
}
|
||||
{
|
||||
group = "networking.istio.io";
|
||||
version = "v1alpha3";
|
||||
kind = "VirtualService";
|
||||
description = "";
|
||||
module = definitions."istio_networking_v1alpha3_VirtualService";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "apikey";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_apikey_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "authorization";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_authorization_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "bypass";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_bypass_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "checknothing";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_checknothing_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "circonus";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_circonus_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "denier";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_denier_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "edge";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_edge_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "fluentd";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_fluentd_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "kubernetesenv";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_kubernetesenv_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "listentry";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_listentry_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "logentry";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_logentry_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "memquota";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_memquota_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "metric";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_metric_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "opa";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_opa_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "prometheus";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_prometheus_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "quota";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_quota_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "rbac";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_rbac_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "redisquota";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_redisquota_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "reportnothing";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_reportnothing_InstanceMsg";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "servicecontrol";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_servicecontrol_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "signalfx";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_signalfx_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "solarwinds";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_solarwinds_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "stackdriver";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_stackdriver_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "statsd";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_statsd_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "stdio";
|
||||
description = "";
|
||||
module = definitions."istio_adapter_stdio_Params";
|
||||
}
|
||||
{
|
||||
group = "config.istio.io";
|
||||
version = "v1alpha2";
|
||||
kind = "tracespan";
|
||||
description = "";
|
||||
module = definitions."istio_mixer_tracespan_InstanceMsg";
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,24 @@ stdenv.mkDerivation rec {
|
|||
pname = "k3s-airgap-images";
|
||||
version = k3s.version;
|
||||
|
||||
src = let
|
||||
throwError = throw "Unsupported system ${stdenv.hostPlatform.system}";
|
||||
in {
|
||||
x86_64-linux = fetchurl {
|
||||
url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-amd64.tar";
|
||||
sha256 = "sha256-6kQmlpNV+4cU1Kn5lyZhutXYK5qYdey0jubzYRRF3vA=";
|
||||
};
|
||||
aarch64-linux = fetchurl {
|
||||
url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-arm64.tar";
|
||||
sha256 = "sha256-OlqqdAmBN+azT0kfjZ/Bd0CFbbW5hTg9/8T9U05N0zE=";
|
||||
};
|
||||
armv7l-linux = fetchurl {
|
||||
url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-arm.tar";
|
||||
sha256 = "sha256-j/ARBtHDnfRk/7BpOvavoHe7L5dmsCZe5+wuZ5t4V/k=";
|
||||
};
|
||||
}.${stdenv.hostPlatform.system} or throwError;
|
||||
src =
|
||||
let
|
||||
throwError = throw "Unsupported system ${stdenv.hostPlatform.system}";
|
||||
in
|
||||
{
|
||||
x86_64-linux = fetchurl {
|
||||
url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-amd64.tar";
|
||||
sha256 = "sha256-6kQmlpNV+4cU1Kn5lyZhutXYK5qYdey0jubzYRRF3vA=";
|
||||
};
|
||||
aarch64-linux = fetchurl {
|
||||
url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-arm64.tar";
|
||||
sha256 = "sha256-OlqqdAmBN+azT0kfjZ/Bd0CFbbW5hTg9/8T9U05N0zE=";
|
||||
};
|
||||
armv7l-linux = fetchurl {
|
||||
url = "https://github.com/rancher/k3s/releases/download/v${version}/k3s-airgap-images-arm.tar";
|
||||
sha256 = "sha256-j/ARBtHDnfRk/7BpOvavoHe7L5dmsCZe5+wuZ5t4V/k=";
|
||||
};
|
||||
}.${stdenv.hostPlatform.system} or throwError;
|
||||
|
||||
preferLocalBuild = true;
|
||||
dontUnpack = true;
|
||||
|
|
|
|||
343
modules/k8s.nix
343
modules/k8s.nix
|
|
@ -3,19 +3,20 @@
|
|||
{ options, config, lib, pkgs, k8s, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.kubernetes;
|
||||
|
||||
gvkKeyFn = type: "${type.group}/${type.version}/${type.kind}";
|
||||
|
||||
getDefaults = resource: group: version: kind:
|
||||
catAttrs "default" (filter (default:
|
||||
(resource == null || default.resource == null || default.resource == resource) &&
|
||||
(default.group == null || default.group == group) &&
|
||||
(default.version == null || default.version == version) &&
|
||||
(default.kind == null || default.kind == kind)
|
||||
) cfg.api.defaults);
|
||||
catAttrs "default" (filter
|
||||
(default:
|
||||
(resource == null || default.resource == null || default.resource == resource) &&
|
||||
(default.group == null || default.group == group) &&
|
||||
(default.version == null || default.version == version) &&
|
||||
(default.kind == null || default.kind == kind)
|
||||
)
|
||||
cfg.api.defaults);
|
||||
|
||||
moduleToAttrs = value:
|
||||
if isAttrs value
|
||||
|
|
@ -34,7 +35,7 @@ let
|
|||
|
||||
defaults = mkOption {
|
||||
description = "Kubernetes defaults to apply to resources";
|
||||
type = types.listOf (types.submodule ({config, ...}: {
|
||||
type = types.listOf (types.submodule ({ config, ... }: {
|
||||
options = {
|
||||
group = mkOption {
|
||||
description = "Group to apply default to (all by default)";
|
||||
|
|
@ -69,45 +70,47 @@ let
|
|||
default = mkOption {
|
||||
description = "Default to apply";
|
||||
type = types.unspecified;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = [];
|
||||
default = [ ];
|
||||
apply = unique;
|
||||
};
|
||||
|
||||
types = mkOption {
|
||||
description = "List of registered kubernetes types";
|
||||
type = coerceListOfSubmodulesToAttrs {
|
||||
options = {
|
||||
group = mkOption {
|
||||
description = "Resource type group";
|
||||
type = types.str;
|
||||
};
|
||||
type = coerceListOfSubmodulesToAttrs
|
||||
{
|
||||
options = {
|
||||
group = mkOption {
|
||||
description = "Resource type group";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
version = mkOption {
|
||||
description = "Resoruce type version";
|
||||
type = types.str;
|
||||
};
|
||||
version = mkOption {
|
||||
description = "Resoruce type version";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
kind = mkOption {
|
||||
description = "Resource type kind";
|
||||
type = types.str;
|
||||
};
|
||||
kind = mkOption {
|
||||
description = "Resource type kind";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
name = mkOption {
|
||||
description = "Resource type name";
|
||||
type = types.nullOr types.str;
|
||||
};
|
||||
name = mkOption {
|
||||
description = "Resource type name";
|
||||
type = types.nullOr types.str;
|
||||
};
|
||||
|
||||
attrName = mkOption {
|
||||
description = "Name of the nixified attribute";
|
||||
type = types.str;
|
||||
attrName = mkOption {
|
||||
description = "Name of the nixified attribute";
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
} gvkKeyFn;
|
||||
default = {};
|
||||
}
|
||||
gvkKeyFn;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -120,24 +123,32 @@ let
|
|||
indexOf = lst: value:
|
||||
head (filter (v: v != -1) (imap0 (i: v: if v == value then i else -1) lst));
|
||||
|
||||
compareVersions = ver1: ver2: let
|
||||
getVersion = v: substring 1 10 v;
|
||||
splittedVer1 = builtins.splitVersion (getVersion ver1);
|
||||
splittedVer2 = builtins.splitVersion (getVersion ver2);
|
||||
compareVersions = ver1: ver2:
|
||||
let
|
||||
getVersion = v: substring 1 10 v;
|
||||
splittedVer1 = builtins.splitVersion (getVersion ver1);
|
||||
splittedVer2 = builtins.splitVersion (getVersion ver2);
|
||||
|
||||
v1 = if length splittedVer1 == 1 then "${getVersion ver1}prod" else getVersion ver1;
|
||||
v2 = if length splittedVer2 == 1 then "${getVersion ver2}prod" else getVersion ver2;
|
||||
in builtins.compareVersions v1 v2;
|
||||
v1 = if length splittedVer1 == 1 then "${getVersion ver1}prod" else getVersion ver1;
|
||||
v2 = if length splittedVer2 == 1 then "${getVersion ver2}prod" else getVersion ver2;
|
||||
in
|
||||
builtins.compareVersions v1 v2;
|
||||
|
||||
customResourceTypesByAttrName = zipAttrs (mapAttrsToList (_: resourceType: {
|
||||
${resourceType.attrName} = resourceType;
|
||||
}) cfg.customTypes);
|
||||
customResourceTypesByAttrName = zipAttrs (mapAttrsToList
|
||||
(_: resourceType: {
|
||||
${resourceType.attrName} = resourceType;
|
||||
})
|
||||
cfg.customTypes);
|
||||
|
||||
customResourceTypesByAttrNameSortByVersion = mapAttrs (_: resourceTypes:
|
||||
reverseList (sort (r1: r2:
|
||||
compareVersions r1.version r2.version > 0
|
||||
) resourceTypes)
|
||||
) customResourceTypesByAttrName;
|
||||
customResourceTypesByAttrNameSortByVersion = mapAttrs
|
||||
(_: resourceTypes:
|
||||
reverseList (sort
|
||||
(r1: r2:
|
||||
compareVersions r1.version r2.version > 0
|
||||
)
|
||||
resourceTypes)
|
||||
)
|
||||
customResourceTypesByAttrName;
|
||||
|
||||
latestCustomResourceTypes =
|
||||
mapAttrsToList (_: resources: last resources) customResourceTypesByAttrNameSortByVersion;
|
||||
|
|
@ -163,7 +174,7 @@ let
|
|||
spec = mkOption {
|
||||
description = "Module spec";
|
||||
type = types.either types.attrs (types.submodule ct.module);
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -174,34 +185,43 @@ let
|
|||
};
|
||||
};
|
||||
|
||||
customResourceOptions = (mapAttrsToList (_: ct: {config, ...}: let
|
||||
module = customResourceModuleForType config ct;
|
||||
in {
|
||||
options.resources.${ct.group}.${ct.version}.${ct.kind} = mkOption {
|
||||
description = ct.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = {};
|
||||
};
|
||||
}) cfg.customTypes) ++ (map (ct: { options, config, ... }: let
|
||||
module = customResourceModuleForType config ct;
|
||||
in {
|
||||
options.resources.${ct.attrName} = mkOption {
|
||||
description = ct.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = {};
|
||||
};
|
||||
customResourceOptions = (mapAttrsToList
|
||||
(_: ct: { config, ... }:
|
||||
let
|
||||
module = customResourceModuleForType config ct;
|
||||
in
|
||||
{
|
||||
options.resources.${ct.group}.${ct.version}.${ct.kind} = mkOption {
|
||||
description = ct.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = { };
|
||||
};
|
||||
})
|
||||
cfg.customTypes) ++ (map
|
||||
(ct: { options, config, ... }:
|
||||
let
|
||||
module = customResourceModuleForType config ct;
|
||||
in
|
||||
{
|
||||
options.resources.${ct.attrName} = mkOption {
|
||||
description = ct.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = { };
|
||||
};
|
||||
|
||||
config.resources.${ct.group}.${ct.version}.${ct.kind} =
|
||||
mkAliasDefinitions options.resources.${ct.attrName};
|
||||
}) latestCustomResourceTypes);
|
||||
config.resources.${ct.group}.${ct.version}.${ct.kind} =
|
||||
mkAliasDefinitions options.resources.${ct.attrName};
|
||||
})
|
||||
latestCustomResourceTypes);
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
imports = [ ./base.nix ];
|
||||
|
||||
options.kubernetes = {
|
||||
version = mkOption {
|
||||
description = "Kubernetes version to use";
|
||||
type = types.enum ["1.19" "1.20" "1.21"];
|
||||
type = types.enum [ "1.19" "1.20" "1.21" ];
|
||||
default = "1.21";
|
||||
};
|
||||
|
||||
|
|
@ -227,76 +247,80 @@ in {
|
|||
apiOptions
|
||||
] ++ customResourceOptions;
|
||||
};
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
imports = mkOption {
|
||||
type = types.listOf (types.either types.package types.path);
|
||||
description = "List of resources to import";
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
resources = mkOption {
|
||||
description = "Alias for `config.kubernetes.api.resources` options";
|
||||
default = {};
|
||||
default = { };
|
||||
type = types.attrsOf types.attrs;
|
||||
};
|
||||
|
||||
customTypes = mkOption {
|
||||
description = "List of custom resource types to make API for";
|
||||
type = coerceListOfSubmodulesToAttrs {
|
||||
options = {
|
||||
group = mkOption {
|
||||
description = "Custom type group";
|
||||
type = types.str;
|
||||
};
|
||||
type = coerceListOfSubmodulesToAttrs
|
||||
{
|
||||
options = {
|
||||
group = mkOption {
|
||||
description = "Custom type group";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
version = mkOption {
|
||||
description = "Custom type version";
|
||||
type = types.str;
|
||||
};
|
||||
version = mkOption {
|
||||
description = "Custom type version";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
kind = mkOption {
|
||||
description = "Custom type kind";
|
||||
type = types.str;
|
||||
};
|
||||
kind = mkOption {
|
||||
description = "Custom type kind";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
name = mkOption {
|
||||
description = "Custom type resource name";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
name = mkOption {
|
||||
description = "Custom type resource name";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
|
||||
attrName = mkOption {
|
||||
description = "Name of the nixified attribute";
|
||||
type = types.str;
|
||||
};
|
||||
attrName = mkOption {
|
||||
description = "Name of the nixified attribute";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
description = mkOption {
|
||||
description = "Custom type description";
|
||||
type = types.str;
|
||||
default = "";
|
||||
};
|
||||
description = mkOption {
|
||||
description = "Custom type description";
|
||||
type = types.str;
|
||||
default = "";
|
||||
};
|
||||
|
||||
module = mkOption {
|
||||
description = "Custom type module";
|
||||
type = types.unspecified;
|
||||
default = {};
|
||||
module = mkOption {
|
||||
description = "Custom type module";
|
||||
type = types.unspecified;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
} gvkKeyFn;
|
||||
default = {};
|
||||
}
|
||||
gvkKeyFn;
|
||||
default = { };
|
||||
};
|
||||
|
||||
objects = mkOption {
|
||||
description = "List of generated kubernetes objects";
|
||||
type = types.listOf types.attrs;
|
||||
apply = items: sort (r1: r2:
|
||||
if elem r1.kind cfg.resourceOrder && elem r2.kind cfg.resourceOrder
|
||||
then indexOf cfg.resourceOrder r1.kind < indexOf cfg.resourceOrder r2.kind
|
||||
else if elem r1.kind cfg.resourceOrder then true else false
|
||||
) (unique items);
|
||||
default = [];
|
||||
apply = items: sort
|
||||
(r1: r2:
|
||||
if elem r1.kind cfg.resourceOrder && elem r2.kind cfg.resourceOrder
|
||||
then indexOf cfg.resourceOrder r1.kind < indexOf cfg.resourceOrder r2.kind
|
||||
else if elem r1.kind cfg.resourceOrder then true else false
|
||||
)
|
||||
(unique items);
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
generated = mkOption {
|
||||
|
|
@ -321,41 +345,44 @@ in {
|
|||
|
||||
# module propagation options
|
||||
_m.propagate = [{
|
||||
features = ["k8s"];
|
||||
features = [ "k8s" ];
|
||||
module = { config, ... }: {
|
||||
# propagate kubernetes version and namespace
|
||||
kubernetes.version = mkDefault cfg.version;
|
||||
kubernetes.namespace = mkDefault cfg.namespace;
|
||||
};
|
||||
} {
|
||||
features = ["k8s" "submodule"];
|
||||
module = { config, ... }: {
|
||||
# set module defaults
|
||||
kubernetes.api.defaults = (
|
||||
# propagate defaults if default propagation is enabled
|
||||
(filter (default: default.propagate) cfg.api.defaults) ++
|
||||
}
|
||||
{
|
||||
features = [ "k8s" "submodule" ];
|
||||
module = { config, ... }: {
|
||||
# set module defaults
|
||||
kubernetes.api.defaults = (
|
||||
# propagate defaults if default propagation is enabled
|
||||
(filter (default: default.propagate) cfg.api.defaults) ++
|
||||
|
||||
[
|
||||
# set module name and version for all kuberentes resources
|
||||
{
|
||||
default.metadata.labels = {
|
||||
"kubenix/module-name" = config.submodule.name;
|
||||
"kubenix/module-version" = config.submodule.version;
|
||||
};
|
||||
}
|
||||
]
|
||||
);
|
||||
};
|
||||
}];
|
||||
[
|
||||
# set module name and version for all kuberentes resources
|
||||
{
|
||||
default.metadata.labels = {
|
||||
"kubenix/module-name" = config.submodule.name;
|
||||
"kubenix/module-version" = config.submodule.version;
|
||||
};
|
||||
}
|
||||
]
|
||||
);
|
||||
};
|
||||
}];
|
||||
|
||||
# expose k8s helper methods as module argument
|
||||
_module.args.k8s = import ../lib/k8s.nix { inherit lib; };
|
||||
|
||||
kubernetes.api = mkMerge ([{
|
||||
# register custom types
|
||||
types = mapAttrsToList (_: cr: {
|
||||
inherit (cr) name group version kind attrName;
|
||||
}) cfg.customTypes;
|
||||
types = mapAttrsToList
|
||||
(_: cr: {
|
||||
inherit (cr) name group version kind attrName;
|
||||
})
|
||||
cfg.customTypes;
|
||||
|
||||
defaults = [{
|
||||
default = {
|
||||
|
|
@ -373,24 +400,30 @@ in {
|
|||
}] ++
|
||||
|
||||
# import of yaml files
|
||||
(map (i: let
|
||||
# load yaml file
|
||||
object = loadYAML i;
|
||||
groupVersion = splitString "/" object.apiVersion;
|
||||
name = object.metadata.name;
|
||||
version = last groupVersion;
|
||||
group =
|
||||
if version == (head groupVersion)
|
||||
then "core" else head groupVersion;
|
||||
kind = object.kind;
|
||||
in {
|
||||
resources.${group}.${version}.${kind}.${name} = object;
|
||||
}) cfg.imports));
|
||||
(map
|
||||
(i:
|
||||
let
|
||||
# load yaml file
|
||||
object = loadYAML i;
|
||||
groupVersion = splitString "/" object.apiVersion;
|
||||
name = object.metadata.name;
|
||||
version = last groupVersion;
|
||||
group =
|
||||
if version == (head groupVersion)
|
||||
then "core" else head groupVersion;
|
||||
kind = object.kind;
|
||||
in
|
||||
{
|
||||
resources.${group}.${version}.${kind}.${name} = object;
|
||||
})
|
||||
cfg.imports));
|
||||
|
||||
kubernetes.objects = flatten (mapAttrsToList (_: type:
|
||||
mapAttrsToList (name: resource: moduleToAttrs resource)
|
||||
cfg.api.resources.${type.group}.${type.version}.${type.kind}
|
||||
) cfg.api.types);
|
||||
kubernetes.objects = flatten (mapAttrsToList
|
||||
(_: type:
|
||||
mapAttrsToList (name: resource: moduleToAttrs resource)
|
||||
cfg.api.resources.${type.group}.${type.version}.${type.kind}
|
||||
)
|
||||
cfg.api.types);
|
||||
|
||||
kubernetes.generated = k8s.mkHashedList {
|
||||
items = config.kubernetes.objects;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
{ options, config, pkgs, lib, kubenix, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
parentModule = module;
|
||||
globalConfig = config;
|
||||
|
|
@ -29,46 +28,50 @@ let
|
|||
else if isAttrs mkOptionDefault.module then module // attrs
|
||||
else module
|
||||
);
|
||||
in [
|
||||
in
|
||||
[
|
||||
{
|
||||
_module.args.name = module.name;
|
||||
_module.args.module = module;
|
||||
}
|
||||
./k8s.nix
|
||||
./legacy.nix
|
||||
(injectModuleAttrs moduleDefinition.module {_file = file;})
|
||||
(injectModuleAttrs moduleDefinition.module { _file = file; })
|
||||
{
|
||||
config.kubernetes.namespace = mkOptionDefault module.namespace;
|
||||
config.kubenix.project = mkOptionDefault config.kubenix.project;
|
||||
}
|
||||
] ++ config.kubernetes.defaultModuleConfiguration.all
|
||||
++ (optionals (hasAttr moduleDefinition.name config.kubernetes.defaultModuleConfiguration)
|
||||
config.kubernetes.defaultModuleConfiguration.${moduleDefinition.name});
|
||||
] ++ config.kubernetes.defaultModuleConfiguration.all
|
||||
++ (optionals (hasAttr moduleDefinition.name config.kubernetes.defaultModuleConfiguration)
|
||||
config.kubernetes.defaultModuleConfiguration.${moduleDefinition.name});
|
||||
|
||||
# prefix kubernetes objects with ${serviceName}, this magic was removed in new kubenix
|
||||
prefixResources = resources: serviceName:
|
||||
mapAttrs' (name: resource: nameValuePair "${serviceName}-${name}" resource) resources;
|
||||
|
||||
# TODO: rewrite using mkOptionType
|
||||
defaultModuleConfigurationOptions = mapAttrs (name: moduleDefinition: mkOption {
|
||||
description = "Module default configuration for ${name} module";
|
||||
type = types.coercedTo types.unspecified (value: [value]) (types.listOf types.unspecified);
|
||||
default = [];
|
||||
apply = filter (v: v!=[]);
|
||||
}) config.kubernetes.moduleDefinitions;
|
||||
defaultModuleConfigurationOptions = mapAttrs
|
||||
(name: moduleDefinition: mkOption {
|
||||
description = "Module default configuration for ${name} module";
|
||||
type = types.coercedTo types.unspecified (value: [ value ]) (types.listOf types.unspecified);
|
||||
default = [ ];
|
||||
apply = filter (v: v != [ ]);
|
||||
})
|
||||
config.kubernetes.moduleDefinitions;
|
||||
|
||||
getModuleDefinition = name:
|
||||
if hasAttr name config.kubernetes.moduleDefinitions
|
||||
then config.kubernetes.moduleDefinitions.${name}
|
||||
else throw ''requested kubernetes moduleDefinition with name "${name}" does not exist'';
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
imports = [ ./k8s.nix ];
|
||||
|
||||
options.kubernetes.moduleDefinitions = mkOption {
|
||||
description = "Legacy kubenix attribute set of module definitions";
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule ({name, ...}: {
|
||||
default = { };
|
||||
type = types.attrsOf (types.submodule ({ name, ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Module definition name";
|
||||
|
|
@ -101,19 +104,19 @@ in {
|
|||
options = defaultModuleConfigurationOptions // {
|
||||
all = mkOption {
|
||||
description = "Module default configuration for all modules";
|
||||
type = types.coercedTo types.unspecified (value: [value]) (types.listOf types.unspecified);
|
||||
default = [];
|
||||
apply = filter (v: v != []);
|
||||
type = types.coercedTo types.unspecified (value: [ value ]) (types.listOf types.unspecified);
|
||||
default = [ ];
|
||||
apply = filter (v: v != [ ]);
|
||||
};
|
||||
};
|
||||
};
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
options.kubernetes.modules = mkOption {
|
||||
description = "Legacy kubenix attribute set of modules";
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule ({config, name, ...}: {
|
||||
default = { };
|
||||
type = types.attrsOf (types.submodule ({ config, name, ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Module name";
|
||||
|
|
@ -130,17 +133,19 @@ in {
|
|||
labels = mkOption {
|
||||
description = "Attribute set of module lables";
|
||||
type = types.attrsOf types.str;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
configuration = mkOption {
|
||||
description = "Module configuration";
|
||||
type = submoduleWithSpecialArgs {
|
||||
imports = mkModuleOptions (getModuleDefinition config.module) config;
|
||||
} {
|
||||
inherit kubenix;
|
||||
};
|
||||
default = {};
|
||||
type = submoduleWithSpecialArgs
|
||||
{
|
||||
imports = mkModuleOptions (getModuleDefinition config.module) config;
|
||||
}
|
||||
{
|
||||
inherit kubenix;
|
||||
};
|
||||
default = { };
|
||||
};
|
||||
|
||||
module = mkOption {
|
||||
|
|
@ -153,9 +158,9 @@ in {
|
|||
};
|
||||
|
||||
options.kubernetes.defaults = mkOption {
|
||||
type = types.attrsOf (types.coercedTo types.attrs (value: [value]) (types.listOf types.attrs));
|
||||
type = types.attrsOf (types.coercedTo types.attrs (value: [ value ]) (types.listOf types.attrs));
|
||||
description = "Legacy kubenix kubernetes defaults.";
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
# for back compatibility with kubernetes.customResources
|
||||
|
|
@ -163,50 +168,63 @@ in {
|
|||
|
||||
config = {
|
||||
kubernetes = mkMerge [{
|
||||
api.defaults = mapAttrsToList (attrName: default: let
|
||||
type = head (mapAttrsToList (_: v: v) (filterAttrs (_: type: type.attrName == attrName) config.kubernetes.api.types));
|
||||
in {
|
||||
default = { imports = default; };
|
||||
} // (if (attrName == "all") then {} else {
|
||||
resource = type.name;
|
||||
})) config.kubernetes.defaults;
|
||||
api.defaults = mapAttrsToList
|
||||
(attrName: default:
|
||||
let
|
||||
type = head (mapAttrsToList (_: v: v) (filterAttrs (_: type: type.attrName == attrName) config.kubernetes.api.types));
|
||||
in
|
||||
{
|
||||
default = { imports = default; };
|
||||
} // (if (attrName == "all") then { } else {
|
||||
resource = type.name;
|
||||
}))
|
||||
config.kubernetes.defaults;
|
||||
|
||||
resources = mkMerge (
|
||||
mapAttrsToList (name: module:
|
||||
mapAttrs' (_: type: let
|
||||
moduleDefinition = getModuleDefinition module.module;
|
||||
mapAttrsToList
|
||||
(name: module:
|
||||
mapAttrs'
|
||||
(_: type:
|
||||
let
|
||||
moduleDefinition = getModuleDefinition module.module;
|
||||
|
||||
moduleResources = module.configuration.kubernetes.api.resources.${type.attrName} or {};
|
||||
moduleResources = module.configuration.kubernetes.api.resources.${type.attrName} or { };
|
||||
|
||||
moduleConfig =
|
||||
if moduleDefinition.prefixResources && type.kind != "CustomResourceDefinition"
|
||||
then prefixResources (moduleToAttrs moduleResources) name
|
||||
else moduleToAttrs moduleResources;
|
||||
in nameValuePair type.attrName
|
||||
(if moduleDefinition.assignAsDefaults
|
||||
then mkAllDefault moduleConfig 1000
|
||||
else moduleConfig)
|
||||
) module.configuration.kubernetes.api.types
|
||||
) config.kubernetes.modules
|
||||
moduleConfig =
|
||||
if moduleDefinition.prefixResources && type.kind != "CustomResourceDefinition"
|
||||
then prefixResources (moduleToAttrs moduleResources) name
|
||||
else moduleToAttrs moduleResources;
|
||||
in
|
||||
nameValuePair type.attrName
|
||||
(if moduleDefinition.assignAsDefaults
|
||||
then mkAllDefault moduleConfig 1000
|
||||
else moduleConfig)
|
||||
)
|
||||
module.configuration.kubernetes.api.types
|
||||
)
|
||||
config.kubernetes.modules
|
||||
);
|
||||
|
||||
# custom types created from customResourceDefinitions
|
||||
customTypes =
|
||||
mapAttrsToList (name: crd: {
|
||||
group = crd.spec.group;
|
||||
version = crd.spec.version;
|
||||
kind = crd.spec.names.kind;
|
||||
name = crd.spec.names.plural;
|
||||
attrName = mkOptionDefault name;
|
||||
}) (config.kubernetes.resources.customResourceDefinitions or {});
|
||||
mapAttrsToList
|
||||
(name: crd: {
|
||||
group = crd.spec.group;
|
||||
version = crd.spec.version;
|
||||
kind = crd.spec.names.kind;
|
||||
name = crd.spec.names.plural;
|
||||
attrName = mkOptionDefault name;
|
||||
})
|
||||
(config.kubernetes.resources.customResourceDefinitions or { });
|
||||
|
||||
defaultModuleConfiguration.all = {
|
||||
_file = head options.kubernetes.defaultModuleConfiguration.files;
|
||||
config.kubernetes.version = mkDefault config.kubernetes.version;
|
||||
config.kubernetes.moduleDefinitions = config.kubernetes.moduleDefinitions;
|
||||
};
|
||||
} {
|
||||
resources = mkAliasDefinitions options.kubernetes.customResources;
|
||||
}];
|
||||
}
|
||||
{
|
||||
resources = mkAliasDefinitions options.kubernetes.customResources;
|
||||
}];
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,24 +26,24 @@ with lib;
|
|||
tags = mkOption {
|
||||
description = "List of submodule tags";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
exports = mkOption {
|
||||
description = "Attribute set of functions to export";
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
passthru = mkOption {
|
||||
description = "Attribute set to passthru";
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
args._empty = mkOption {};
|
||||
args._empty = mkOption { };
|
||||
};
|
||||
|
||||
config._module.args.args = config.submodule.args;
|
||||
config._m.features = ["submodule"];
|
||||
config._m.features = [ "submodule" ];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{ config, options, kubenix, pkgs, lib, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.submodules;
|
||||
parentConfig = config;
|
||||
|
|
@ -13,67 +12,82 @@ let
|
|||
else requiredVersion == version
|
||||
else true;
|
||||
|
||||
getDefaults = {name, version, tags, features}:
|
||||
catAttrs "default" (filter (submoduleDefault:
|
||||
(submoduleDefault.name == null || submoduleDefault.name == name) &&
|
||||
(matchesVersion submoduleDefault.version version) &&
|
||||
(
|
||||
(length submoduleDefault.tags == 0) ||
|
||||
(length (intersectLists submoduleDefault.tags tags)) > 0
|
||||
) &&
|
||||
(
|
||||
(length submoduleDefault.features == 0) ||
|
||||
(length (intersectLists submoduleDefault.features features)) > 0
|
||||
getDefaults = { name, version, tags, features }:
|
||||
catAttrs "default" (filter
|
||||
(submoduleDefault:
|
||||
(submoduleDefault.name == null || submoduleDefault.name == name) &&
|
||||
(matchesVersion submoduleDefault.version version) &&
|
||||
(
|
||||
(length submoduleDefault.tags == 0) ||
|
||||
(length (intersectLists submoduleDefault.tags tags)) > 0
|
||||
) &&
|
||||
(
|
||||
(length submoduleDefault.features == 0) ||
|
||||
(length (intersectLists submoduleDefault.features features)) > 0
|
||||
)
|
||||
)
|
||||
) config.submodules.defaults);
|
||||
config.submodules.defaults);
|
||||
|
||||
specialArgs = cfg.specialArgs // {
|
||||
parentConfig = config;
|
||||
};
|
||||
|
||||
findSubmodule = {name, version ? null, latest ? true}: let
|
||||
matchingSubmodules = filter (el:
|
||||
el.definition.name == name &&
|
||||
(matchesVersion version el.definition.version)
|
||||
) cfg.imports;
|
||||
findSubmodule = { name, version ? null, latest ? true }:
|
||||
let
|
||||
matchingSubmodules = filter
|
||||
(el:
|
||||
el.definition.name == name &&
|
||||
(matchesVersion version el.definition.version)
|
||||
)
|
||||
cfg.imports;
|
||||
|
||||
versionSortedSubmodules = sort (s1: s2:
|
||||
if builtins.compareVersions s1.definition.version s2.definition.version > 0
|
||||
then true else false
|
||||
) matchingSubmodules;
|
||||
versionSortedSubmodules = sort
|
||||
(s1: s2:
|
||||
if builtins.compareVersions s1.definition.version s2.definition.version > 0
|
||||
then true else false
|
||||
)
|
||||
matchingSubmodules;
|
||||
|
||||
matchingModule =
|
||||
if length versionSortedSubmodules == 0
|
||||
then throw "No module found ${name}/${if version == null then "latest" else version}"
|
||||
else head versionSortedSubmodules;
|
||||
in matchingModule;
|
||||
matchingModule =
|
||||
if length versionSortedSubmodules == 0
|
||||
then throw "No module found ${name}/${if version == null then "latest" else version}"
|
||||
else head versionSortedSubmodules;
|
||||
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);
|
||||
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" "_m" "submodules"]);
|
||||
in {
|
||||
_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" "_m" "submodules" ]);
|
||||
in
|
||||
{
|
||||
imports = [ ./base.nix ];
|
||||
|
||||
options = {
|
||||
submodules.specialArgs = mkOption {
|
||||
description = "Special args to pass to submodules. These arguments can be used for imports";
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
submodules.defaults = mkOption {
|
||||
description = "List of defaults to apply to submodule instances";
|
||||
type = types.listOf (types.submodule ({config, ...}: {
|
||||
type = types.listOf (types.submodule ({ config, ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Name of the submodule to apply defaults for";
|
||||
|
|
@ -93,23 +107,23 @@ in {
|
|||
tags = mkOption {
|
||||
description = "List of tags to apply defaults for";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
features = mkOption {
|
||||
description = "List of features that submodule has to have to apply defaults";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
default = mkOption {
|
||||
description = "Default to apply to submodule instance";
|
||||
type = types.unspecified;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
submodules.propagate.enable = mkOption {
|
||||
|
|
@ -123,139 +137,147 @@ in {
|
|||
type = types.listOf (
|
||||
types.coercedTo
|
||||
types.path
|
||||
(module: {inherit module;})
|
||||
(types.submodule ({name, config, ...}: let
|
||||
evaledSubmodule' = evalModules {
|
||||
inherit specialArgs;
|
||||
modules = config.modules ++ [ ./base.nix ];
|
||||
check = false;
|
||||
};
|
||||
|
||||
evaledSubmodule =
|
||||
if (!(elem "submodule" evaledSubmodule'.config._m.features))
|
||||
then throw "no submodule defined"
|
||||
else evaledSubmodule';
|
||||
in {
|
||||
options = {
|
||||
module = mkOption {
|
||||
description = "Module defining submodule";
|
||||
type = types.unspecified;
|
||||
(module: { inherit module; })
|
||||
(types.submodule ({ name, config, ... }:
|
||||
let
|
||||
evaledSubmodule' = evalModules {
|
||||
inherit specialArgs;
|
||||
modules = config.modules ++ [ ./base.nix ];
|
||||
check = false;
|
||||
};
|
||||
|
||||
modules = mkOption {
|
||||
description = "List of modules defining submodule";
|
||||
type = types.listOf types.unspecified;
|
||||
default = [config.module];
|
||||
evaledSubmodule =
|
||||
if (!(elem "submodule" evaledSubmodule'.config._m.features))
|
||||
then throw "no submodule defined"
|
||||
else evaledSubmodule';
|
||||
in
|
||||
{
|
||||
options = {
|
||||
module = mkOption {
|
||||
description = "Module defining submodule";
|
||||
type = types.unspecified;
|
||||
};
|
||||
|
||||
modules = mkOption {
|
||||
description = "List of modules defining submodule";
|
||||
type = types.listOf types.unspecified;
|
||||
default = [ config.module ];
|
||||
};
|
||||
|
||||
features = mkOption {
|
||||
description = "List of features exposed by submodule";
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
|
||||
definition = mkOption {
|
||||
description = "Submodule definition";
|
||||
type = types.attrs;
|
||||
};
|
||||
|
||||
exportAs = mkOption {
|
||||
description = "Name under which to register exports";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
features = mkOption {
|
||||
description = "List of features exposed by submodule";
|
||||
type = types.listOf types.str;
|
||||
};
|
||||
config = {
|
||||
definition = {
|
||||
inherit (evaledSubmodule.config.submodule) name description version tags exports;
|
||||
};
|
||||
|
||||
definition = mkOption {
|
||||
description = "Submodule definition";
|
||||
type = types.attrs;
|
||||
features = evaledSubmodule.config._m.features;
|
||||
};
|
||||
|
||||
exportAs = mkOption {
|
||||
description = "Name under which to register exports";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
definition = {
|
||||
inherit (evaledSubmodule.config.submodule) name description version tags exports;
|
||||
};
|
||||
|
||||
features = evaledSubmodule.config._m.features;
|
||||
};
|
||||
})
|
||||
)
|
||||
})
|
||||
)
|
||||
);
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
submodules.instances = mkOption {
|
||||
description = "Attribute set of submodule instances";
|
||||
default = {};
|
||||
type = types.attrsOf (types.submodule ({name, config, options, ...}: let
|
||||
# submodule associated with
|
||||
submodule = findSubmodule {
|
||||
name = config.submodule;
|
||||
version = config.version;
|
||||
};
|
||||
|
||||
# definition of a submodule
|
||||
submoduleDefinition = submodule.definition;
|
||||
|
||||
# submodule defaults
|
||||
defaults = getDefaults {
|
||||
name = submoduleDefinition.name;
|
||||
version = submoduleDefinition.version;
|
||||
tags = submoduleDefinition.tags;
|
||||
features = submodule.features;
|
||||
};
|
||||
in {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Submodule instance name";
|
||||
type = types.str;
|
||||
default = name;
|
||||
default = { };
|
||||
type = types.attrsOf (types.submodule ({ name, config, options, ... }:
|
||||
let
|
||||
# submodule associated with
|
||||
submodule = findSubmodule {
|
||||
name = config.submodule;
|
||||
version = config.version;
|
||||
};
|
||||
|
||||
submodule = mkOption {
|
||||
description = "Name of the submodule to use";
|
||||
type = types.str;
|
||||
default = name;
|
||||
};
|
||||
# definition of a submodule
|
||||
submoduleDefinition = submodule.definition;
|
||||
|
||||
version = mkOption {
|
||||
description = ''
|
||||
Version of submodule to use, if version starts with "~" it is
|
||||
threated as regex pattern for example "~1.0.*"
|
||||
'';
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
# submodule defaults
|
||||
defaults = getDefaults {
|
||||
name = submoduleDefinition.name;
|
||||
version = submoduleDefinition.version;
|
||||
tags = submoduleDefinition.tags;
|
||||
features = submodule.features;
|
||||
};
|
||||
in
|
||||
{
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Submodule instance name";
|
||||
type = types.str;
|
||||
default = name;
|
||||
};
|
||||
|
||||
passthru.enable = mkOption {
|
||||
description = "Whether to passthru submodule resources";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
submodule = mkOption {
|
||||
description = "Name of the submodule to use";
|
||||
type = types.str;
|
||||
default = name;
|
||||
};
|
||||
|
||||
config = mkOption {
|
||||
description = "Submodule instance ${config.name} for ${submoduleDefinition.name}:${submoduleDefinition.version} config";
|
||||
type = submoduleWithSpecialArgs ({...}: {
|
||||
imports = submodule.modules ++ defaults ++ [ ./base.nix ];
|
||||
_module.args.pkgs = pkgs;
|
||||
_module.args.name = config.name;
|
||||
_module.args.submodule = config;
|
||||
submodule.args = mkAliasDefinitions options.args;
|
||||
}) specialArgs;
|
||||
default = {};
|
||||
};
|
||||
version = mkOption {
|
||||
description = ''
|
||||
Version of submodule to use, if version starts with "~" it is
|
||||
threated as regex pattern for example "~1.0.*"
|
||||
'';
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
|
||||
args = mkOption {
|
||||
description = "Submodule arguments (alias of config.submodule.args)";
|
||||
passthru.enable = mkOption {
|
||||
description = "Whether to passthru submodule resources";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
config = mkOption {
|
||||
description = "Submodule instance ${config.name} for ${submoduleDefinition.name}:${submoduleDefinition.version} config";
|
||||
type = submoduleWithSpecialArgs
|
||||
({ ... }: {
|
||||
imports = submodule.modules ++ defaults ++ [ ./base.nix ];
|
||||
_module.args.pkgs = pkgs;
|
||||
_module.args.name = config.name;
|
||||
_module.args.submodule = config;
|
||||
submodule.args = mkAliasDefinitions options.args;
|
||||
})
|
||||
specialArgs;
|
||||
default = { };
|
||||
};
|
||||
|
||||
args = mkOption {
|
||||
description = "Submodule arguments (alias of config.submodule.args)";
|
||||
};
|
||||
};
|
||||
};
|
||||
}));
|
||||
}));
|
||||
};
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
config = mkMerge ([
|
||||
{
|
||||
# register exported functions as args
|
||||
_module.args = mkMerge (map (submodule: {
|
||||
${submodule.exportAs} = submodule.definition.exports;
|
||||
}) (filter (submodule: submodule.exportAs != null) cfg.imports));
|
||||
_module.args = mkMerge (map
|
||||
(submodule: {
|
||||
${submodule.exportAs} = submodule.definition.exports;
|
||||
})
|
||||
(filter (submodule: submodule.exportAs != null) cfg.imports));
|
||||
|
||||
_m.features = ["submodules"];
|
||||
_m.features = [ "submodules" ];
|
||||
|
||||
submodules.specialArgs.kubenix = kubenix;
|
||||
|
||||
|
|
@ -267,17 +289,19 @@ in {
|
|||
};
|
||||
}]
|
||||
|
||||
(map (propagate: {
|
||||
features = propagate.features;
|
||||
default = propagate.module;
|
||||
}) config._m.propagate)
|
||||
(map
|
||||
(propagate: {
|
||||
features = propagate.features;
|
||||
default = propagate.module;
|
||||
})
|
||||
config._m.propagate)
|
||||
];
|
||||
}
|
||||
|
||||
(mkIf cfg.propagate.enable {
|
||||
# if propagate is enabled and submodule has submodules included propagage defaults and imports
|
||||
submodules.defaults = [{
|
||||
features = ["submodules"];
|
||||
features = [ "submodules" ];
|
||||
default = {
|
||||
submodules = {
|
||||
defaults = cfg.defaults;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{ nixosPath, config, pkgs, lib, kubenix, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.testing;
|
||||
|
||||
|
|
@ -18,7 +17,8 @@ let
|
|||
isTestEnabled = test:
|
||||
(cfg.enabledTests == null || elem test.name cfg.enabledTests) && test.enable;
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./docker.nix
|
||||
./driver/kubetest.nix
|
||||
|
|
@ -40,30 +40,32 @@ in {
|
|||
|
||||
defaults = mkOption {
|
||||
description = "List of defaults to apply to tests";
|
||||
type = types.listOf (types.submodule ({config, ...}: {
|
||||
type = types.listOf (types.submodule ({ config, ... }: {
|
||||
options = {
|
||||
features = mkOption {
|
||||
description = "List of features that test has to have to apply defaults";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
default = mkOption {
|
||||
description = "Default to apply to test";
|
||||
type = types.unspecified;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
tests = mkOption {
|
||||
description = "List of test cases";
|
||||
default = [];
|
||||
type = types.listOf (types.coercedTo types.path (module: {
|
||||
inherit module;
|
||||
}) (types.submodule testModule));
|
||||
default = [ ];
|
||||
type = types.listOf (types.coercedTo types.path
|
||||
(module: {
|
||||
inherit module;
|
||||
})
|
||||
(types.submodule testModule));
|
||||
apply = tests: filter isTestEnabled tests;
|
||||
};
|
||||
|
||||
|
|
@ -82,7 +84,7 @@ in {
|
|||
args = mkOption {
|
||||
description = "Attribute set of extra args passed to tests";
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
success = mkOption {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
with import ../../lib/docker.nix { inherit lib pkgs; };
|
||||
|
||||
with import ../../lib/docker.nix { inherit lib pkgs; };
|
||||
let
|
||||
testing = config.testing;
|
||||
|
||||
allImages = flatten (map (t: t.evaled.config.docker.export or []) testing.tests);
|
||||
allImages = flatten (map (t: t.evaled.config.docker.export or [ ]) testing.tests);
|
||||
|
||||
cfg = config.testing.docker;
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.docker = {
|
||||
registryUrl = mkOption {
|
||||
description = "Docker registry url";
|
||||
|
|
@ -38,7 +38,7 @@ in {
|
|||
};
|
||||
|
||||
config.testing.defaults = [{
|
||||
features = ["docker"];
|
||||
features = [ "docker" ];
|
||||
default = {
|
||||
docker.registry.url = cfg.registryUrl;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
testing = config.testing;
|
||||
cfg = testing.driver.kubetest;
|
||||
|
||||
kubetest = import ./kubetestdrv.nix {inherit pkgs;};
|
||||
kubetest = import ./kubetestdrv.nix { inherit pkgs; };
|
||||
|
||||
pythonEnv = pkgs.python38.withPackages (ps: with ps; [
|
||||
pytest
|
||||
|
|
@ -16,18 +15,20 @@ let
|
|||
|
||||
toTestScript = t:
|
||||
if isString t.script
|
||||
then pkgs.writeText "${t.name}.py" ''
|
||||
${cfg.defaultHeader}
|
||||
${t.script}
|
||||
''
|
||||
then
|
||||
pkgs.writeText "${t.name}.py" ''
|
||||
${cfg.defaultHeader}
|
||||
${t.script}
|
||||
''
|
||||
else t.script;
|
||||
|
||||
tests = pkgs.linkFarm "${testing.name}-tests" (
|
||||
map (t: {
|
||||
path = toTestScript t;
|
||||
name = "${t.name}_test.py";
|
||||
})
|
||||
( filter (t: t.script != null) testing.tests )
|
||||
map
|
||||
(t: {
|
||||
path = toTestScript t;
|
||||
name = "${t.name}_test.py";
|
||||
})
|
||||
(filter (t: t.script != null) testing.tests)
|
||||
);
|
||||
|
||||
testScript = pkgs.writeScript "test-${testing.name}.sh" ''
|
||||
|
|
@ -35,7 +36,8 @@ let
|
|||
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
|
||||
'';
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.driver.kubetest = {
|
||||
defaultHeader = mkOption {
|
||||
type = types.lines;
|
||||
|
|
@ -48,7 +50,7 @@ in {
|
|||
extraPackages = mkOption {
|
||||
type = types.listOf types.package;
|
||||
description = "Extra packages to pass to tests";
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{ lib, config, testing, kubenix, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
modules = [
|
||||
# testing module
|
||||
|
|
@ -36,25 +35,29 @@ let
|
|||
|
||||
# defaults that can be applied on tests
|
||||
defaults =
|
||||
filter (d:
|
||||
(intersectLists d.features testFeatures) == d.features ||
|
||||
(length d.features) == 0
|
||||
) testing.defaults;
|
||||
filter
|
||||
(d:
|
||||
(intersectLists d.features testFeatures) == d.features ||
|
||||
(length d.features) == 0
|
||||
)
|
||||
testing.defaults;
|
||||
|
||||
# add default modules to all modules
|
||||
modulesWithDefaults = modules ++ (map (d: d.default) defaults);
|
||||
|
||||
# evaled test
|
||||
evaled = let
|
||||
evaled' = kubenix.evalModules {
|
||||
modules = modulesWithDefaults;
|
||||
};
|
||||
in
|
||||
evaled =
|
||||
let
|
||||
evaled' = kubenix.evalModules {
|
||||
modules = modulesWithDefaults;
|
||||
};
|
||||
in
|
||||
if testing.throwError then evaled'
|
||||
else if (builtins.tryEval evaled'.config.test.assertions).success
|
||||
then evaled' else null;
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
options = {
|
||||
module = mkOption {
|
||||
description = "Module defining kubenix test";
|
||||
|
|
@ -97,7 +100,7 @@ in {
|
|||
description = "Test result";
|
||||
type = types.unspecified;
|
||||
internal = true;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
script = mkOption {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
testing = config.testing;
|
||||
|
||||
|
|
@ -32,7 +31,8 @@ let
|
|||
echo "--> running tests"
|
||||
${testing.testScript} --kube-config=$KUBECONFIG
|
||||
'';
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.runtime.local = {
|
||||
script = mkOption {
|
||||
type = types.package;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
}:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
testing = config.testing;
|
||||
kubeconfig = "/etc/${config.services.kubernetes.pki.etcClusterAdminKubeconfig}";
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.test;
|
||||
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.test = {
|
||||
name = mkOption {
|
||||
description = "Test name";
|
||||
|
|
@ -38,8 +38,8 @@ in {
|
|||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
example = [ { assertion = false; message = "you can't enable this for some reason"; } ];
|
||||
default = [ ];
|
||||
example = [{ assertion = false; message = "you can't enable this for some reason"; }];
|
||||
description = ''
|
||||
This option allows modules to express conditions that must
|
||||
hold for the evaluation of the system configuration to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue