mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
move past legacy compat
This commit is contained in:
parent
d1ad09a897
commit
70d249aaff
6 changed files with 1 additions and 507 deletions
|
|
@ -31,9 +31,6 @@ let
|
|||
./k8s/order.nix
|
||||
./k8s/submodule.nix
|
||||
./k8s/imports.nix
|
||||
#./legacy/k8s.nix
|
||||
#./legacy/crd.nix
|
||||
#./legacy/modules.nix
|
||||
# ./helm/simple.nix
|
||||
# ./istio/bookinfo.nix # infinite recursion
|
||||
./submodules/simple.nix
|
||||
|
|
|
|||
|
|
@ -1,108 +0,0 @@
|
|||
{ options, config, lib, kubenix, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
findObject = { kind, name }: filter
|
||||
(object:
|
||||
object.kind == kind && object.metadata.name == name
|
||||
)
|
||||
config.kubernetes.objects;
|
||||
|
||||
getObject = filter: head (findObject filter);
|
||||
|
||||
hasObject = { kind, name }: length (findObject { inherit kind name; }) == 1;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s legacy ];
|
||||
|
||||
test = {
|
||||
name = "legacy-crd";
|
||||
description = "Simple test tesing kubenix legacy integration with crds crd";
|
||||
enable = builtins.compareVersions config.kubernetes.version "1.15" <= 0;
|
||||
assertions = [{
|
||||
message = "should define crd in module";
|
||||
assertion =
|
||||
hasObject { kind = "SecretClaim"; name = "module-claim"; };
|
||||
}
|
||||
{
|
||||
message = "should define crd in root";
|
||||
assertion =
|
||||
hasObject { kind = "SecretClaim"; name = "root-claim"; };
|
||||
}];
|
||||
};
|
||||
|
||||
kubernetes.namespace = "test";
|
||||
|
||||
kubernetes.moduleDefinitions.secret-claim.module = { config, k8s, module, ... }: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Name of the secret claim";
|
||||
type = types.str;
|
||||
default = module.name;
|
||||
};
|
||||
|
||||
type = mkOption {
|
||||
description = "Type of the secret";
|
||||
type = types.enum [ "Opaque" "kubernetes.io/tls" ];
|
||||
default = "Opaque";
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
description = "Secret path";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
renew = mkOption {
|
||||
description = "Renew time in seconds";
|
||||
type = types.nullOr types.int;
|
||||
default = null;
|
||||
};
|
||||
|
||||
data = mkOption {
|
||||
type = types.nullOr types.attrs;
|
||||
description = "Data to pass to get secrets";
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
kubernetes.resources.customResourceDefinitions.secret-claims = {
|
||||
kind = "CustomResourceDefinition";
|
||||
apiVersion = "apiextensions.k8s.io/v1beta1";
|
||||
metadata.name = "secretclaims.vaultproject.io";
|
||||
spec = {
|
||||
group = "vaultproject.io";
|
||||
version = "v1";
|
||||
scope = "Namespaced";
|
||||
names = {
|
||||
plural = "secretclaims";
|
||||
kind = "SecretClaim";
|
||||
shortNames = [ "scl" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.customResources.secret-claims.claim = {
|
||||
metadata.name = config.name;
|
||||
spec = {
|
||||
inherit (config) type path;
|
||||
} // (optionalAttrs (config.renew != null) {
|
||||
inherit (config) renew;
|
||||
}) // (optionalAttrs (config.data != null) {
|
||||
inherit (config) data;
|
||||
});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.modules.module-claim = {
|
||||
module = "secret-claim";
|
||||
configuration.path = "tokens/test";
|
||||
};
|
||||
|
||||
kubernetes.customResources.secret-claims.root-claim = {
|
||||
spec = {
|
||||
path = "secrets/test2";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,56 +0,0 @@
|
|||
{ config, lib, kubenix, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
cfg = config.kubernetes.api.resources.deployments.app;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s legacy ];
|
||||
|
||||
test = {
|
||||
name = "legacy-k8s";
|
||||
description = "Simple test kubenix legacy kubernetes support";
|
||||
assertions = [{
|
||||
message = "should have correct resource options set";
|
||||
assertion =
|
||||
cfg.kind == "Deployment" &&
|
||||
cfg.metadata.name == "app";
|
||||
}
|
||||
{
|
||||
message = "should have correct defaults set";
|
||||
assertion =
|
||||
cfg.metadata.namespace == "test" &&
|
||||
cfg.metadata.labels.label1 == "value1" &&
|
||||
cfg.metadata.labels.label2 == "value2";
|
||||
}];
|
||||
};
|
||||
|
||||
kubernetes.resources.deployments.app = {
|
||||
spec = {
|
||||
replicas = 2;
|
||||
selector = {
|
||||
matchLabels.app = "app";
|
||||
};
|
||||
template.spec = {
|
||||
containers.app = {
|
||||
image = "hello-world";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.resources.configMaps.app = {
|
||||
data."my-conf.json" = builtins.toJSON { };
|
||||
};
|
||||
|
||||
kubernetes.defaults = {
|
||||
all = [{
|
||||
metadata.namespace = "test";
|
||||
metadata.labels.label1 = "value1";
|
||||
}];
|
||||
|
||||
deployments = [{
|
||||
metadata.labels.label2 = "value2";
|
||||
}];
|
||||
};
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
{ options, config, lib, kubenix, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
findObject = { kind, name }: filter
|
||||
(object:
|
||||
object.kind == kind && object.metadata.name == name
|
||||
)
|
||||
config.kubernetes.objects;
|
||||
|
||||
getObject = filter: head (findObject filter);
|
||||
|
||||
hasObject = { kind, name }: length (findObject { inherit kind name; }) == 1;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s legacy ];
|
||||
|
||||
test = {
|
||||
name = "legacy-modules";
|
||||
description = "Simple test tesing kubenix legacy modules";
|
||||
assertions = [{
|
||||
message = "should have all objects";
|
||||
assertion =
|
||||
hasObject { kind = "Deployment"; name = "myapp"; } &&
|
||||
hasObject { kind = "Deployment"; name = "myapp2"; } &&
|
||||
hasObject { kind = "Deployment"; name = "myapp2-app2"; };
|
||||
}
|
||||
{
|
||||
message = "should have default labels set";
|
||||
assertion =
|
||||
(getObject { kind = "Deployment"; name = "myapp2-app2"; }).metadata.labels.module-label or false == "value" &&
|
||||
(getObject { kind = "Deployment"; name = "myapp2"; }).metadata.labels.module-label or false == "value";
|
||||
}
|
||||
{
|
||||
message = "should passthru resources to root module";
|
||||
assertion =
|
||||
config.kubernetes.resources.deployments.myapp2-app2-app.metadata.labels.module-label or false == "value";
|
||||
}];
|
||||
};
|
||||
|
||||
kubernetes.defaults.all.metadata.labels.module-label = "value";
|
||||
|
||||
# propagate default module configuration and defaults
|
||||
kubernetes.defaultModuleConfiguration = {
|
||||
all.kubernetes.defaultModuleConfiguration = mkAliasDefinitions options.kubernetes.defaultModuleConfiguration;
|
||||
all.kubernetes.defaults = mkAliasDefinitions options.kubernetes.defaults;
|
||||
};
|
||||
|
||||
kubernetes.moduleDefinitions.app1.module = { config, k8s, module, ... }: {
|
||||
config.kubernetes.resources.deployments.app = {
|
||||
metadata.name = module.name;
|
||||
spec = {
|
||||
selector = {
|
||||
matchLabels.app = "app";
|
||||
};
|
||||
template.spec = {
|
||||
containers.app = {
|
||||
image = "hello-world";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.moduleDefinitions.app2.module = { name, config, k8s, module, ... }: {
|
||||
options = {
|
||||
replicas = mkOption {
|
||||
description = "Number of replicas to run";
|
||||
type = types.int;
|
||||
default = 2;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
kubernetes.resources.deployments.app = {
|
||||
metadata.name = module.name;
|
||||
spec = {
|
||||
replicas = config.replicas;
|
||||
selector = {
|
||||
matchLabels.app = "app";
|
||||
};
|
||||
template.spec = {
|
||||
containers.app = {
|
||||
image = "hello-world";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.modules.app2 = {
|
||||
name = "${name}-app2";
|
||||
module = "app1";
|
||||
namespace = module.namespace;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.modules.myapp = {
|
||||
module = "app1";
|
||||
namespace = "test";
|
||||
};
|
||||
|
||||
kubernetes.modules.myapp2 = {
|
||||
module = "app2";
|
||||
namespace = "test";
|
||||
configuration.replicas = 3;
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue