mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
feat(k8s): improvements
- format k8s generated files with nixfmt - improve k8s module true and mount resources at `kubernetes.api.resources` - create alias `kubernetes.resources` to `kubernetes.api.resources` - rename from `kubernetes.api.resources` to `kubernetes.api.types` - rename from `kubernetes.customResources` to `kubernetes.customTypes`
This commit is contained in:
parent
42b7d5f551
commit
3d149d6101
11 changed files with 116285 additions and 122144 deletions
|
|
@ -1,4 +1,5 @@
|
|||
{ pkgs ? import <nixpkgs> {}
|
||||
{ name ? "k8s"
|
||||
, pkgs ? import <nixpkgs> {}
|
||||
, lib ? pkgs.lib
|
||||
, spec ? ./specs/1.10/swagger.json
|
||||
, ... }:
|
||||
|
|
@ -198,18 +199,18 @@ let
|
|||
}
|
||||
) swagger.definitions;
|
||||
|
||||
genResources = swagger: mapAttrs' (name: path: let
|
||||
genResourceTypes = swagger: mapAttrs' (name: path: let
|
||||
ref = refType (head path.post.parameters).schema;
|
||||
group' = path.post."x-kubernetes-group-version-kind".group;
|
||||
version' = path.post."x-kubernetes-group-version-kind".version;
|
||||
in nameValuePair ref {
|
||||
inherit ref;
|
||||
|
||||
kind = path.post."x-kubernetes-group-version-kind".kind;
|
||||
version = version';
|
||||
resource = last (splitString "/" name);
|
||||
description = swagger.definitions.${ref}.description;
|
||||
name = last (splitString "/" name);
|
||||
group = if group' == "" then "core" else group';
|
||||
version = version';
|
||||
kind = path.post."x-kubernetes-group-version-kind".kind;
|
||||
description = swagger.definitions.${ref}.description;
|
||||
defintion = refDefinition (head path.post.parameters).schema;
|
||||
})
|
||||
(filterAttrs (name: path:
|
||||
|
|
@ -219,39 +220,40 @@ let
|
|||
|
||||
swagger = fetchSpecs spec;
|
||||
definitions = genDefinitions swagger;
|
||||
resources = genResources swagger;
|
||||
resourceTypes = genResourceTypes swagger;
|
||||
|
||||
resourcesByKind = zipAttrs (mapAttrsToList (name: resource: {
|
||||
${resource.kind} = resource;
|
||||
}) resources);
|
||||
resourceTypesByKind = zipAttrs (mapAttrsToList (name: resourceType: {
|
||||
${resourceType.kind} = resourceType;
|
||||
}) resourceTypes);
|
||||
|
||||
resourcesByKindOrderedByVersion = mapAttrs (kind: resources:
|
||||
resourcesTypesByKindSortByVersion = mapAttrs (kind: resourceTypes:
|
||||
reverseList (sort (r1: r2:
|
||||
compareVersions r1.version r2.version > 0
|
||||
) resources)
|
||||
) resourcesByKind;
|
||||
) resourceTypes)
|
||||
) resourceTypesByKind;
|
||||
|
||||
latestResourcesByKind =
|
||||
mapAttrs (kind: resources: last resources) resourcesByKindOrderedByVersion;
|
||||
latestResourceTypesByKind =
|
||||
mapAttrs (kind: resources: last resources) resourcesTypesByKindSortByVersion;
|
||||
|
||||
genResourceOptions = resource: with gen; let
|
||||
submoduleForDefinition' = definition: let
|
||||
in submoduleForDefinition
|
||||
definition.ref definition.resource definition.kind definition.group definition.version;
|
||||
definition.ref definition.name definition.kind definition.group definition.version;
|
||||
in mkOption {
|
||||
description = resource.description;
|
||||
type = types.attrsOf (submoduleForDefinition' resource);
|
||||
default = {};
|
||||
};
|
||||
in pkgs.writeText "gen.nix"
|
||||
"# This file was generated with kubenix k8s generator, do not edit
|
||||
{lib, config, ... }:
|
||||
|
||||
with lib;
|
||||
generated = ''
|
||||
# This file was generated with kubenix k8s generator, do not edit
|
||||
{ lib, options, config, ... }:
|
||||
|
||||
let
|
||||
with lib;
|
||||
|
||||
let
|
||||
getDefaults = resource: group: version: kind:
|
||||
catAttrs \"default\" (filter (default:
|
||||
catAttrs "default" (filter (default:
|
||||
(default.resource == null || default.resource == resource) &&
|
||||
(default.group == null || default.group == group) &&
|
||||
(default.version == null || default.version == version) &&
|
||||
|
|
@ -260,8 +262,8 @@ let
|
|||
|
||||
types = lib.types // rec {
|
||||
str = mkOptionType {
|
||||
name = \"str\";
|
||||
description = \"string\";
|
||||
name = "str";
|
||||
description = "string";
|
||||
check = isString;
|
||||
merge = mergeEqualOption;
|
||||
};
|
||||
|
|
@ -270,8 +272,8 @@ let
|
|||
# converted to `finalType` using `coerceFunc`.
|
||||
coercedTo = coercedType: coerceFunc: finalType:
|
||||
mkOptionType rec {
|
||||
name = \"coercedTo\";
|
||||
description = \"\${finalType.description} or \${coercedType.description}\";
|
||||
name = "coercedTo";
|
||||
description = "''${finalType.description} or ''${coercedType.description}";
|
||||
check = x: finalType.check x || coercedType.check x;
|
||||
merge = loc: defs:
|
||||
let
|
||||
|
|
@ -295,36 +297,36 @@ let
|
|||
mergeValuesByKey = mergeKey: values:
|
||||
listToAttrs (map
|
||||
(value: nameValuePair (
|
||||
if isAttrs value.\${mergeKey}
|
||||
then toString value.\${mergeKey}.content
|
||||
else (toString value.\${mergeKey})
|
||||
if isAttrs value.''${mergeKey}
|
||||
then toString value.''${mergeKey}.content
|
||||
else (toString value.''${mergeKey})
|
||||
) value)
|
||||
values);
|
||||
|
||||
submoduleOf = ref: types.submodule ({name, ...}: {
|
||||
options = definitions.\"\${ref}\".options or {};
|
||||
config = definitions.\"\${ref}\".config or {};
|
||||
options = definitions."''${ref}".options or {};
|
||||
config = definitions."''${ref}".config or {};
|
||||
});
|
||||
|
||||
submoduleWithMergeOf = ref: mergeKey: types.submodule ({name, ...}: let
|
||||
convertName = name:
|
||||
if definitions.\"\${ref}\".options.\${mergeKey}.type == types.int
|
||||
if definitions."''${ref}".options.''${mergeKey}.type == types.int
|
||||
then toInt name
|
||||
else name;
|
||||
in {
|
||||
options = definitions.\"\${ref}\".options;
|
||||
config = definitions.\"\${ref}\".config // {
|
||||
\${mergeKey} = mkOverride 1002 (convertName name);
|
||||
options = definitions."''${ref}".options;
|
||||
config = definitions."''${ref}".config // {
|
||||
''${mergeKey} = mkOverride 1002 (convertName name);
|
||||
};
|
||||
});
|
||||
|
||||
submoduleForDefinition = ref: resource: kind: group: version: let
|
||||
apiVersion = if group == \"core\" then version else \"\${group}/\${version}\";
|
||||
apiVersion = if group == "core" then version else "''${group}/''${version}";
|
||||
in types.submodule ({name, ...}: {
|
||||
imports = getDefaults resource group version kind;
|
||||
options = definitions.\"\${ref}\".options;
|
||||
options = definitions."''${ref}".options;
|
||||
config = mkMerge [
|
||||
definitions.\"\${ref}\".config
|
||||
definitions."''${ref}".config
|
||||
{
|
||||
kind = mkOptionDefault kind;
|
||||
apiVersion = mkOptionDefault apiVersion;
|
||||
|
|
@ -342,34 +344,60 @@ let
|
|||
);
|
||||
|
||||
definitions = {
|
||||
${concatStrings (mapAttrsToList (name: value: "
|
||||
\"${name}\" = {${optionalString (hasAttr "options" value) "
|
||||
options = {${concatStrings (mapAttrsToList (name: value: "
|
||||
\"${name}\" = ${value};
|
||||
") value.options)}};
|
||||
"}${optionalString (hasAttr "config" value) "
|
||||
config = {${concatStrings (mapAttrsToList (name: value: "
|
||||
\"${name}\" = ${value};
|
||||
") value.config)}};
|
||||
"}};
|
||||
") definitions)}
|
||||
${concatStrings (mapAttrsToList (name: value: ''
|
||||
"${name}" = {
|
||||
${optionalString (hasAttr "options" value) "
|
||||
options = {${concatStrings (mapAttrsToList (name: value: ''
|
||||
"${name}" = ${value};
|
||||
'') value.options)}};
|
||||
"}
|
||||
|
||||
${optionalString (hasAttr "config" value) ''
|
||||
config = {${concatStrings (mapAttrsToList (name: value: ''
|
||||
"${name}" = ${value};
|
||||
'') value.config)}};
|
||||
''}
|
||||
};
|
||||
'') definitions)}
|
||||
};
|
||||
in {
|
||||
# all resource versions
|
||||
options = {
|
||||
resources = {
|
||||
${concatStrings (mapAttrsToList (_: rt: ''
|
||||
"${rt.group}"."${rt.version}"."${rt.kind}" = ${genResourceOptions rt};
|
||||
'') resourceTypes)}
|
||||
} // {
|
||||
${concatStrings (mapAttrsToList (_: rt: ''
|
||||
"${rt.name}" = ${genResourceOptions rt};
|
||||
'') latestResourceTypesByKind)}
|
||||
};
|
||||
};
|
||||
in {
|
||||
options = {${concatStrings (mapAttrsToList (name: resource: "
|
||||
\"${resource.group}\".\"${resource.version}\".\"${resource.kind}\" = ${genResourceOptions resource};
|
||||
") resources)}} // {${concatStrings (mapAttrsToList (name: resource: "
|
||||
\"${resource.resource}\" = ${genResourceOptions resource};
|
||||
") latestResourcesByKind)}};
|
||||
|
||||
config = {
|
||||
# expose resource definitions
|
||||
inherit definitions;
|
||||
|
||||
resources = [${concatStrings (mapAttrsToList (name: resource: "{
|
||||
group = \"${resource.group}\";
|
||||
version = \"${resource.version}\";
|
||||
kind = \"${resource.kind}\";
|
||||
resource = \"${resource.resource}\";
|
||||
}") resources)}];
|
||||
# register resource types
|
||||
types = [${concatStrings (mapAttrsToList (_: rt: ''{
|
||||
name = "${rt.name}";
|
||||
group = "${rt.group}";
|
||||
version = "${rt.version}";
|
||||
kind = "${rt.kind}";
|
||||
}'') resourceTypes)}];
|
||||
|
||||
resources = {
|
||||
${concatStrings (mapAttrsToList (_: rt: ''
|
||||
"${rt.name}" =
|
||||
mkAliasDefinitions options.resources."${rt.group}"."${rt.version}"."${rt.kind}";
|
||||
'') latestResourceTypesByKind)}
|
||||
};
|
||||
}
|
||||
"
|
||||
};
|
||||
}
|
||||
'';
|
||||
in pkgs.runCommand "k8s-${name}-gen.nix" {
|
||||
buildInputs = [ pkgs.haskellPackages.nixfmt ];
|
||||
} ''
|
||||
cp ${builtins.toFile "k8s-${name}-gen-raw.nix" generated} $out
|
||||
nixfmt -w 100 $out
|
||||
''
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
147
modules/k8s.nix
147
modules/k8s.nix
|
|
@ -1,6 +1,6 @@
|
|||
# K8S module defines kubernetes definitions for kubenix
|
||||
|
||||
{ config, lib, pkgs, k8s, ... }:
|
||||
{ options, config, lib, pkgs, k8s, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
|
|
@ -24,14 +24,6 @@ let
|
|||
|
||||
else value;
|
||||
|
||||
flattenResources = resources: flatten (
|
||||
mapAttrsToList (groupName: versions:
|
||||
mapAttrsToList (versionName: kinds:
|
||||
builtins.trace versionName kinds
|
||||
) versions
|
||||
) resources
|
||||
);
|
||||
|
||||
apiOptions = { config, ... }: {
|
||||
options = {
|
||||
definitions = mkOption {
|
||||
|
|
@ -82,41 +74,68 @@ let
|
|||
default = [];
|
||||
};
|
||||
|
||||
resources = mkOption {
|
||||
types = mkOption {
|
||||
description = "List of registered kubernetes types";
|
||||
type = types.listOf (types.submodule {
|
||||
options = {
|
||||
name = mkOption {
|
||||
description = "Resource type name";
|
||||
type = types.nullOr types.str;
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
description = "Resoruce group";
|
||||
description = "Resource type group";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
version = mkOption {
|
||||
description = "Resoruce version";
|
||||
description = "Resoruce type version";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
kind = mkOption {
|
||||
description = "Resource kind";
|
||||
description = "Resource type kind";
|
||||
type = types.str;
|
||||
};
|
||||
|
||||
resource = mkOption {
|
||||
description = "Resource name";
|
||||
type = types.nullOr types.str;
|
||||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
# apply aliased option
|
||||
resources = mkAliasDefinitions options.kubernetes.resources;
|
||||
};
|
||||
};
|
||||
|
||||
indexOf = lst: value:
|
||||
head (filter (v: v != -1) (imap0 (i: v: if v == value then i else -1) lst));
|
||||
|
||||
customResourceOptions = map (cr: {config, ...}: let
|
||||
module = { name, ... }: {
|
||||
imports = getDefaults cr.resource cr.group cr.version cr.kind;
|
||||
compareVersions = ver1: ver2: let
|
||||
getVersion = v: substring 1 10 v;
|
||||
splittedVer1 = builtins.splitVersion (getVersion ver1);
|
||||
splittedVer2 = builtins.splitVersion (getVersion ver2);
|
||||
|
||||
v1 = if length splittedVer1 == 1 then "${getVersion ver1}prod" else getVersion ver1;
|
||||
v2 = if length splittedVer2 == 1 then "${getVersion ver2}prod" else getVersion ver2;
|
||||
in builtins.compareVersions v1 v2;
|
||||
|
||||
customResourceTypesByKind = zipAttrs (map (resourceType: {
|
||||
${resourceType.kind} = resourceType;
|
||||
}) cfg.customTypes);
|
||||
|
||||
customResourceTypesByKindSortByVersion = mapAttrs (_: resourceTypes:
|
||||
reverseList (sort (r1: r2:
|
||||
compareVersions r1.version r2.version > 0
|
||||
) resourceTypes)
|
||||
) customResourceTypesByKind;
|
||||
|
||||
latestCustomResourceTypes =
|
||||
mapAttrsToList (_: resources: last resources) customResourceTypesByKindSortByVersion;
|
||||
|
||||
customResourceModuleForType = config: ct: { name, ... }: {
|
||||
imports = getDefaults ct.name ct.group ct.version ct.kind;
|
||||
options = {
|
||||
apiVersion = mkOption {
|
||||
description = "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources";
|
||||
|
|
@ -135,38 +154,39 @@ let
|
|||
|
||||
spec = mkOption {
|
||||
description = "Module spec";
|
||||
type = types.either types.attrs (types.submodule cr.module);
|
||||
type = types.either types.attrs (types.submodule ct.module);
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
apiVersion = mkOptionDefault "${cr.group}/${cr.version}";
|
||||
kind = mkOptionDefault cr.kind;
|
||||
apiVersion = mkOptionDefault "${ct.group}/${ct.version}";
|
||||
kind = mkOptionDefault ct.kind;
|
||||
metadata.name = mkOptionDefault name;
|
||||
};
|
||||
};
|
||||
in if cr.resource != null then {
|
||||
options.${cr.group}.${cr.version}.${cr.kind} = mkOption {
|
||||
description = cr.description;
|
||||
|
||||
customResourceOptions = (map (ct: {config, ...}: let
|
||||
module = customResourceModuleForType config ct;
|
||||
in {
|
||||
options.resources.${ct.group}.${ct.version}.${ct.kind} = mkOption {
|
||||
description = ct.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = {};
|
||||
};
|
||||
}) cfg.customTypes) ++ (map (ct: { options, config, ... }: let
|
||||
module = customResourceModuleForType config ct;
|
||||
in {
|
||||
options.resources.${ct.name} = mkOption {
|
||||
description = ct.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = {};
|
||||
};
|
||||
|
||||
options.${cr.resource} = mkOption {
|
||||
description = cr.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = {};
|
||||
};
|
||||
config.resources.${ct.group}.${ct.version}.${ct.kind} =
|
||||
mkAliasDefinitions options.resources.${ct.name};
|
||||
}) latestCustomResourceTypes);
|
||||
|
||||
config.${cr.group}.${cr.version}.${cr.kind} = config.${cr.resource};
|
||||
} else {
|
||||
options.${cr.group}.${cr.version}.${cr.kind} = mkOption {
|
||||
description = cr.description;
|
||||
type = types.attrsOf (types.submodule module);
|
||||
default = {};
|
||||
};
|
||||
}) cfg.customResources;
|
||||
in {
|
||||
imports = [ ./base.nix ./submodules.nix ];
|
||||
|
||||
|
|
@ -208,9 +228,13 @@ in {
|
|||
default = [];
|
||||
};
|
||||
|
||||
customResources = mkOption {
|
||||
resources = mkOption {
|
||||
description = "Alias for `config.kubernetes.api.resources` options";
|
||||
};
|
||||
|
||||
customTypes = mkOption {
|
||||
default = [];
|
||||
description = "List of custom resource definitions to make API for";
|
||||
description = "List of custom resource types to make API for";
|
||||
type = types.listOf (types.submodule ({config, ...}: {
|
||||
options = {
|
||||
group = mkOption {
|
||||
|
|
@ -228,7 +252,7 @@ in {
|
|||
type = types.str;
|
||||
};
|
||||
|
||||
resource = mkOption {
|
||||
name = mkOption {
|
||||
description = "Custom resource definition resource name";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
|
|
@ -245,12 +269,6 @@ in {
|
|||
type = types.unspecified;
|
||||
default = {};
|
||||
};
|
||||
|
||||
alias = mkOption {
|
||||
description = "Alias to create for API";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
|
@ -279,9 +297,10 @@ in {
|
|||
_module.features = [ "k8s" ];
|
||||
|
||||
kubernetes.api = mkMerge ([{
|
||||
resources = map (cr: {
|
||||
inherit (cr) group version kind resource;
|
||||
}) cfg.customResources;
|
||||
# register custom types
|
||||
types = map (cr: {
|
||||
inherit (cr) name group version kind;
|
||||
}) cfg.customTypes;
|
||||
|
||||
defaults = [{
|
||||
default = {
|
||||
|
|
@ -316,20 +335,18 @@ in {
|
|||
}) cfg.imports));
|
||||
|
||||
kubernetes.objects = mkMerge [
|
||||
# gvk resources
|
||||
(flatten (map (gvk:
|
||||
mapAttrsToList (name: resource:
|
||||
moduleToAttrs resource
|
||||
) cfg.api.${gvk.group}.${gvk.version}.${gvk.kind}
|
||||
) cfg.api.resources))
|
||||
# versioned resources
|
||||
(flatten (map (type:
|
||||
mapAttrsToList (name: resource: moduleToAttrs resource)
|
||||
cfg.api.resources.${type.group}.${type.version}.${type.kind}
|
||||
) cfg.api.types))
|
||||
|
||||
# aliased gvk resources
|
||||
(flatten (map (gvk:
|
||||
if gvk.resource == null then []
|
||||
else mapAttrsToList (name: resource:
|
||||
moduleToAttrs resource
|
||||
) cfg.api.${gvk.resource}
|
||||
) cfg.api.resources))
|
||||
# latest resources
|
||||
(flatten (map (type:
|
||||
if type.name == null then []
|
||||
else mapAttrsToList (name: resource: moduleToAttrs resource)
|
||||
cfg.api.resources.${type.name}
|
||||
) cfg.api.types))
|
||||
|
||||
# passthru of child kubernetes objects if passthru is enabled on submodule
|
||||
# and submodule has k8s module loaded
|
||||
|
|
|
|||
47
release.nix
47
release.nix
|
|
@ -8,7 +8,8 @@ let
|
|||
|
||||
lib = kubenix.lib;
|
||||
|
||||
generateK8S = spec: import ./generators/k8s {
|
||||
generateK8S = name: spec: import ./generators/k8s {
|
||||
inherit name;
|
||||
inherit pkgs;
|
||||
inherit (pkgs) lib;
|
||||
inherit spec;
|
||||
|
|
@ -23,63 +24,77 @@ let
|
|||
inherit pkgs lib kubenix k8sVersion e2e throwError nixosPath;
|
||||
};
|
||||
in rec {
|
||||
generate.k8s = pkgs.linkFarm "k8s-generated.nix" [{
|
||||
generate.k8s = pkgs.linkFarm "k8s-generated.nix" [
|
||||
{
|
||||
name = "v1.7.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.7" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.7.16";
|
||||
sha256 = "1ksalw3hzbcca89n9h3pas9nqj2n5gq3rbpdx633ycqb8g46h1iw";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
} {
|
||||
}
|
||||
|
||||
{
|
||||
name = "v1.8.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.8" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.8.15";
|
||||
sha256 = "1mwaafnkimr4kwqws4qli11wbavpmf27i6pjq77sfsapw9sz54j4";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
} {
|
||||
}
|
||||
|
||||
{
|
||||
name = "v1.9.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.9" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.9.11";
|
||||
sha256 = "1wl944ci7k8knrkdrc328agyq4c953j9dm0sn314s42j18lfd7rv";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
} {
|
||||
}
|
||||
|
||||
{
|
||||
name = "v1.10.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.10" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.10.13";
|
||||
sha256 = "07hwcamlc1kh5flwv4ahfkcg2lyhnbs8q2xczaws6v3sjxaycrrn";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
} {
|
||||
}
|
||||
|
||||
{
|
||||
name = "v1.11.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.11" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.11.8";
|
||||
sha256 = "1q6x38zdycd4ai31gn666hg41bs4q32dyz2d07x76hj33fkzqs1f";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
} {
|
||||
}
|
||||
|
||||
{
|
||||
name = "v1.12.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.12" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.12.6";
|
||||
sha256 = "0p9wh264xfm4c0inz99jclf603c414807vn19gfn62bfls3jcmgf";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
} {
|
||||
}
|
||||
|
||||
{
|
||||
name = "v1.13.nix";
|
||||
path = generateK8S "${pkgs.fetchFromGitHub {
|
||||
path = generateK8S "v1.13" "${pkgs.fetchFromGitHub {
|
||||
owner = "kubernetes";
|
||||
repo = "kubernetes";
|
||||
rev = "v1.13.4";
|
||||
sha256 = "1q3dc416fr9nzy64pl7rydahygnird0vpk9yflssw7v9gx84m6x9";
|
||||
}}/api/openapi-spec/swagger.json";
|
||||
}];
|
||||
}
|
||||
];
|
||||
|
||||
generate.istio = pkgs.linkFarm "istio-generated.nix" [{
|
||||
name = "latest.nix";
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@
|
|||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.kubernetes.api.customresourcedefinitions.crontabs;
|
||||
crd = config.kubernetes.api.resources.customresourcedefinitions.crontabs;
|
||||
latestCrontab = config.kubernetes.api.resources.crontabs.latest;
|
||||
in {
|
||||
imports = with kubenix.modules; [ test k8s ];
|
||||
|
||||
|
|
@ -12,19 +13,25 @@ in {
|
|||
description = "Simple test tesing CRD";
|
||||
enable = builtins.compareVersions config.kubernetes.version "1.8" >= 0;
|
||||
assertions = [{
|
||||
message = "should have group set";
|
||||
assertion = cfg.spec.group == "stable.example.com";
|
||||
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";
|
||||
}];
|
||||
testScript = ''
|
||||
$kube->waitUntilSucceeds("kubectl apply -f ${toYAML config.kubernetes.generated}");
|
||||
$kube->succeed("kubectl get crds | grep -i crontabs");
|
||||
$kube->succeed("kubectl get crontabs | grep -i crontab");
|
||||
$kube->succeed("kubectl get crontabs | grep -i versioned");
|
||||
$kube->succeed("kubectl get crontabs | grep -i latest");
|
||||
'';
|
||||
};
|
||||
|
||||
kubernetes.version = k8sVersion;
|
||||
|
||||
kubernetes.api.customresourcedefinitions.crontabs = {
|
||||
kubernetes.resources.customresourcedefinitions.crontabs = {
|
||||
metadata.name = "crontabs.stable.example.com";
|
||||
spec = {
|
||||
group = "stable.example.com";
|
||||
|
|
@ -39,11 +46,26 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
kubernetes.customResources = [{
|
||||
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";
|
||||
group = "stable.example.com";
|
||||
version = "v1";
|
||||
kind = "CronTab";
|
||||
resource = "crontabs";
|
||||
description = "CronTabs resources";
|
||||
module = {
|
||||
options.schedule = mkOption {
|
||||
|
|
@ -51,7 +73,27 @@ in {
|
|||
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;
|
||||
};
|
||||
};
|
||||
};
|
||||
}];
|
||||
|
||||
kubernetes.api."stable.example.com"."v1".CronTab.crontab.spec.schedule = "* * * * *";
|
||||
kubernetes.resources."stable.example.com"."v1".CronTab.versioned.spec.schedule = "* * * * *";
|
||||
kubernetes.resources.crontabs.latest.spec.schedule = "* * * * *";
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue