From fde2d5557c227152d96acbe32f75da7b7a34e309 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Wed, 13 Feb 2019 17:05:18 +0100 Subject: [PATCH] feat(test,k8s): add crd tests --- k8s/default.nix | 3 ++- test/default.nix | 2 ++ test/k8s/1.13/crd.nix | 40 ++++++++++++++++++++++++++++++++++++++++ test/k8s/crd.nix | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 test/k8s/1.13/crd.nix create mode 100644 test/k8s/crd.nix diff --git a/k8s/default.nix b/k8s/default.nix index 86277d4..70950ea 100644 --- a/k8s/default.nix +++ b/k8s/default.nix @@ -152,11 +152,12 @@ in { description = mkOption { description = "CRD description"; type = types.str; + default = ""; }; module = mkOption { description = "CRD module"; - default = {}; + default = types.unspecified; }; }; })); diff --git a/test/default.nix b/test/default.nix index 82eb935..b755c79 100644 --- a/test/default.nix +++ b/test/default.nix @@ -16,6 +16,8 @@ with lib; testing.tests = [ ./k8s/simple.nix ./k8s/deployment.nix + ./k8s/crd.nix + ./k8s/1.13/crd.nix ./submodules/simple.nix ]; } diff --git a/test/k8s/1.13/crd.nix b/test/k8s/1.13/crd.nix new file mode 100644 index 0000000..4fb519e --- /dev/null +++ b/test/k8s/1.13/crd.nix @@ -0,0 +1,40 @@ +{ config, lib, kubenix, ... }: + +with lib; + +let + cfg = config.kubernetes.api.customresourcedefinitions.crontabs; +in { + imports = [ + kubenix.k8s + ]; + + test = { + name = "k8s/1.13/crd"; + description = "Simple test tesing CRD for k8s 1.13"; + enable = builtins.compareVersions config.kubernetes.version "1.13" >= 0; + assertions = [{ + message = "should have versions set"; + assertion = (head cfg.spec.versions).name == "v1"; + }]; + }; + + kubernetes.api.customresourcedefinitions.crontabs = { + metadata.name = "crontabs.stable.example.com"; + spec = { + group = "stable.example.com"; + versions = [{ + name = "v1"; + served = true; + storage = true; + }]; + scope = "Namespaced"; + names = { + plural = "crontabs"; + singular = "crontab"; + kind = "CronTab"; + shortNames = ["ct"]; + }; + }; + }; +} diff --git a/test/k8s/crd.nix b/test/k8s/crd.nix new file mode 100644 index 0000000..98d257d --- /dev/null +++ b/test/k8s/crd.nix @@ -0,0 +1,35 @@ +{ config, lib, kubenix, ... }: + +with lib; + +let + cfg = config.kubernetes.api.customresourcedefinitions.crontabs; +in { + imports = [ + kubenix.k8s + ]; + + test = { + name = "k8s/crd"; + description = "Simple test tesing CRD"; + assertions = [{ + message = "should have group set"; + assertion = cfg.spec.group == "stable.example.com"; + }]; + }; + + kubernetes.api.customresourcedefinitions.crontabs = { + metadata.name = "crontabs.stable.example.com"; + spec = { + group = "stable.example.com"; + version = "v1"; + scope = "Namespaced"; + names = { + plural = "crontabs"; + singular = "crontab"; + kind = "CronTab"; + shortNames = ["ct"]; + }; + }; + }; +}