mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
switch formatting to nixpkgs-fmt
This commit is contained in:
parent
3598716c73
commit
2712e89716
65 changed files with 4839 additions and 5222 deletions
|
|
@ -1,15 +1,9 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
kubenix,
|
||||
...
|
||||
}:
|
||||
{ config, pkgs, lib, kubenix, ... }:
|
||||
with lib; let
|
||||
cfg = config.testing;
|
||||
|
||||
testModule = {
|
||||
imports = [./evalTest.nix];
|
||||
imports = [ ./evalTest.nix ];
|
||||
|
||||
# passthru testing configuration
|
||||
config._module.args = {
|
||||
|
|
@ -18,9 +12,9 @@ with lib; let
|
|||
};
|
||||
};
|
||||
|
||||
isTestEnabled = test:
|
||||
(cfg.enabledTests == null || elem test.name cfg.enabledTests) && test.enable;
|
||||
in {
|
||||
isTestEnabled = test: (cfg.enabledTests == null || elem test.name cfg.enabledTests) && test.enable;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./docker.nix
|
||||
./driver/kubetest.nix
|
||||
|
|
@ -48,23 +42,23 @@ in {
|
|||
features = mkOption {
|
||||
description = "List of features that test has to have to apply options";
|
||||
type = types.listOf types.str;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
options = mkOption {
|
||||
description = "Options to apply to test";
|
||||
type = types.unspecified;
|
||||
default = {};
|
||||
apply = default: {_file = "testing.common";} // default;
|
||||
default = { };
|
||||
apply = default: { _file = "testing.common"; } // default;
|
||||
};
|
||||
};
|
||||
}));
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
tests = mkOption {
|
||||
description = "List of test cases";
|
||||
default = [];
|
||||
default = [ ];
|
||||
type = types.listOf (types.coercedTo types.path
|
||||
(module: {
|
||||
inherit module;
|
||||
|
|
@ -88,7 +82,7 @@ in {
|
|||
args = mkOption {
|
||||
description = "Attribute set of extra args passed to tests";
|
||||
type = types.attrs;
|
||||
default = {};
|
||||
default = { };
|
||||
};
|
||||
|
||||
success = mkOption {
|
||||
|
|
|
|||
|
|
@ -1,17 +1,13 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{ config, lib, pkgs, ... }:
|
||||
with lib;
|
||||
with import ../../lib/docker {inherit lib pkgs;}; let
|
||||
with import ../../lib/docker { inherit lib pkgs; }; let
|
||||
inherit (config) testing;
|
||||
|
||||
allImages = unique (flatten (map (t: t.evaled.config.docker.export or []) testing.tests));
|
||||
allImages = unique (flatten (map (t: t.evaled.config.docker.export or [ ]) testing.tests));
|
||||
|
||||
cfg = config.testing.docker;
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.docker = {
|
||||
registryUrl = mkOption {
|
||||
description = "Docker registry url";
|
||||
|
|
@ -38,13 +34,11 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
config.testing.common = [
|
||||
{
|
||||
features = ["docker"];
|
||||
options = {
|
||||
_file = "testing.docker.registryUrl";
|
||||
docker.registry.url = cfg.registryUrl;
|
||||
};
|
||||
}
|
||||
];
|
||||
config.testing.common = [{
|
||||
features = [ "docker" ];
|
||||
options = {
|
||||
_file = "testing.docker.registryUrl";
|
||||
docker.registry.url = cfg.registryUrl;
|
||||
};
|
||||
}];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,15 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{ lib, config, pkgs, ... }:
|
||||
with lib; let
|
||||
inherit (config) testing;
|
||||
cfg = testing.driver.kubetest;
|
||||
|
||||
kubetest = import ./kubetestdrv.nix {inherit pkgs;};
|
||||
kubetest = import ./kubetestdrv.nix { inherit pkgs; };
|
||||
|
||||
pythonEnv = pkgs.python38.withPackages (ps:
|
||||
with ps;
|
||||
[
|
||||
pytest
|
||||
kubetest
|
||||
kubernetes
|
||||
]
|
||||
++ cfg.extraPackages);
|
||||
pythonEnv = pkgs.python38.withPackages (ps: with ps; [
|
||||
pytest
|
||||
kubetest
|
||||
kubernetes
|
||||
] ++ cfg.extraPackages);
|
||||
|
||||
toTestScript = t:
|
||||
if isString t.script
|
||||
|
|
@ -28,26 +20,29 @@ with lib; let
|
|||
''
|
||||
else t.script;
|
||||
|
||||
tests = let
|
||||
# make sure tests are prefixed so that alphanumerical
|
||||
# sorting reproduces them in the same order as they
|
||||
# have been declared in the list.
|
||||
seive = t: t.script != null && t.enabled;
|
||||
allEligibleTests = filter seive testing.tests;
|
||||
listLengthPadding = builtins.length (
|
||||
lib.stringToCharacters (
|
||||
builtins.toString (
|
||||
builtins.length allEligibleTests
|
||||
tests =
|
||||
let
|
||||
# make sure tests are prefixed so that alphanumerical
|
||||
# sorting reproduces them in the same order as they
|
||||
# have been declared in the list.
|
||||
seive = t: t.script != null && t.enabled;
|
||||
allEligibleTests = filter seive testing.tests;
|
||||
listLengthPadding = builtins.length (
|
||||
lib.stringToCharacters (
|
||||
builtins.toString (
|
||||
builtins.length allEligibleTests
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
op = i: t: {
|
||||
path = toTestScript t;
|
||||
name = let
|
||||
prefix = lib.fixedWidthNumber listLengthPadding i;
|
||||
in "${prefix}_${t.name}_test.py";
|
||||
};
|
||||
in
|
||||
);
|
||||
op = i: t: {
|
||||
path = toTestScript t;
|
||||
name =
|
||||
let
|
||||
prefix = lib.fixedWidthNumber listLengthPadding i;
|
||||
in
|
||||
"${prefix}_${t.name}_test.py";
|
||||
};
|
||||
in
|
||||
pkgs.linkFarm "${testing.name}-tests" (
|
||||
lib.imap0 op allEligibleTests
|
||||
);
|
||||
|
|
@ -56,7 +51,8 @@ with lib; let
|
|||
#!/usr/bin/env bash
|
||||
${pythonEnv}/bin/pytest -p no:cacheprovider ${tests} $@
|
||||
'';
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.driver.kubetest = {
|
||||
defaultHeader = mkOption {
|
||||
type = types.lines;
|
||||
|
|
@ -69,7 +65,7 @@ in {
|
|||
extraPackages = mkOption {
|
||||
type = types.listOf types.package;
|
||||
description = "Extra packages to pass to tests";
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
{pkgs ? import <nixpkgs> {}}:
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
with pkgs;
|
||||
with pkgs.python38Packages;
|
||||
with pkgs.python38;
|
||||
pkgs.python38Packages.buildPythonPackage rec {
|
||||
pname = "kubetest";
|
||||
version = "0.9.5";
|
||||
src = fetchPypi {
|
||||
inherit pname version;
|
||||
sha256 = "sha256-TqDHMciAEXv4vMWLJY1YdtXsP4ho+INgdFB3xQQNoZU=";
|
||||
};
|
||||
propagatedBuildInputs = [pytest kubernetes];
|
||||
doCheck = false;
|
||||
}
|
||||
pkgs.python38Packages.buildPythonPackage rec {
|
||||
pname = "kubetest";
|
||||
version = "0.9.5";
|
||||
src = fetchPypi {
|
||||
inherit pname version;
|
||||
sha256 = "sha256-TqDHMciAEXv4vMWLJY1YdtXsP4ho+INgdFB3xQQNoZU=";
|
||||
};
|
||||
propagatedBuildInputs = [ pytest kubernetes ];
|
||||
doCheck = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,4 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
testing,
|
||||
kubenix,
|
||||
...
|
||||
}:
|
||||
{ lib, config, testing, kubenix, ... }:
|
||||
with lib; let
|
||||
modules = [
|
||||
# testing module
|
||||
|
|
@ -29,13 +23,9 @@ with lib; let
|
|||
|
||||
# eval without checking
|
||||
evaled' = kubenix.evalModules {
|
||||
modules =
|
||||
modules
|
||||
++ [
|
||||
{
|
||||
_module.args.check = false;
|
||||
}
|
||||
];
|
||||
modules = modules ++ [{
|
||||
_module.args.check = false;
|
||||
}];
|
||||
};
|
||||
|
||||
# test configuration
|
||||
|
|
@ -45,13 +35,11 @@ with lib; let
|
|||
testFeatures = evaled'.config._m.features;
|
||||
|
||||
# common options that can be applied on this test
|
||||
commonOpts =
|
||||
filter
|
||||
(
|
||||
d:
|
||||
(intersectLists d.features testFeatures)
|
||||
== d.features
|
||||
|| (length d.features) == 0
|
||||
commonOpts = filter
|
||||
(d:
|
||||
(intersectLists d.features testFeatures)
|
||||
== d.features
|
||||
|| (length d.features) == 0
|
||||
)
|
||||
testing.common;
|
||||
|
||||
|
|
@ -59,17 +47,19 @@ with lib; let
|
|||
modulesWithCommonOptions = modules ++ (map (d: d.options) commonOpts);
|
||||
|
||||
# evaled test
|
||||
evaled = let
|
||||
evaled' = kubenix.evalModules {
|
||||
modules = modulesWithCommonOptions;
|
||||
};
|
||||
in
|
||||
evaled =
|
||||
let
|
||||
evaled' = kubenix.evalModules {
|
||||
modules = modulesWithCommonOptions;
|
||||
};
|
||||
in
|
||||
if testing.doThrowError
|
||||
then evaled'
|
||||
else if (builtins.tryEval evaled'.config.test.assertions).success
|
||||
then evaled'
|
||||
else null;
|
||||
in {
|
||||
in
|
||||
{
|
||||
options = {
|
||||
module = mkOption {
|
||||
description = "Module defining kubenix test";
|
||||
|
|
@ -112,7 +102,7 @@ in {
|
|||
description = "Test result";
|
||||
type = types.unspecified;
|
||||
internal = true;
|
||||
default = [];
|
||||
default = [ ];
|
||||
};
|
||||
|
||||
script = mkOption {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,4 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{ lib, config, pkgs, ... }:
|
||||
with lib; let
|
||||
inherit (config) testing;
|
||||
|
||||
|
|
@ -34,7 +29,8 @@ with lib; let
|
|||
echo "--> running tests"
|
||||
${testing.testScript} --kube-config=$KUBECONFIG
|
||||
'';
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.runtime.local = {
|
||||
script = mkOption {
|
||||
type = types.package;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,5 @@
|
|||
# nixos-k8s implements nixos kubernetes testing runtime
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}:
|
||||
{ config, pkgs, lib, ... }:
|
||||
with lib; let
|
||||
inherit (config) testing;
|
||||
# kubeconfig = "/etc/${config.services.kubernetes.pki.etcClusterAdminKubeconfig}";
|
||||
|
|
@ -12,15 +7,15 @@ with lib; let
|
|||
kubecerts = "/var/lib/kubernetes/secrets";
|
||||
|
||||
# how we differ from the standard configuration of mkKubernetesBaseTest
|
||||
extraConfiguration = {config, ...}: {
|
||||
extraConfiguration = { config, ... }: {
|
||||
virtualisation = {
|
||||
memorySize = 2048;
|
||||
};
|
||||
|
||||
networking = {
|
||||
nameservers = ["10.0.0.254"];
|
||||
nameservers = [ "10.0.0.254" ];
|
||||
firewall = {
|
||||
trustedInterfaces = ["docker0" "cni0"];
|
||||
trustedInterfaces = [ "docker0" "cni0" ];
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -29,26 +24,22 @@ with lib; let
|
|||
kubelet = {
|
||||
seedDockerImages = testing.docker.images;
|
||||
networkPlugin = "cni";
|
||||
cni.config = [
|
||||
{
|
||||
name = "mynet";
|
||||
type = "bridge";
|
||||
bridge = "cni0";
|
||||
addIf = true;
|
||||
ipMasq = true;
|
||||
isGateway = true;
|
||||
ipam = {
|
||||
type = "host-local";
|
||||
subnet = "10.1.0.0/16";
|
||||
gateway = "10.1.0.1";
|
||||
routes = [
|
||||
{
|
||||
dst = "0.0.0.0/0";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
];
|
||||
cni.config = [{
|
||||
name = "mynet";
|
||||
type = "bridge";
|
||||
bridge = "cni0";
|
||||
addIf = true;
|
||||
ipMasq = true;
|
||||
isGateway = true;
|
||||
ipam = {
|
||||
type = "host-local";
|
||||
subnet = "10.1.0.0/16";
|
||||
gateway = "10.1.0.1";
|
||||
routes = [{
|
||||
dst = "0.0.0.0/0";
|
||||
}];
|
||||
};
|
||||
}];
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -58,8 +49,8 @@ with lib; let
|
|||
services.copy-certs = {
|
||||
description = "Share k8s certificates with host";
|
||||
script = "cp -rf ${kubecerts} /tmp/xchg/; cp -f ${kubeconfig} /tmp/xchg/;";
|
||||
after = ["kubernetes.target"];
|
||||
wantedBy = ["multi-user.target"];
|
||||
after = [ "kubernetes.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
|
|
@ -72,16 +63,18 @@ with lib; let
|
|||
machine1.succeed("${testing.testScript} --kube-config=${kubeconfig}")
|
||||
'';
|
||||
|
||||
test = with import "${pkgs.path}/nixos/tests/kubernetes/base.nix" {
|
||||
inherit pkgs;
|
||||
inherit (pkgs) system;
|
||||
};
|
||||
test = with import "${pkgs.path}/nixos/tests/kubernetes/base.nix"
|
||||
{
|
||||
inherit pkgs;
|
||||
inherit (pkgs) system;
|
||||
};
|
||||
mkKubernetesSingleNodeTest {
|
||||
inherit extraConfiguration;
|
||||
inherit (config.testing) name;
|
||||
test = script;
|
||||
};
|
||||
in {
|
||||
in
|
||||
{
|
||||
options.testing.runtime.nixos-k8s = {
|
||||
driver = mkOption {
|
||||
description = "Test driver";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
{ lib, config, ... }:
|
||||
with lib; {
|
||||
options.test = {
|
||||
name = mkOption {
|
||||
|
|
@ -36,13 +32,11 @@ with lib; {
|
|||
};
|
||||
};
|
||||
});
|
||||
default = [];
|
||||
example = [
|
||||
{
|
||||
assertion = false;
|
||||
message = "you can't enable this for some reason";
|
||||
}
|
||||
];
|
||||
default = [ ];
|
||||
example = [{
|
||||
assertion = false;
|
||||
message = "you can't enable this for some reason";
|
||||
}];
|
||||
description = ''
|
||||
This option allows modules to express conditions that must
|
||||
hold for the evaluation of the system configuration to
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue