kubenix/tests/k8s/crd.nix

100 lines
2.7 KiB
Nix
Raw Normal View History

{ config, lib, kubenix, pkgs, k8sVersion, ... }:
2019-02-13 17:05:18 +01:00
with lib;
let
2019-09-27 18:29:00 +02:00
crd = config.kubernetes.api.resources.customResourceDefinitions.crontabs;
latestCrontab = config.kubernetes.api.resources.crontabs.latest;
2019-02-13 17:05:18 +01:00
in {
imports = with kubenix.modules; [ test k8s ];
2019-02-13 17:05:18 +01:00
test = {
name = "k8s-crd";
2019-02-13 17:05:18 +01:00
description = "Simple test tesing CRD";
2019-02-16 14:02:13 +01:00
enable = builtins.compareVersions config.kubernetes.version "1.8" >= 0;
2019-02-13 17:05:18 +01:00
assertions = [{
message = "CRD should have group and version set";
assertion =
crd.spec.group == "stable.example.com" &&
crd.spec.version == "v1";
} {
message = "Custom resource should have correct version set";
assertion = latestCrontab.apiVersion == "stable.example.com/v2";
2019-02-13 17:05:18 +01:00
}];
2019-02-25 17:16:24 +01:00
testScript = ''
2019-02-20 09:34:15 +01:00
$kube->waitUntilSucceeds("kubectl apply -f ${toYAML config.kubernetes.generated}");
$kube->succeed("kubectl get crds | grep -i crontabs");
$kube->succeed("kubectl get crontabs | grep -i versioned");
$kube->succeed("kubectl get crontabs | grep -i latest");
2019-02-20 09:34:15 +01:00
'';
2019-02-13 17:05:18 +01:00
};
kubernetes.version = k8sVersion;
2019-09-27 18:29:00 +02:00
kubernetes.resources.customResourceDefinitions.crontabs = {
2019-02-13 17:05:18 +01:00
metadata.name = "crontabs.stable.example.com";
spec = {
group = "stable.example.com";
version = "v1";
scope = "Namespaced";
names = {
plural = "crontabs";
singular = "crontab";
kind = "CronTab";
shortNames = ["ct"];
};
};
};
2019-02-20 09:34:15 +01:00
2019-09-27 18:29:00 +02:00
kubernetes.resources.customResourceDefinitions.crontabsv2 = {
metadata.name = "crontabs.stable.example.com";
spec = {
group = "stable.example.com";
version = "v2";
scope = "Namespaced";
names = {
plural = "crontabs";
singular = "crontab";
kind = "CronTab";
shortNames = ["ct"];
};
};
};
kubernetes.customTypes = [{
name = "crontabs";
2019-02-20 09:34:15 +01:00
group = "stable.example.com";
version = "v1";
kind = "CronTab";
description = "CronTabs resources";
module = {
options.schedule = mkOption {
description = "Crontab schedule script";
type = types.str;
};
};
} {
name = "crontabs";
group = "stable.example.com";
version = "v2";
kind = "CronTab";
description = "CronTabs resources";
module = {
options = {
schedule = mkOption {
description = "Crontab schedule script";
type = types.str;
};
command = mkOption {
description = "Command to run";
type = types.str;
};
};
};
2019-02-20 09:34:15 +01:00
}];
kubernetes.resources."stable.example.com"."v1".CronTab.versioned.spec.schedule = "* * * * *";
kubernetes.resources.crontabs.latest.spec.schedule = "* * * * *";
2019-02-13 17:05:18 +01:00
}