kubenix/test/modules.nix

58 lines
1.3 KiB
Nix
Raw Normal View History

2017-11-11 11:52:17 +01:00
{lib, k8s, ...}:
2017-11-11 13:42:15 +01:00
with k8s;
2017-11-11 11:52:17 +01:00
with lib;
{
config = {
kubernetes.moduleDefinitions.nginx.module = {name, config, ...}: {
options = {
port = mkOption {
description = "Port for nginx to listen on";
type = types.int;
default = 80;
};
2017-11-11 13:42:15 +01:00
password = mkValueOrSecretOption {
description = "Nginx simple auth credentials";
default.secret = "test";
};
2017-11-11 11:52:17 +01:00
};
config = {
kubernetes.resources.deployments.nginx = mkMerge [
2017-11-11 13:42:15 +01:00
(loadJSON ./deployment.json)
2017-11-11 11:52:17 +01:00
{
metadata.name = "${name}-nginx";
spec.template.spec.containers.nginx.ports."80" = {
containerPort = config.port;
};
2017-11-11 13:42:15 +01:00
spec.template.spec.containers.nginx.env.name = config.password;
2017-11-11 11:52:17 +01:00
}
];
kubernetes.resources.configMaps.nginx = mkMerge [
2017-11-11 13:42:15 +01:00
(loadJSON ./configMap.json)
2017-11-11 11:52:17 +01:00
{
metadata.name = mkForce "${name}-nginx";
}
];
};
};
kubernetes.modules.app-v1.module = "nginx";
kubernetes.modules.app-v2 = {
module = "nginx";
configuration.port = 8080;
};
2017-11-11 13:42:15 +01:00
kubernetes.resources.services.nginx = loadJSON ./service.json;
2017-11-11 11:52:17 +01:00
kubernetes.defaultModuleConfiguration = [{
kubernetes.defaults.deployments.spec.replicas = 3;
}];
};
}