mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 08:00:06 +01:00
feat(k8s): explicit resource ordering
This commit is contained in:
parent
ade94ccefa
commit
e00079fb97
3 changed files with 74 additions and 2 deletions
|
|
@ -110,6 +110,9 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
indexOf = lst: value:
|
||||||
|
head (filter (v: v != -1) (imap0 (i: v: if v == value then i else -1) lst));
|
||||||
in {
|
in {
|
||||||
imports = [./lib.nix];
|
imports = [./lib.nix];
|
||||||
|
|
||||||
|
|
@ -119,6 +122,15 @@ in {
|
||||||
default = "1.13";
|
default = "1.13";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
options.kubernetes.resourceOrder = mkOption {
|
||||||
|
description = "Preffered resource order";
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [
|
||||||
|
"CustomResourceDefinition"
|
||||||
|
"Namespace"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
options.kubernetes.api = mkOption {
|
options.kubernetes.api = mkOption {
|
||||||
type = types.submodule {
|
type = types.submodule {
|
||||||
imports = [
|
imports = [
|
||||||
|
|
@ -207,13 +219,15 @@ in {
|
||||||
|
|
||||||
config.kubernetes.api.resources = map (cr: {
|
config.kubernetes.api.resources = map (cr: {
|
||||||
inherit (cr) group version kind resource;
|
inherit (cr) group version kind resource;
|
||||||
}) config.kubernetes.customResources;
|
}) cfg.customResources;
|
||||||
|
|
||||||
options.kubernetes.objects = mkOption {
|
options.kubernetes.objects = mkOption {
|
||||||
description = "Attribute set of kubernetes objects";
|
description = "Attribute set of kubernetes objects";
|
||||||
type = types.listOf types.attrs;
|
type = types.listOf types.attrs;
|
||||||
apply = items: sort (r1: r2:
|
apply = items: sort (r1: r2:
|
||||||
if r1.kind == "CustomResourceDefinition" || r2.kind == "CustomResourceDefinition" then true else false
|
if elem r1.kind cfg.resourceOrder && elem r2.kind cfg.resourceOrder
|
||||||
|
then indexOf cfg.resourceOrder r1.kind < indexOf cfg.resourceOrder r2.kind
|
||||||
|
else if elem r1.kind cfg.resourceOrder then true else false
|
||||||
) (moduleToAttrs (unique items));
|
) (moduleToAttrs (unique items));
|
||||||
default = [];
|
default = [];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ let
|
||||||
./k8s/1.13/crd.nix
|
./k8s/1.13/crd.nix
|
||||||
./k8s/submodule.nix
|
./k8s/submodule.nix
|
||||||
./k8s/defaults.nix
|
./k8s/defaults.nix
|
||||||
|
./k8s/order.nix
|
||||||
./helm/simple.nix
|
./helm/simple.nix
|
||||||
./istio/bookinfo.nix
|
./istio/bookinfo.nix
|
||||||
./submodules/simple.nix
|
./submodules/simple.nix
|
||||||
|
|
|
||||||
57
tests/k8s/order.nix
Normal file
57
tests/k8s/order.nix
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
{ config, lib, kubenix, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.kubernetes.api.customresourcedefinitions.crontabs;
|
||||||
|
in {
|
||||||
|
imports = [
|
||||||
|
kubenix.k8s
|
||||||
|
];
|
||||||
|
|
||||||
|
test = {
|
||||||
|
name = "k8s-order";
|
||||||
|
description = "test tesing k8s resource order";
|
||||||
|
enable = builtins.compareVersions config.kubernetes.version "1.8" >= 0;
|
||||||
|
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.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"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
kubernetes.customResources = [{
|
||||||
|
group = "stable.example.com";
|
||||||
|
version = "v1";
|
||||||
|
kind = "CronTab";
|
||||||
|
resource = "crontabs";
|
||||||
|
description = "CronTabs resources";
|
||||||
|
module = {
|
||||||
|
options.schedule = mkOption {
|
||||||
|
description = "Crontab schedule script";
|
||||||
|
type = types.str;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}];
|
||||||
|
|
||||||
|
kubernetes.api.namespaces.test = {};
|
||||||
|
|
||||||
|
kubernetes.api."stable.example.com"."v1".CronTab.crontab.spec.schedule = "* * * * *";
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue