This commit is contained in:
GTrunSec 2022-04-02 14:42:22 -07:00
parent 836fe9abd0
commit bc5c70db39
No known key found for this signature in database
GPG key ID: 2368FAFA4ABDD2A0
13 changed files with 68 additions and 57 deletions

View file

@ -1,7 +1,8 @@
{system ? builtins.currentSystem}: ( {system ? builtins.currentSystem}:
(import ./compat.nix).flake-compat { (
src = ./.; (import ./compat.nix).flake-compat {
inherit system; src = ./.;
} inherit system;
) }
.defaultNix )
.defaultNix

View file

@ -3,7 +3,8 @@
registry, registry,
}: let }: let
# evaluated configuration # evaluated configuration
inherit ((evalModules { inherit
((evalModules {
module = {kubenix, ...}: { module = {kubenix, ...}: {
imports = [ imports = [
kubenix.modules.testing kubenix.modules.testing
@ -29,7 +30,9 @@
]; ];
}; };
}; };
})) config; }))
config
;
in { in {
inherit config; inherit config;

View file

@ -12,7 +12,7 @@
nixpkgs, nixpkgs,
... ...
} @ inputs: } @ inputs:
(inputs.flake-utils.lib.eachSystem ["x86_64-linux"]( (inputs.flake-utils.lib.eachSystem ["x86_64-linux"] (
#inputs.flake-utils.lib.eachDefaultSystem ( #inputs.flake-utils.lib.eachDefaultSystem (
system: let system: let
pkgs = import inputs.nixpkgs { pkgs = import inputs.nixpkgs {
@ -77,10 +77,10 @@
else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" {} "exit 1"; else pkgs.runCommandNoCC "testing-suite-config-assertions-for-${suite.name}-failed" {} "exit 1";
mkExamples = attrs: mkExamples = attrs:
(import ./examples {inherit evalModules;}) (import ./examples {inherit evalModules;})
({registry = "docker.io/gatehub";} // attrs); ({registry = "docker.io/gatehub";} // attrs);
mkK8STests = attrs: mkK8STests = attrs:
(import ./tests {inherit evalModules;}) (import ./tests {inherit evalModules;})
({registry = "docker.io/gatehub";} // attrs); ({registry = "docker.io/gatehub";} // attrs);
in { in {
# TODO: access "success" derivation with nice testing utils for nice output # TODO: access "success" derivation with nice testing utils for nice output
nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing; nginx-example = wasSuccess (mkExamples {}).nginx-deployment.config.testing;

View file

@ -305,7 +305,8 @@ with lib; let
genResourceOptions = resource: genResourceOptions = resource:
with gen; let with gen; let
submoduleForDefinition' = definition: submoduleForDefinition submoduleForDefinition' = definition:
submoduleForDefinition
definition.ref definition.ref
definition.name definition.name
definition.kind definition.kind

View file

@ -1,7 +1,4 @@
{ {lib, ...}:
lib,
...
}:
with lib; { with lib; {
options = { options = {
kubenix.project = mkOption { kubenix.project = mkOption {

View file

@ -415,7 +415,8 @@ in {
features = ["k8s" "submodule"]; features = ["k8s" "submodule"];
module = {config, ...}: { module = {config, ...}: {
# set module defaults # set module defaults
kubernetes.api.defaults = (filter (default: default.propagate) cfg.api.defaults) kubernetes.api.defaults =
(filter (default: default.propagate) cfg.api.defaults)
++ [ ++ [
# set module name and version for all kuberentes resources # set module name and version for all kuberentes resources
{ {

View file

@ -236,11 +236,14 @@ in {
}: let }: let
evaledSubmodule' = evalModules { evaledSubmodule' = evalModules {
inherit specialArgs; inherit specialArgs;
modules = config.modules ++ [./base.nix] ++ [ modules =
{ config.modules
_module.args.check = false; ++ [./base.nix]
} ++ [
]; {
_module.args.check = false;
}
];
}; };
evaledSubmodule = evaledSubmodule =

View file

@ -12,10 +12,7 @@ with lib; let
kubecerts = "/var/lib/kubernetes/secrets"; kubecerts = "/var/lib/kubernetes/secrets";
# how we differ from the standard configuration of mkKubernetesBaseTest # how we differ from the standard configuration of mkKubernetesBaseTest
extraConfiguration = { extraConfiguration = {config, ...}: {
config,
...
}: {
virtualisation = { virtualisation = {
memorySize = 2048; memorySize = 2048;
}; };

View file

@ -1,7 +1,8 @@
{system ? builtins.currentSystem}: ( {system ? builtins.currentSystem}:
(import ./compat.nix).flake-compat { (
src = ./.; (import ./compat.nix).flake-compat {
inherit system; src = ./.;
} inherit system;
) }
.shellNix )
.shellNix

View file

@ -7,7 +7,8 @@
doThrowError ? true, # whether any testing error should throw an error doThrowError ? true, # whether any testing error should throw an error
enabledTests ? null, enabledTests ? null,
}: let }: let
inherit ((evalModules { inherit
((evalModules {
module = { module = {
kubenix, kubenix,
pkgs, pkgs,
@ -48,6 +49,8 @@
]; ];
}; };
}; };
})) config; }))
config
;
in in
config.testing // {recurseForDerivations = true;} config.testing // {recurseForDerivations = true;}

View file

@ -1,9 +1,14 @@
{ config, lib, pkgs, kubenix, helm, ... }: {
config,
lib,
pkgs,
kubenix,
helm,
...
}:
with lib; with lib;
with kubenix.lib; with kubenix.lib;
with pkgs.dockerTools; with pkgs.dockerTools; let
let
corev1 = config.kubernetes.api.resources.core.v1; corev1 = config.kubernetes.api.resources.core.v1;
appsv1 = config.kubernetes.api.resources.apps.v1; appsv1 = config.kubernetes.api.resources.apps.v1;
@ -30,9 +35,8 @@ let
finalImageName = "docker.io/bitnami/bitnami-shell"; finalImageName = "docker.io/bitnami/bitnami-shell";
finalImageTag = "10"; finalImageTag = "10";
}; };
in in {
{ imports = [kubenix.modules.test kubenix.modules.helm kubenix.modules.k8s kubenix.modules.docker];
imports = [ kubenix.modules.test kubenix.modules.helm kubenix.modules.k8s kubenix.modules.docker ];
docker.images = { docker.images = {
postgresql.image = postgresql; postgresql.image = postgresql;
@ -43,14 +47,16 @@ in
test = { test = {
name = "helm-simple"; name = "helm-simple";
description = "Simple k8s testing wheter name, apiVersion and kind are preset"; description = "Simple k8s testing wheter name, apiVersion and kind are preset";
assertions = [{ assertions = [
message = "should have generated resources"; {
assertion = message = "should have generated resources";
appsv1.StatefulSet ? "app-psql-postgresql-primary" && assertion =
appsv1.StatefulSet ? "app-psql-postgresql-read" && appsv1.StatefulSet
corev1.Secret ? "app-psql-postgresql" && ? "app-psql-postgresql-primary"
corev1.Service ? "app-psql-postgresql-headless"; && appsv1.StatefulSet ? "app-psql-postgresql-read"
} && corev1.Secret ? "app-psql-postgresql"
&& corev1.Service ? "app-psql-postgresql-headless";
}
{ {
message = "should have values passed"; message = "should have values passed";
assertion = appsv1.StatefulSet.app-psql-postgresql-read.spec.replicas == 2; assertion = appsv1.StatefulSet.app-psql-postgresql-read.spec.replicas == 2;
@ -59,7 +65,8 @@ in
message = "should have namespace defined"; message = "should have namespace defined";
assertion = assertion =
appsv1.StatefulSet.app-psql-postgresql-primary.metadata.namespace == "test"; appsv1.StatefulSet.app-psql-postgresql-primary.metadata.namespace == "test";
}]; }
];
script = '' script = ''
@pytest.mark.applymanifest('${config.kubernetes.resultYAML}') @pytest.mark.applymanifest('${config.kubernetes.resultYAML}')
def test_helm_deployment(kube): def test_helm_deployment(kube):

View file

@ -1,7 +1,4 @@
{ {kubenix, ...}: {
kubenix,
...
}: {
imports = with kubenix.modules; [test k8s istio]; imports = with kubenix.modules; [test k8s istio];
test = { test = {

View file

@ -13,7 +13,7 @@ with lib; let
inherit (config.submodules.instances) instance5; inherit (config.submodules.instances) instance5;
inherit (config.submodules.instances) versioned-submodule; inherit (config.submodules.instances) versioned-submodule;
submodule = { ...}: { submodule = {...}: {
imports = [kubenix.modules.submodule]; imports = [kubenix.modules.submodule];
options.submodule.args = { options.submodule.args = {