2019-03-12 20:33:56 +01:00
|
|
|
{ config, lib, kubenix, pkgs, k8sVersion, ... }:
|
2019-02-13 17:05:18 +01:00
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
2019-09-25 00:58:39 +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 {
|
2019-03-07 23:23:07 +01:00
|
|
|
imports = with kubenix.modules; [ test k8s ];
|
2019-02-13 17:05:18 +01:00
|
|
|
|
|
|
|
|
test = {
|
2019-02-20 23:09:08 +01:00
|
|
|
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 = [{
|
2019-09-25 00:58:39 +02:00
|
|
|
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");
|
2019-09-25 00:58:39 +02:00
|
|
|
$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
|
|
|
};
|
|
|
|
|
|
2019-03-12 20:33:56 +01:00
|
|
|
kubernetes.version = k8sVersion;
|
|
|
|
|
|
2019-09-25 00:58:39 +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-25 00:58:39 +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;
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-09-25 00:58:39 +02:00
|
|
|
} {
|
|
|
|
|
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
|
|
|
}];
|
|
|
|
|
|
2019-09-25 00:58:39 +02: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
|
|
|
}
|