mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
fmt
This commit is contained in:
parent
a0ce293db8
commit
60592d3096
55 changed files with 23668 additions and 30925 deletions
|
|
@ -1,20 +1,25 @@
|
|||
{ config, lib, kubenix, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
latestCrontab = config.kubernetes.api.resources.cronTabs.latest;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s ];
|
||||
config,
|
||||
lib,
|
||||
kubenix,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
latestCrontab = config.kubernetes.api.resources.cronTabs.latest;
|
||||
in {
|
||||
imports = with kubenix.modules; [test k8s];
|
||||
|
||||
test = {
|
||||
name = "k8s-crd";
|
||||
description = "Simple test tesing CRD";
|
||||
enable = builtins.compareVersions config.kubernetes.version "1.8" >= 0;
|
||||
assertions = [{
|
||||
message = "Custom resource should have correct version set";
|
||||
assertion = latestCrontab.apiVersion == "stable.example.com/v2";
|
||||
}];
|
||||
assertions = [
|
||||
{
|
||||
message = "Custom resource should have correct version set";
|
||||
assertion = latestCrontab.apiVersion == "stable.example.com/v2";
|
||||
}
|
||||
];
|
||||
script = ''
|
||||
@pytest.mark.applymanifest('${config.kubernetes.resultYAML}')
|
||||
def test_testing_module(kube):
|
||||
|
|
@ -50,7 +55,6 @@ in
|
|||
type = types.str;
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
{
|
||||
group = "stable.example.com";
|
||||
|
|
|
|||
|
|
@ -1,20 +1,23 @@
|
|||
{ config, lib, kubenix, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
kubenix,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
pod1 = config.kubernetes.api.resources.pods.pod1;
|
||||
pod2 = config.kubernetes.api.resources.pods.pod2;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s ];
|
||||
in {
|
||||
imports = with kubenix.modules; [test k8s];
|
||||
|
||||
test = {
|
||||
name = "k8s-defaults";
|
||||
description = "Simple k8s testing wheter name, apiVersion and kind are preset";
|
||||
assertions = [{
|
||||
message = "Should have label set with resource";
|
||||
assertion = pod1.metadata.labels.resource-label == "value";
|
||||
}
|
||||
assertions = [
|
||||
{
|
||||
message = "Should have label set with resource";
|
||||
assertion = pod1.metadata.labels.resource-label == "value";
|
||||
}
|
||||
{
|
||||
message = "Should have default label set with group, version, kind";
|
||||
assertion = pod1.metadata.labels.gvk-label == "value";
|
||||
|
|
@ -22,19 +25,21 @@ in
|
|||
{
|
||||
message = "Should have conditional annotation set";
|
||||
assertion = pod2.metadata.annotations.conditional-annotation == "value";
|
||||
}];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
kubernetes.resources.pods.pod1 = { };
|
||||
kubernetes.resources.pods.pod1 = {};
|
||||
|
||||
kubernetes.resources.pods.pod2 = {
|
||||
metadata.labels.custom-label = "value";
|
||||
};
|
||||
|
||||
kubernetes.api.defaults = [{
|
||||
resource = "pods";
|
||||
default.metadata.labels.resource-label = "value";
|
||||
}
|
||||
kubernetes.api.defaults = [
|
||||
{
|
||||
resource = "pods";
|
||||
default.metadata.labels.resource-label = "value";
|
||||
}
|
||||
{
|
||||
group = "core";
|
||||
kind = "Pod";
|
||||
|
|
@ -43,10 +48,11 @@ in
|
|||
}
|
||||
{
|
||||
resource = "pods";
|
||||
default = { config, ... }: {
|
||||
default = {config, ...}: {
|
||||
config.metadata.annotations = mkIf (config.metadata.labels ? "custom-label") {
|
||||
conditional-annotation = "value";
|
||||
};
|
||||
};
|
||||
}];
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,13 @@
|
|||
{ config, lib, pkgs, kubenix, images, test, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
kubenix,
|
||||
images,
|
||||
test,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.kubernetes.api.resources.deployments.nginx;
|
||||
image = images.nginx;
|
||||
|
||||
|
|
@ -12,30 +18,31 @@ let
|
|||
namespace = config.kubernetes.namespace;
|
||||
name = "curl";
|
||||
};
|
||||
spec.containers = [{
|
||||
name = "curl";
|
||||
image = config.docker.images.curl.path;
|
||||
args = [ "curl" "--retry" "20" "--retry-connrefused" "http://nginx" ];
|
||||
}];
|
||||
spec.containers = [
|
||||
{
|
||||
name = "curl";
|
||||
image = config.docker.images.curl.path;
|
||||
args = ["curl" "--retry" "20" "--retry-connrefused" "http://nginx"];
|
||||
}
|
||||
];
|
||||
spec.restartPolicy = "Never";
|
||||
});
|
||||
|
||||
in
|
||||
{
|
||||
imports = [ kubenix.modules.test kubenix.modules.k8s kubenix.modules.docker ];
|
||||
in {
|
||||
imports = [kubenix.modules.test kubenix.modules.k8s kubenix.modules.docker];
|
||||
|
||||
test = {
|
||||
name = "k8s-deployment";
|
||||
description = "Simple k8s testing a simple deployment";
|
||||
assertions = [{
|
||||
message = "should have correct apiVersion and kind set";
|
||||
assertion =
|
||||
if ((builtins.compareVersions config.kubernetes.version "1.7") <= 0)
|
||||
then cfg.apiVersion == "apps/v1beta1"
|
||||
else if ((builtins.compareVersions config.kubernetes.version "1.8") <= 0)
|
||||
then cfg.apiVersion == "apps/v1beta2"
|
||||
else cfg.apiVersion == "apps/v1";
|
||||
}
|
||||
assertions = [
|
||||
{
|
||||
message = "should have correct apiVersion and kind set";
|
||||
assertion =
|
||||
if ((builtins.compareVersions config.kubernetes.version "1.7") <= 0)
|
||||
then cfg.apiVersion == "apps/v1beta1"
|
||||
else if ((builtins.compareVersions config.kubernetes.version "1.8") <= 0)
|
||||
then cfg.apiVersion == "apps/v1beta2"
|
||||
else cfg.apiVersion == "apps/v1";
|
||||
}
|
||||
{
|
||||
message = "should have corrent kind set";
|
||||
assertion = cfg.kind == "Deployment";
|
||||
|
|
@ -43,7 +50,8 @@ in
|
|||
{
|
||||
message = "should have replicas set";
|
||||
assertion = cfg.spec.replicas == 3;
|
||||
}];
|
||||
}
|
||||
];
|
||||
script = ''
|
||||
import time
|
||||
|
||||
|
|
@ -97,10 +105,12 @@ in
|
|||
|
||||
kubernetes.resources.services.nginx = {
|
||||
spec = {
|
||||
ports = [{
|
||||
name = "http";
|
||||
port = 80;
|
||||
}];
|
||||
ports = [
|
||||
{
|
||||
name = "http";
|
||||
port = 80;
|
||||
}
|
||||
];
|
||||
selector.app = "nginx";
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,25 +1,29 @@
|
|||
{ config, lib, kubenix, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
kubenix,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
pod = config.kubernetes.api.resources.core.v1.Pod.test;
|
||||
deployment = config.kubernetes.api.resources.apps.v1.Deployment.nginx-deployment;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s ];
|
||||
in {
|
||||
imports = with kubenix.modules; [test k8s];
|
||||
|
||||
test = {
|
||||
name = "k8s-imports";
|
||||
description = "Simple k8s testing imports";
|
||||
enable = builtins.compareVersions config.kubernetes.version "1.10" >= 0;
|
||||
assertions = [{
|
||||
message = "Pod should have name set";
|
||||
assertion = pod.metadata.name == "test";
|
||||
}
|
||||
assertions = [
|
||||
{
|
||||
message = "Pod should have name set";
|
||||
assertion = pod.metadata.name == "test";
|
||||
}
|
||||
{
|
||||
message = "Deployment should have name set";
|
||||
assertion = deployment.metadata.name == "nginx-deployment";
|
||||
}];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
kubernetes.imports = [
|
||||
|
|
|
|||
|
|
@ -1,22 +1,28 @@
|
|||
{ config, lib, kubenix, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
cfg = config.kubernetes.api.resources.customResourceDefinitions.crontabs;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test k8s ];
|
||||
config,
|
||||
lib,
|
||||
kubenix,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.kubernetes.api.resources.customResourceDefinitions.crontabs;
|
||||
in {
|
||||
imports = with kubenix.modules; [test k8s];
|
||||
|
||||
test = {
|
||||
name = "k8s-order";
|
||||
description = "test tesing k8s resource order";
|
||||
assertions = [{
|
||||
message = "should have correct order of resources";
|
||||
assertion =
|
||||
(elemAt config.kubernetes.objects 0).kind == "CustomResourceDefinition" &&
|
||||
(elemAt config.kubernetes.objects 1).kind == "Namespace" &&
|
||||
(elemAt config.kubernetes.objects 2).kind == "CronTab";
|
||||
}];
|
||||
assertions = [
|
||||
{
|
||||
message = "should have correct order of resources";
|
||||
assertion =
|
||||
(elemAt config.kubernetes.objects 0).kind
|
||||
== "CustomResourceDefinition"
|
||||
&& (elemAt config.kubernetes.objects 1).kind == "Namespace"
|
||||
&& (elemAt config.kubernetes.objects 2).kind == "CronTab";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
kubernetes.resources.customResourceDefinitions.crontabs = {
|
||||
|
|
@ -24,38 +30,42 @@ in
|
|||
metadata.name = "crontabs.stable.example.com";
|
||||
spec = {
|
||||
group = "stable.example.com";
|
||||
versions = [{
|
||||
name = "v1";
|
||||
served = true;
|
||||
schema = true;
|
||||
}];
|
||||
versions = [
|
||||
{
|
||||
name = "v1";
|
||||
served = true;
|
||||
schema = true;
|
||||
}
|
||||
];
|
||||
scope = "Namespaced";
|
||||
names = {
|
||||
plural = "crontabs";
|
||||
singular = "crontab";
|
||||
kind = "CronTab";
|
||||
shortNames = [ "ct" ];
|
||||
shortNames = ["ct"];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.customTypes = [{
|
||||
name = "crontabs";
|
||||
description = "CronTabs resources";
|
||||
kubernetes.customTypes = [
|
||||
{
|
||||
name = "crontabs";
|
||||
description = "CronTabs resources";
|
||||
|
||||
attrName = "cronTabs";
|
||||
group = "stable.example.com";
|
||||
version = "v1";
|
||||
kind = "CronTab";
|
||||
module = {
|
||||
options.schedule = mkOption {
|
||||
description = "Crontab schedule script";
|
||||
type = types.str;
|
||||
attrName = "cronTabs";
|
||||
group = "stable.example.com";
|
||||
version = "v1";
|
||||
kind = "CronTab";
|
||||
module = {
|
||||
options.schedule = mkOption {
|
||||
description = "Crontab schedule script";
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
};
|
||||
}];
|
||||
}
|
||||
];
|
||||
|
||||
kubernetes.resources.namespaces.test = { };
|
||||
kubernetes.resources.namespaces.test = {};
|
||||
|
||||
kubernetes.resources."stable.example.com"."v1".CronTab.crontab.spec.schedule = "* * * * *";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,26 @@
|
|||
{ config, kubenix, ... }:
|
||||
let
|
||||
cfg = config.kubernetes.api.resources.pods.nginx;
|
||||
in
|
||||
{
|
||||
imports = [ kubenix.modules.test kubenix.modules.k8s ];
|
||||
config,
|
||||
kubenix,
|
||||
...
|
||||
}: let
|
||||
cfg = config.kubernetes.api.resources.pods.nginx;
|
||||
in {
|
||||
imports = [kubenix.modules.test kubenix.modules.k8s];
|
||||
|
||||
test = {
|
||||
name = "k8s-simple";
|
||||
description = "Simple k8s testing wheter name, apiVersion and kind are preset";
|
||||
assertions = [{
|
||||
message = "should have apiVersion and kind set";
|
||||
assertion = cfg.apiVersion == "v1" && cfg.kind == "Pod";
|
||||
}
|
||||
assertions = [
|
||||
{
|
||||
message = "should have apiVersion and kind set";
|
||||
assertion = cfg.apiVersion == "v1" && cfg.kind == "Pod";
|
||||
}
|
||||
{
|
||||
message = "should have name set";
|
||||
assertion = cfg.metadata.name == "nginx";
|
||||
}];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
kubernetes.resources.pods.nginx = { };
|
||||
kubernetes.resources.pods.nginx = {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +1,68 @@
|
|||
{ name, config, lib, kubenix, images, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
cfg = config.submodules.instances.passthru;
|
||||
in
|
||||
{
|
||||
imports = with kubenix.modules; [ test submodules k8s docker ];
|
||||
name,
|
||||
config,
|
||||
lib,
|
||||
kubenix,
|
||||
images,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.submodules.instances.passthru;
|
||||
in {
|
||||
imports = with kubenix.modules; [test submodules k8s docker];
|
||||
|
||||
test = {
|
||||
name = "k8s-submodule";
|
||||
description = "Simple k8s submodule test";
|
||||
assertions = [{
|
||||
message = "Submodule has correct name set";
|
||||
assertion = (head config.kubernetes.objects).metadata.name == "passthru";
|
||||
}
|
||||
assertions = [
|
||||
{
|
||||
message = "Submodule has correct name set";
|
||||
assertion = (head config.kubernetes.objects).metadata.name == "passthru";
|
||||
}
|
||||
{
|
||||
message = "Should expose docker image";
|
||||
assertion = (head config.docker.export).imageName == "xtruder/nginx";
|
||||
}];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
kubernetes.namespace = "test-namespace";
|
||||
|
||||
submodules.imports = [{
|
||||
module = { name, config, ... }: {
|
||||
imports = with kubenix.modules; [ submodule k8s docker ];
|
||||
submodules.imports = [
|
||||
{
|
||||
module = {
|
||||
name,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
imports = with kubenix.modules; [submodule k8s docker];
|
||||
|
||||
config = {
|
||||
submodule = {
|
||||
name = "test-submodule";
|
||||
passthru = {
|
||||
kubernetes.objects = config.kubernetes.objects;
|
||||
docker.images = config.docker.images;
|
||||
config = {
|
||||
submodule = {
|
||||
name = "test-submodule";
|
||||
passthru = {
|
||||
kubernetes.objects = config.kubernetes.objects;
|
||||
docker.images = config.docker.images;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
kubernetes.resources.pods.nginx = {
|
||||
metadata.name = name;
|
||||
spec.containers.nginx.image = config.docker.images.nginx.path;
|
||||
};
|
||||
kubernetes.resources.pods.nginx = {
|
||||
metadata.name = name;
|
||||
spec.containers.nginx.image = config.docker.images.nginx.path;
|
||||
};
|
||||
|
||||
docker.images.nginx.image = images.nginx;
|
||||
docker.images.nginx.image = images.nginx;
|
||||
};
|
||||
};
|
||||
};
|
||||
}];
|
||||
}
|
||||
];
|
||||
|
||||
kubernetes.api.defaults = [{
|
||||
propagate = true;
|
||||
default.metadata.labels.my-label = "my-value";
|
||||
}];
|
||||
kubernetes.api.defaults = [
|
||||
{
|
||||
propagate = true;
|
||||
default.metadata.labels.my-label = "my-value";
|
||||
}
|
||||
];
|
||||
|
||||
submodules.instances.passthru = {
|
||||
submodule = "test-submodule";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue